When a OVS daemon is configured to run as a Windows service, when the service is stopped by calling service_stop(), the windows services manager does not give enough time to do everything in the atexit handler. So call the exit handler directly from service_stop().
Signed-off-by: Gurucharan Shetty <gshe...@nicira.com --- lib/daemon-windows.c | 6 ++++++ lib/fatal-signal.c | 3 +-- lib/fatal-signal.h | 1 + tests/daemon.at | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/daemon-windows.c b/lib/daemon-windows.c index f94ad9b..a326c83 100644 --- a/lib/daemon-windows.c +++ b/lib/daemon-windows.c @@ -218,6 +218,11 @@ should_service_stop(void) void service_stop() { + if (!service_started) { + return; + } + atexit_handler(); + ResetEvent(wevent); CloseHandle(wevent); @@ -404,6 +409,7 @@ unlink_pidfile(void) } if (pidfile) { unlink(pidfile); + free(pidfile); } } diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c index 3ddff00..3206388 100644 --- a/lib/fatal-signal.c +++ b/lib/fatal-signal.c @@ -64,7 +64,6 @@ static volatile sig_atomic_t stored_sig_nr = SIG_ATOMIC_MAX; static struct ovs_mutex mutex; -static void atexit_handler(void); static void call_hooks(int sig_nr); #ifdef _WIN32 static BOOL WINAPI ConsoleHandlerRoutine(DWORD dwCtrlType); @@ -226,7 +225,7 @@ fatal_ignore_sigpipe(void) #endif } -static void +void atexit_handler(void) { call_hooks(0); diff --git a/lib/fatal-signal.h b/lib/fatal-signal.h index e50d14a..02bbdaf 100644 --- a/lib/fatal-signal.h +++ b/lib/fatal-signal.h @@ -31,6 +31,7 @@ void fatal_signal_fork(void); void fatal_signal_run(void); void fatal_signal_wait(void); void fatal_ignore_sigpipe(void); +void atexit_handler(void); /* Convenience functions for unlinking files upon termination. * diff --git a/tests/daemon.at b/tests/daemon.at index 9cb4d83..61c4bd4 100644 --- a/tests/daemon.at +++ b/tests/daemon.at @@ -148,3 +148,28 @@ AT_CHECK([grep 'ovsdb-server: could not initialize control socket' stderr], [0], [ignore], []) AT_CHECK([test ! -s pid]) AT_CLEANUP + +AT_SETUP([daemon --service]) +AT_SKIP_IF([test "$IS_WIN32" != "yes"]) +OVSDB_INIT([db]) +AT_CAPTURE_FILE([pid]) +# To create a Windows service, we need the absolute path for the executable. +abs_path="$(cd $(dirname `which ovsdb-server`); pwd -W; cd $OLDPWD)" + +AT_CHECK([sc create ovsdb-server binpath="$abs_path/ovsdb-server `pwd`/db --log-file=`pwd`/ovsdb-server.log --pidfile=`pwd`/pid --remote=punix:`pwd`/socket --unixctl=`pwd`/unixctl --service"], +[0], [[[SC]] CreateService SUCCESS +]) + +AT_CHECK([sc start ovsdb-server], [0], [ignore]) +OVS_WAIT_UNTIL([test -s pid]) +AT_CHECK([sc query ovsdb-server | grep STATE | grep RUNNING], [0], [ignore]) +AT_CHECK([kill -0 `cat pid`], [0], [ignore]) +AT_CHECK([ovs-appctl -t `pwd`/unixctl ovsdb-server/list-dbs], [0], +[Open_vSwitch +]) +AT_CHECK([sc stop ovsdb-server], [0], [ignore]) +OVS_WAIT_UNTIL([test ! -s pid]) +AT_CHECK([sc query ovsdb-server | grep STATE | grep STOPPED], [0], [ignore]) +AT_CHECK([sc delete ovsdb-server], [0], [[[SC]] DeleteService SUCCESS +]) +AT_CLEANUP -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev