[rrd-developers] [PATCH] chdir(base_dir) even if we are staying in the foreground (-g).

kevin brintnall kbrint at rufus.net
Mon Sep 29 22:28:44 CEST 2008


The daemon should behave the same way w/r/t files whether we "-g" or not.
---
 src/rrd_daemon.c |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c
index ead969b..a0e6bdb 100644
--- a/src/rrd_daemon.c
+++ b/src/rrd_daemon.c
@@ -1999,6 +1999,7 @@ static int daemonize (void) /* {{{ */
 {
   int status;
   int fd;
+  char *base_dir;
 
   fd = open_pidfile();
   if (fd < 0) return fd;
@@ -2006,7 +2007,6 @@ static int daemonize (void) /* {{{ */
   if (!stay_foreground)
   {
     pid_t child;
-    char *base_dir;
 
     child = fork ();
     if (child < 0)
@@ -2019,17 +2019,6 @@ static int daemonize (void) /* {{{ */
       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 ();
 
@@ -2043,6 +2032,17 @@ static int daemonize (void) /* {{{ */
     dup (0);
   } /* if (!stay_foreground) */
 
+  /* 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);
+  }
+
   install_signal_handlers();
 
   openlog ("rrdcached", LOG_PID, LOG_DAEMON);
-- 
1.6.0.2



More information about the rrd-developers mailing list