diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-10-04 18:11:47 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-10-04 18:11:47 +0000 |
commit | a0dbf69b83e932370562948146f08195c6cf130d (patch) | |
tree | 17a991124026a7f4aa44bba8c2a34eee4a2f8947 /contrib/package/freifunk-watchdog/src/watchdog.c | |
parent | 32acbdde47c5b0064da6618e693c8a77e48d3aec (diff) |
contrib/package: reap zombies in freifunk-watchdog, fix a warning
Diffstat (limited to 'contrib/package/freifunk-watchdog/src/watchdog.c')
-rw-r--r-- | contrib/package/freifunk-watchdog/src/watchdog.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/contrib/package/freifunk-watchdog/src/watchdog.c b/contrib/package/freifunk-watchdog/src/watchdog.c index b87bed0a9..2d6e4a6f7 100644 --- a/contrib/package/freifunk-watchdog/src/watchdog.c +++ b/contrib/package/freifunk-watchdog/src/watchdog.c @@ -21,10 +21,18 @@ /* Global watchdog fd, required by signal handler */ int wdfd = -1; +/* Handle finished childs */ +static void sigchld_handler(int sig) +{ + pid_t pid; + + while( (pid = waitpid(-1, NULL, WNOHANG)) > 0 ) + syslog(LOG_INFO, "Child returned (pid %d)", pid); +} + /* Watchdog shutdown helper */ static void shutdown_watchdog(int sig) { - static int wdelay = 3600; static const char wshutdown = WATCH_SHUTDOWN; if( wdfd > -1 ) @@ -298,7 +306,7 @@ static int do_daemon(void) int loadavg_panic = 0; openlog(SYSLOG_IDENT, 0, LOG_DAEMON); - //daemon(1, 1); + memset(&sa, 0, sizeof(sa)); if( (iwfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1 ) { @@ -327,6 +335,11 @@ static int do_daemon(void) ioctl(wdfd, WDIOC_SETTIMEOUT, &wdtimeout); } + /* Install signal handler to reap childs */ + sa.sa_handler = sigchld_handler; + sa.sa_flags = 0; + sigaction(SIGCHLD, &sa, NULL); + while( 1 ) { /* Check/increment action interval */ |