From fe6988251d9a8698ff17c5a791b7113763e7db45 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 4 Nov 2008 16:11:17 -0800 Subject: [PATCH] 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. --- controller/controller.c | 10 +++++----- lib/vlog-socket.c | 5 +++++ secchan/secchan.c | 6 +++--- switch/switch.c | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/controller/controller.c b/controller/controller.c index ce05aa7bf..41f25478c 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 7cfc5d7c8..0dc836f53 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 35b851ff8..8edb5b689 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 525e9fa78..fba885853 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); -- 2.43.0