From 9e15c889f7a94db2decefd93dd6b3f77fb1b7bc6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 3 May 2010 15:43:49 -0700 Subject: [PATCH] ovs-vswitchd: Implement "exit" unixctl command. This is useful for profiling, since common profilers do not print anything until the process terminates, and only if the process terminates in the ordinary way by calling exit(). --- vswitchd/ovs-vswitchd.8.in | 3 +++ vswitchd/ovs-vswitchd.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in index b7c99404..24c1c5d3 100644 --- a/vswitchd/ovs-vswitchd.8.in +++ b/vswitchd/ovs-vswitchd.8.in @@ -106,6 +106,9 @@ to be loaded. \fBovs\-vswitchd\fR process. The currently supported commands are described below. The command descriptions assume an understanding of how to configure Open vSwitch. +.SS "GENERAL COMMANDS" +.IP "\fBexit\fR" +Causes \fBovs\-vswitchd\fR to gracefully terminate. .SS "BRIDGE COMMANDS" These commands manage bridges. .IP "\fBfdb/show\fR \fIbridge\fR" diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c index c1acfc41..64781560 100644 --- a/vswitchd/ovs-vswitchd.c +++ b/vswitchd/ovs-vswitchd.c @@ -50,6 +50,8 @@ #include "vlog.h" #define THIS_MODULE VLM_vswitchd +static unixctl_cb_func ovs_vswitchd_exit; + static const char *parse_options(int argc, char *argv[]); static void usage(void) NO_RETURN; @@ -61,7 +63,7 @@ main(int argc, char *argv[]) struct ovsdb_idl *idl; const char *remote; bool need_reconfigure; - bool inited; + bool inited, exiting; unsigned int idl_seqno; int retval; @@ -82,6 +84,7 @@ main(int argc, char *argv[]) if (retval) { exit(EXIT_FAILURE); } + unixctl_command_register("exit", ovs_vswitchd_exit, &exiting); daemonize_complete(); @@ -90,7 +93,8 @@ main(int argc, char *argv[]) need_reconfigure = false; inited = false; - for (;;) { + exiting = false; + while (!exiting) { if (signal_poll(sighup)) { vlog_reopen_log_file(); } @@ -252,3 +256,12 @@ usage(void) leak_checker_usage(); exit(EXIT_SUCCESS); } + +static void +ovs_vswitchd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED, + void *exiting_) +{ + bool *exiting = exiting_; + *exiting = true; + unixctl_command_reply(conn, 200, NULL); +} -- 2.30.2