src/rrd_xport.c: Implement the `--daemon' option for `rrdtool xport'.
[rrdtool.git] / src / rrd_daemon.c
index ac26a27..87ac8e9 100644 (file)
@@ -1085,6 +1085,13 @@ static int daemonize (void) /* {{{ */
 {
   pid_t child;
   int status;
+  char *base_dir;
+
+  /* These structures are static, because `sigaction' behaves weird if the are
+   * overwritten.. */
+  static struct sigaction sa_int;
+  static struct sigaction sa_term;
+  static struct sigaction sa_pipe;
 
   child = fork ();
   if (child < 0)
@@ -1120,21 +1127,18 @@ static int daemonize (void) /* {{{ */
   dup (0);
   dup (0);
 
-  {
-    struct sigaction sa;
-
-    memset (&sa, 0, sizeof (sa));
-    sa.sa_handler = sig_int_handler;
-    sigaction (SIGINT, &sa, NULL);
+  /* Install signal handlers */
+  memset (&sa_int, 0, sizeof (sa_int));
+  sa_int.sa_handler = sig_int_handler;
+  sigaction (SIGINT, &sa_int, NULL);
 
-    memset (&sa, 0, sizeof (sa));
-    sa.sa_handler = sig_term_handler;
-    sigaction (SIGINT, &sa, NULL);
+  memset (&sa_term, 0, sizeof (sa_term));
+  sa_term.sa_handler = sig_term_handler;
+  sigaction (SIGINT, &sa_term, NULL);
 
-    memset (&sa, 0, sizeof (sa));
-    sa.sa_handler = SIG_IGN;
-    sigaction (SIGPIPE, &sa, NULL);
-  }
+  memset (&sa_pipe, 0, sizeof (sa_pipe));
+  sa_pipe.sa_handler = SIG_IGN;
+  sigaction (SIGPIPE, &sa_pipe, NULL);
 
   openlog ("rrdcached", LOG_PID, LOG_DAEMON);