Create vlog sockets after daemonizing, so that pidfiles can be used.
authorBen Pfaff <blp@nicira.com>
Wed, 5 Nov 2008 00:11:17 +0000 (16:11 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 5 Nov 2008 00:14:00 +0000 (16:14 -0800)
Otherwise, pidfiles contain the process ID of the process that forked
and exited, so that "vlogconf --target <program.pid>" will fail.

controller/controller.c
lib/vlog-socket.c
secchan/secchan.c
switch/switch.c

index ce05aa7..41f2547 100644 (file)
@@ -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;
index 7cfc5d7..0dc836f 100644 (file)
@@ -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 <program>.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
index 35b851f..8edb5b6 100644 (file)
@@ -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);
 
index 525e9fa..fba8858 100644 (file)
@@ -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);