From: Ben Pfaff Date: Wed, 5 Nov 2008 00:11:17 +0000 (-0800) Subject: Create vlog sockets after daemonizing, so that pidfiles can be used. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe6988251d9a8698ff17c5a791b7113763e7db45;p=openvswitch Create vlog sockets after daemonizing, so that pidfiles can be used. Otherwise, pidfiles contain the process ID of the process that forked and exited, so that "vlogconf --target " will fail. --- diff --git a/controller/controller.c b/controller/controller.c index ce05aa7b..41f25478 100644 --- a/controller/controller.c +++ b/controller/controller.c @@ -101,11 +101,6 @@ main(int argc, char *argv[]) "use --help for usage"); } - retval = vlog_server_listen(NULL, NULL); - if (retval) { - ofp_fatal(retval, "Could not listen for vlog connections"); - } - n_switches = n_listeners = 0; for (i = optind; i < argc; i++) { const char *name = argv[i]; @@ -140,6 +135,11 @@ main(int argc, char *argv[]) die_if_already_running(); daemonize(); + retval = vlog_server_listen(NULL, NULL); + if (retval) { + ofp_fatal(retval, "Could not listen for vlog connections"); + } + while (n_switches > 0 || n_listeners > 0) { int iteration; int i; diff --git a/lib/vlog-socket.c b/lib/vlog-socket.c index 7cfc5d7c..0dc836f5 100644 --- a/lib/vlog-socket.c +++ b/lib/vlog-socket.c @@ -79,6 +79,11 @@ static void poll_server(int fd, short int events, void *server_); * - An absolute path (starting with '/') that gives the exact name of * the Unix domain socket to listen on. * + * A program that (optionally) daemonizes itself should call this function + * *after* daemonization, so that the socket name contains the pid of the + * daemon instead of the pid of the program that exited. (Otherwise, "vlogconf + * --target .pid" will fail.) + * * Returns 0 if successful, otherwise a positive errno value. If successful, * sets '*serverp' to the new vlog_server, otherwise to NULL. */ int diff --git a/secchan/secchan.c b/secchan/secchan.c index 35b851ff..8edb5b68 100644 --- a/secchan/secchan.c +++ b/secchan/secchan.c @@ -140,15 +140,15 @@ main(int argc, char *argv[]) /* Initialize switch status hook. */ switch_status_start(&secchan, &s, &switch_status); + die_if_already_running(); + daemonize(); + /* Start listening for vlogconf requests. */ retval = vlog_server_listen(NULL, NULL); if (retval) { ofp_fatal(retval, "Could not listen for vlog connections"); } - die_if_already_running(); - daemonize(); - VLOG_WARN("OpenFlow reference implementation version %s", VERSION BUILDNR); VLOG_WARN("OpenFlow protocol version 0x%02x", OFP_VERSION); diff --git a/switch/switch.c b/switch/switch.c index 525e9fa7..fba88585 100644 --- a/switch/switch.c +++ b/switch/switch.c @@ -119,14 +119,14 @@ main(int argc, char *argv[]) add_ports(dp, port_list); } + die_if_already_running(); + daemonize(); + error = vlog_server_listen(NULL, NULL); if (error) { ofp_fatal(error, "could not listen for vlog connections"); } - die_if_already_running(); - daemonize(); - for (;;) { dp_run(dp); dp_wait(dp);