From: Alan T. DeKok Date: Tue, 13 Oct 2009 10:53:49 +0000 (+0200) Subject: Write the PID file as late as possible X-Git-Tag: release_2_1_8~97 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=c78568c693afc74d7a180807cd40a4d8d02b2b95;p=freeradius.git Write the PID file as late as possible i.e. after checking the config, and after opening any sockets --- diff --git a/src/main/radiusd.c b/src/main/radiusd.c index d499a0a..3104d02 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -289,30 +289,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. */ @@ -393,6 +369,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. */ while ((rcode = radius_event_process()) == 0x80) {