src/rrd_daemon.c: Add Kevin to the list of copyright holders.
[rrdtool.git] / src / rrd_daemon.c
index abb2ace..0816526 100644 (file)
@@ -1,6 +1,7 @@
 /**
  * RRDTool - src/rrd_daemon.c
  * Copyright (C) 2008 Florian octo Forster
+ * Copyright (C) 2008 Kevin Brintnall
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
  *   kevin brintnall <kbrint@rufus.net>
  **/
 
+#if 0
+/*
+ * First tell the compiler to stick to the C99 and POSIX standards as close as
+ * possible.
+ */
+#ifndef __STRICT_ANSI__ /* {{{ */
+# define __STRICT_ANSI__
+#endif
+
+#ifndef _ISOC99_SOURCE
+# define _ISOC99_SOURCE
+#endif
+
+#ifdef _POSIX_C_SOURCE
+# undef _POSIX_C_SOURCE
+#endif
+#define _POSIX_C_SOURCE 200112L
+
+/* Single UNIX needed for strdup. */
+#ifdef _XOPEN_SOURCE
+# undef _XOPEN_SOURCE
+#endif
+#define _XOPEN_SOURCE 500
+
 #ifndef _REENTRANT
 # define _REENTRANT
 #endif
 # define _THREAD_SAFE
 #endif
 
+#ifdef _GNU_SOURCE
+# undef _GNU_SOURCE
+#endif
 /* }}} */
+#endif /* 0 */
 
 /*
  * Now for some includes..
@@ -1173,7 +1202,7 @@ static int handle_request_wrote (int fd __attribute__((unused)), /* {{{ */
 
   pthread_mutex_unlock(&cache_lock);
   return (0);
-}
+} /* }}} int handle_request_wrote */
 
 /* if fd < 0, we are in journal replay mode */
 static int handle_request (int fd, char *buffer, size_t buffer_size) /* {{{ */
@@ -1754,9 +1783,7 @@ static void *listen_thread_main (void *args __attribute__((unused))) /* {{{ */
 
 static int daemonize (void) /* {{{ */
 {
-  pid_t child;
   int status;
-  char *base_dir;
 
   /* These structures are static, because `sigaction' behaves weird if the are
    * overwritten.. */
@@ -1764,44 +1791,46 @@ static int daemonize (void) /* {{{ */
   static struct sigaction sa_term;
   static struct sigaction sa_pipe;
 
-  if (stay_foreground)
-    goto child_startup;
-
-  child = fork ();
-  if (child < 0)
-  {
-    fprintf (stderr, "daemonize: fork(2) failed.\n");
-    return (-1);
-  }
-  else if (child > 0)
+  if (!stay_foreground)
   {
-    return (1);
-  }
+    pid_t child;
+    char *base_dir;
 
-  /* Change into the /tmp directory. */
-  base_dir = (config_base_dir != NULL)
-    ? config_base_dir
-    : "/tmp";
-  status = chdir (base_dir);
-  if (status != 0)
-  {
-    fprintf (stderr, "daemonize: chdir (%s) failed.\n", base_dir);
-    return (-1);
-  }
+    child = fork ();
+    if (child < 0)
+    {
+      fprintf (stderr, "daemonize: fork(2) failed.\n");
+      return (-1);
+    }
+    else if (child > 0)
+    {
+      return (1);
+    }
+
+    /* Change into the /tmp directory. */
+    base_dir = (config_base_dir != NULL)
+      ? config_base_dir
+      : "/tmp";
+    status = chdir (base_dir);
+    if (status != 0)
+    {
+      fprintf (stderr, "daemonize: chdir (%s) failed.\n", base_dir);
+      return (-1);
+    }
 
-  /* Become session leader */
-  setsid ();
+    /* Become session leader */
+    setsid ();
 
-  /* Open the first three file descriptors to /dev/null */
-  close (2);
-  close (1);
-  close (0);
+    /* Open the first three file descriptors to /dev/null */
+    close (2);
+    close (1);
+    close (0);
 
-  open ("/dev/null", O_RDWR);
-  dup (0);
-  dup (0);
+    open ("/dev/null", O_RDWR);
+    dup (0);
+    dup (0);
+  } /* if (!stay_foreground) */
 
-child_startup:
   /* Install signal handlers */
   memset (&sa_int, 0, sizeof (sa_int));
   sa_int.sa_handler = sig_int_handler;