ovs-vswitchd: Complete daemonization only after initial configuration.
authorBen Pfaff <blp@nicira.com>
Fri, 28 Jan 2011 20:44:00 +0000 (12:44 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 7 Feb 2011 20:50:19 +0000 (12:50 -0800)
Otherwise when we add support for saving and restoring configuration
of internal devices around kernel module unload and reload, there's
no easy way for the "restore" code to tell when all the interfaces
should be set up and ready for configuration.

lib/daemon.c
lib/daemon.man
ovsdb/ovsdb-server.1.in
vswitchd/bridge.c
vswitchd/ovs-vswitchd.8.in
vswitchd/ovs-vswitchd.c

index 9db6c1f..a8b3fae 100644 (file)
@@ -475,11 +475,14 @@ daemonize_start(void)
 }
 
 /* If daemonization is configured, then this function notifies the parent
- * process that the child process has completed startup successfully. */
+ * process that the child process has completed startup successfully.
+ *
+ * Calling this function more than once has no additional effect. */
 void
 daemonize_complete(void)
 {
     fork_notify_startup(daemonize_fd);
+    daemonize_fd = -1;
 
     if (detach) {
         setsid();
@@ -487,6 +490,7 @@ daemonize_complete(void)
             ignore(chdir("/"));
         }
         close_standard_fds();
+        detach = false;
     }
 }
 
index d9f25e1..7b07cb8 100644 (file)
@@ -20,7 +20,7 @@ When \fB\-\-pidfile\fR is not specified, this option has no effect.
 .TP
 \fB\-\-detach\fR
 Causes \fB\*(PN\fR to detach itself from the foreground session and
-run as a background process.
+run as a background process. \*(DD
 .
 .TP
 \fB\-\-monitor\fR
index a89f091..6100c4d 100644 (file)
@@ -81,6 +81,9 @@ This option can be useful where a database server is needed only to
 run a single command, e.g.:
 .B "ovsdb\-server \-\-remote=punix:socket \-\-run='ovsdb\-client dump unix:socket Open_vSwitch'"
 .SS "Daemon Options"
+.ds DD \
+\fBovsdb\-server\fR detaches only after it starts listening on all \
+configured remotes.
 .so lib/daemon.man
 .SS "Logging Options"
 .so lib/vlog.man
index 2465cfb..72eb734 100644 (file)
@@ -35,6 +35,7 @@
 #include "cfm.h"
 #include "classifier.h"
 #include "coverage.h"
+#include "daemon.h"
 #include "dirs.h"
 #include "dpif.h"
 #include "dynamic-string.h"
@@ -933,6 +934,10 @@ bridge_reconfigure(const struct ovsrec_open_vswitch *ovs_cfg)
     }
 
     free(managers);
+
+    /* ovs-vswitchd has completed initialization, so allow the process that
+     * forked us to exit successfully. */
+    daemonize_complete();
 }
 
 static const char *
index 5c52526..163ad20 100644 (file)
@@ -102,6 +102,10 @@ to be loaded.
 .IP
 On non-Linux hosts, this option is accepted but has no effect.
 .
+.ds DD \
+\fBovs\-vswitchd\fR detaches only after it has connected to the \
+database, retrieved the initial configuration, and set up that \
+configuration.
 .so lib/daemon.man
 .SS "Public Key Infrastructure Options"
 .so lib/ssl.man
index 4ebc8f2..2181e82 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009, 2010 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -84,8 +84,6 @@ main(int argc, char *argv[])
     }
     unixctl_command_register("exit", ovs_vswitchd_exit, &exiting);
 
-    daemonize_complete();
-
     bridge_init(remote);
     exiting = false;
     while (!exiting) {