diff options
author | Russ Allbery <rra@stanford.edu> | 2012-09-25 00:30:33 -0700 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2012-09-25 00:30:33 -0700 |
commit | cc814fc039d720d2773032a8d46915054fdfe3a3 (patch) | |
tree | be37741d0ea2183bb8d2d3d9df1d4c18c0fa5ce1 /server | |
parent | 35ca6663b593c923495f537217f78a39b1cf5e3d (diff) |
Don't create server PID file until the network is ready
Don't create the remctld PID file until the network socket is bound
and listening. This helps init scripts starting the daemon to know
when startup is complete and the service is available.
Change-Id: Iba4b1fdea49eb31f49af36aa68bb1f4161fe0e69
Diffstat (limited to 'server')
-rw-r--r-- | server/remctld.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/server/remctld.c b/server/remctld.c index fa0d8a9..66f504c 100644 --- a/server/remctld.c +++ b/server/remctld.c @@ -276,6 +276,7 @@ server_daemon(struct options *options, struct config *config, struct sockaddr_storage ss; socklen_t sslen; char ip[INET6_ADDRSTRLEN]; + FILE *pid_file; /* Set up a SIGCHLD handler so that we know when to reap children. */ memset(&sa, 0, sizeof(sa)); @@ -322,6 +323,18 @@ server_daemon(struct options *options, struct config *config, sysdie("error listening on socket (fd %d)", fds[i]); /* + * Set up our PID file now that we're ready to accept connections, so that + * the PID file isn't created until clients can connect. + */ + if (options->pid_path != NULL) { + pid_file = fopen(options->pid_path, "w"); + if (pid_file == NULL) + sysdie("cannot create PID file %s", options->pid_path); + fprintf(pid_file, "%ld\n", (long) getpid()); + fclose(pid_file); + } + + /* * The main processing loop. Each time through the loop, check to see if * we need to reap children, check to see if we should re-read our * configuration, and check to see if we're exiting. Then see if we have @@ -394,7 +407,6 @@ int main(int argc, char *argv[]) { struct options options; - FILE *pid_file; int option; struct sigaction sa; gss_cred_id_t creds = GSS_C_NO_CREDENTIAL; @@ -507,18 +519,6 @@ main(int argc, char *argv[]) } /* - * Set up our PID file now after we've daemonized, since we may have - * changed PIDs in the process. - */ - if (options.standalone && options.pid_path != NULL) { - pid_file = fopen(options.pid_path, "w"); - if (pid_file == NULL) - sysdie("cannot create PID file %s", options.pid_path); - fprintf(pid_file, "%ld\n", (long) getpid()); - fclose(pid_file); - } - - /* * If we're not running as a daemon, just process the connection. * Otherwise, create a socket and listen on the socket, processing each * incoming connection. |