ovs-vswitchd: Implement "exit" unixctl command.
authorBen Pfaff <blp@nicira.com>
Mon, 3 May 2010 22:43:49 +0000 (15:43 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 5 May 2010 21:00:13 +0000 (14:00 -0700)
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
vswitchd/ovs-vswitchd.c

index b7c9940..24c1c5d 100644 (file)
@@ -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"
index c1acfc4..6478156 100644 (file)
@@ -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);
+}