- add basic logging support to fsipd
This commit is contained in:
parent
3ca12815f5
commit
ed43cbd4e1
19
fsipd.c
19
fsipd.c
@ -57,7 +57,7 @@
|
|||||||
struct pidfh *pfh;
|
struct pidfh *pfh;
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
struct protoent *proto_tcp, *proto_udp;
|
struct protoent *proto_tcp, *proto_udp;
|
||||||
log_t *lh;
|
log_t *lfh;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare for a clean shutdown
|
* Prepare for a clean shutdown
|
||||||
@ -66,6 +66,7 @@ void
|
|||||||
daemon_shutdown()
|
daemon_shutdown()
|
||||||
{
|
{
|
||||||
pidfile_remove(pfh);
|
pidfile_remove(pfh);
|
||||||
|
log_close(lfh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -77,7 +78,7 @@ signal_handler(int sig)
|
|||||||
switch (sig) {
|
switch (sig) {
|
||||||
|
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
log_reopen(&lh);
|
log_reopen(&lfh);
|
||||||
break;
|
break;
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
@ -92,9 +93,9 @@ signal_handler(int sig)
|
|||||||
void
|
void
|
||||||
process_request(char *str)
|
process_request(char *str)
|
||||||
{
|
{
|
||||||
/* check input str for SIP requests */
|
/* TODO: change format to CSV */
|
||||||
|
|
||||||
syslog(LOG_ALERT, "sip: %s, sport: %d, payload: \"%s\"\n",
|
log_tsprintf(lfh, "sip: %s, sport: %d, payload: \"%s\"\n",
|
||||||
inet_ntoa(sa.sin_addr), ntohs(sa.sin_port), str);
|
inet_ntoa(sa.sin_addr), ntohs(sa.sin_port), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,12 +117,18 @@ daemon_start()
|
|||||||
/* Check if we can acquire the pid file */
|
/* Check if we can acquire the pid file */
|
||||||
pfh = pidfile_open(NULL, 0600, &otherpid);
|
pfh = pidfile_open(NULL, 0600, &otherpid);
|
||||||
|
|
||||||
|
|
||||||
if (pfh == NULL) {
|
if (pfh == NULL) {
|
||||||
if (errno == EEXIST) {
|
if (errno == EEXIST) {
|
||||||
errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", (intmax_t)otherpid);
|
errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", (intmax_t)otherpid);
|
||||||
}
|
}
|
||||||
err(EXIT_FAILURE, "Cannot open or create pidfile");
|
err(EXIT_FAILURE, "Cannot open or create pidfile");
|
||||||
}
|
}
|
||||||
|
/* open a log file in current directory */
|
||||||
|
lfh = log_open(NULL, 0644);
|
||||||
|
if ((lfh = log_open("test.log", 0600)) == NULL) {
|
||||||
|
err(EXIT_FAILURE, "Cannot open log file");
|
||||||
|
}
|
||||||
/* setup socket */
|
/* setup socket */
|
||||||
if ((proto_tcp = getprotobyname("tcp")) == NULL)
|
if ((proto_tcp = getprotobyname("tcp")) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -180,6 +187,10 @@ daemon_start()
|
|||||||
/* create new session and process group */
|
/* create new session and process group */
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
|
syslog(LOG_ALERT, "%s started with PID %d\n",
|
||||||
|
getprogname(), getpid());
|
||||||
|
|
||||||
|
|
||||||
/* persist pid */
|
/* persist pid */
|
||||||
pidfile_write(pfh);
|
pidfile_write(pfh);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user