]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Write the PID file as late as possible
authorAlan T. DeKok <aland@freeradius.org>
Tue, 13 Oct 2009 10:53:49 +0000 (12:53 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 20 Oct 2009 22:05:15 +0000 (00:05 +0200)
i.e. after checking the config, and after opening any sockets

src/main/radiusd.c

index d499a0a2d7bc67c641ed77dc5a913edaf55a67cb..3104d02b2123fe5612293bbfd3ae76fd4f62c7fe 100644 (file)
@@ -288,30 +288,6 @@ int main(int argc, char *argv[])
         */
        radius_pid = getpid();
 
-       /*
-        *  Only write the PID file if we're running as a daemon.
-        *
-        *  And write it AFTER we've forked, so that we write the
-        *  correct PID.
-        */
-       if (dont_fork == FALSE) {
-               FILE *fp;
-
-               fp = fopen(mainconfig.pid_file, "w");
-               if (fp != NULL) {
-                       /*
-                        *      FIXME: What about following symlinks,
-                        *      and having it over-write a normal file?
-                        */
-                       fprintf(fp, "%d\n", (int) radius_pid);
-                       fclose(fp);
-               } else {
-                       radlog(L_ERR|L_CONS, "Failed creating PID file %s: %s\n",
-                              mainconfig.pid_file, strerror(errno));
-                       exit(1);
-               }
-       }
-
        /*
         *      If we're running as a daemon, close the default file
         *      descriptors, AFTER forking.
@@ -392,6 +368,30 @@ int main(int argc, char *argv[])
 
        radius_stats_init(0);
 
+       /*
+        *  Only write the PID file if we're running as a daemon.
+        *
+        *  And write it AFTER we've forked, so that we write the
+        *  correct PID.
+        */
+       if (dont_fork == FALSE) {
+               FILE *fp;
+
+               fp = fopen(mainconfig.pid_file, "w");
+               if (fp != NULL) {
+                       /*
+                        *      FIXME: What about following symlinks,
+                        *      and having it over-write a normal file?
+                        */
+                       fprintf(fp, "%d\n", (int) radius_pid);
+                       fclose(fp);
+               } else {
+                       radlog(L_ERR|L_CONS, "Failed creating PID file %s: %s\n",
+                              mainconfig.pid_file, strerror(errno));
+                       exit(1);
+               }
+       }
+
        /*
         *      Process requests until HUP or exit.
         */