[BB#74] Create log and pid files after we drop privs
authorMukund Sivaraman <muks@banu.com>
Wed, 2 Jun 2010 04:49:49 +0000 (10:19 +0530)
committerMukund Sivaraman <muks@banu.com>
Wed, 2 Jun 2010 05:06:05 +0000 (10:36 +0530)
src/main.c

index dd1ff73e32d291fdcce13fe0d04301eba375e3ab..a632c431d0bc9d22a84e09e4e338e0c29e63880a 100644 (file)
@@ -394,10 +394,6 @@ main (int argc, char **argv)
                 exit (EX_SOFTWARE);
         }
 
-        if (setup_logging ()) {
-                exit (EX_SOFTWARE);
-        }
-
         init_stats ();
 
         /* If ANONYMOUS is turned on, make sure that Content-Length is
@@ -412,14 +408,6 @@ main (int argc, char **argv)
         if (config.godaemon == TRUE)
                 makedaemon ();
 
-        if (config.pidpath) {
-                if (pidfile_create (config.pidpath) < 0) {
-                        fprintf (stderr, "%s: Could not create PID file.\n",
-                                 argv[0]);
-                        exit (EX_OSERR);
-                }
-        }
-
         if (set_signal_handler (SIGPIPE, SIG_IGN) == SIG_ERR) {
                 fprintf (stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
                          argv[0]);
@@ -445,6 +433,20 @@ main (int argc, char **argv)
                 log_message (LOG_WARNING,
                              "Not running as root, so not changing UID/GID.");
 
+        /* Create log file after we drop privileges */
+        if (setup_logging ()) {
+                exit (EX_SOFTWARE);
+        }
+
+        /* Create pid file after we drop privileges */
+        if (config.pidpath) {
+                if (pidfile_create (config.pidpath) < 0) {
+                        fprintf (stderr, "%s: Could not create PID file.\n",
+                                 argv[0]);
+                        exit (EX_OSERR);
+                }
+        }
+
         if (child_pool_create () < 0) {
                 fprintf (stderr,
                          "%s: Could not create the pool of children.\n",