Date: Sun, 30 Jan 2011 13:43:38 -0200
From: Carlos Carvalho <carlos@fisica.ufpr.br>

sigaction.diff uses sigaction() instead of signal(). The main reason
is to improve efficiency by removing the call to signal() inside the
line loop. It also is more portable and gives more control of the
signal handling.

--- a/flog.c
+++ b/flog.c
@@ -60,6 +60,7 @@ int main(int argc, char** argv)
   int totalwn = 0;
   int disk_is_full = 0;
   FILE *pid_fd;
+  struct sigaction act;
 
   // look for switches
   conf.time_format = NULL;
@@ -121,7 +122,13 @@ int main(int argc, char** argv)
   out.name = argv[opt];
   openfile (&out);
 
-  signal (SIGHUP, catchHUP);
+  act.sa_handler = catchHUP;
+  sigemptyset(&act.sa_mask);
+  act.sa_flags = SA_RESTART;
+  if (sigaction(SIGHUP, &act, NULL) < 0) {
+         fprintf(stderr, "Could not install signal handler");
+         exit(1);
+  }
 
   growbuf (4096);
 
@@ -143,7 +150,6 @@ int main(int argc, char** argv)
 
       if (gotHUP) {
 	handleHUP();
-	signal (SIGHUP, catchHUP);
 	gotHUP = 0;
       }
 
