From a7ff9bd76312a7733168629d8e4e922d47b0ae46 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 28 Jan 2011 12:44:00 -0800 Subject: [PATCH] ovs-vswitchd: Complete daemonization only after initial configuration. 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 | 6 +++++- lib/daemon.man | 2 +- ovsdb/ovsdb-server.1.in | 3 +++ vswitchd/bridge.c | 5 +++++ vswitchd/ovs-vswitchd.8.in | 4 ++++ vswitchd/ovs-vswitchd.c | 4 +--- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/daemon.c b/lib/daemon.c index 9db6c1f8..a8b3fae3 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -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; } } diff --git a/lib/daemon.man b/lib/daemon.man index d9f25e1a..7b07cb81 100644 --- a/lib/daemon.man +++ b/lib/daemon.man @@ -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 diff --git a/ovsdb/ovsdb-server.1.in b/ovsdb/ovsdb-server.1.in index a89f0919..6100c4d5 100644 --- a/ovsdb/ovsdb-server.1.in +++ b/ovsdb/ovsdb-server.1.in @@ -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 diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 2465cfb3..72eb7346 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -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 * diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in index 5c525268..163ad205 100644 --- a/vswitchd/ovs-vswitchd.8.in +++ b/vswitchd/ovs-vswitchd.8.in @@ -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 diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c index 4ebc8f2c..2181e82e 100644 --- a/vswitchd/ovs-vswitchd.c +++ b/vswitchd/ovs-vswitchd.c @@ -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) { -- 2.30.2