Added anit-zombie measures to evmapperd
authorskeezix <skeezix@flotsam-vm.(none)>
Wed, 17 Feb 2010 19:28:47 +0000 (14:28 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Wed, 17 Feb 2010 19:28:47 +0000 (14:28 -0500)
apps/pndevmapperd.c

index 8a49d6d..d6a6991 100644 (file)
@@ -18,6 +18,8 @@
 #include <errno.h> // for errno
 #include <time.h> // for time(2)
 #include <ctype.h> // for isdigit
+#include <signal.h> // for sigaction
+#include <sys/wait.h> // for wait
 
 #include <linux/input.h> // for keys
 //#include "../../kernel-rip/input.h" // for keys
@@ -99,12 +101,12 @@ unsigned int g_evmap_max = 0;
  */
 void dispatch_key ( int keycode, int val );
 void dispatch_event ( int code, int val );
+void sigchld_handler ( int n );
 
 static void usage ( char *argv[] ) {
   printf ( "%s [-d]\n", argv [ 0 ] );
   printf ( "-d\tDaemon mode; detach from terminal, chdir to /tmp, suppress output. Optional.\n" );
   printf ( "-l#\tLog-it; -l is 0-and-up (or all), and -l2 means 2-and-up (not all); l[0-3] for now. Log goes to /tmp/pndevmapperd.log\n" );
-  printf ( "Signal: HUP the process to force reload of configuration and reset the notifier watch paths\n" );
   return;
 }
 
@@ -342,6 +344,18 @@ int main ( int argc, char *argv[] ) {
     exit ( -1 );
   } // spin
 
+  /* set up sigchld -- don't want zombies all over; well, we do, but not process zombies
+   */
+  sigset_t ss;
+  sigemptyset ( &ss );
+
+  struct sigaction siggy;
+  siggy.sa_handler = sigchld_handler;
+  siggy.sa_mask = ss; /* implicitly blocks the origin signal */
+  siggy.sa_flags = 0; /* don't need anything */
+
+  sigaction ( SIGCHLD, &siggy, NULL );
+
   /* actually try to do something useful
    */
 
@@ -598,3 +612,13 @@ void dispatch_event ( int code, int val ) {
 
   return;
 }
+
+void sigchld_handler ( int n ) {
+
+  pnd_log ( pndn_rem, "---[ SIGCHLD received ]---\n" );
+
+  int status;
+  wait ( &status );
+
+  return;
+}