Bring manpages and usage messages up-to-date.
[openvswitch] / switch / switch.c
index abd76b6e1a3c113d12b6b4f44c1b31d8c94096f7..9432a022f3a58890e9507108af31ce416216d493 100644 (file)
@@ -38,6 +38,7 @@
 #include <string.h>
 
 #include "command-line.h"
+#include "daemon.h"
 #include "datapath.h"
 #include "fault.h"
 #include "openflow.h"
@@ -55,6 +56,7 @@
 static void parse_options(int argc, char *argv[]);
 static void usage(void) NO_RETURN;
 
+static const char *listen_vconn_name;
 static struct datapath *dp;
 static uint64_t dpid = UINT64_MAX;
 static char *port_list;
@@ -76,6 +78,19 @@ main(int argc, char *argv[])
     }
 
     error = dp_new(&dp, dpid, rconn_new(argv[optind], 128));
+    if (listen_vconn_name) {
+        struct vconn *listen_vconn;
+        int retval;
+        
+        retval = vconn_open(listen_vconn_name, &listen_vconn);
+        if (retval && retval != EAGAIN) {
+            fatal(retval, "opening %s", listen_vconn_name);
+        }
+        if (!vconn_is_passive(listen_vconn)) {
+            fatal(0, "%s is not a passive vconn", listen_vconn_name);
+        }
+        dp_add_listen_vconn(dp, listen_vconn);
+    }
     if (error) {
         fatal(error, "could not create datapath");
     }
@@ -88,6 +103,8 @@ main(int argc, char *argv[])
         fatal(error, "could not listen for vlog connections");
     }
 
+    daemonize();
+
     for (;;) {
         dp_run(dp);
         dp_wait(dp);
@@ -121,6 +138,9 @@ parse_options(int argc, char *argv[])
     static struct option long_options[] = {
         {"interfaces",  required_argument, 0, 'i'},
         {"datapath-id", required_argument, 0, 'd'},
+        {"listen",      required_argument, 0, 'l'},
+        {"detach",      no_argument, 0, 'D'},
+        {"pidfile",     optional_argument, 0, 'P'},
         {"verbose",     optional_argument, 0, 'v'},
         {"help",        no_argument, 0, 'h'},
         {"version",     no_argument, 0, 'V'},
@@ -158,6 +178,14 @@ parse_options(int argc, char *argv[])
             printf("%s "VERSION" compiled "__DATE__" "__TIME__"\n", argv[0]);
             exit(EXIT_SUCCESS);
 
+        case 'D':
+            set_detach();
+            break;
+
+        case 'P':
+            set_pidfile(optarg ? optarg : "switch.pid");
+            break;
+
         case 'v':
             vlog_set_verbosity(optarg);
             break;
@@ -170,6 +198,13 @@ parse_options(int argc, char *argv[])
             }
             break;
 
+        case 'l':
+            if (listen_vconn_name) {
+                fatal(0, "-l or --listen may be only specified once");
+            }
+            listen_vconn_name = optarg;
+            break;
+
         VCONN_SSL_OPTION_HANDLERS
 
         case '?':
@@ -189,14 +224,21 @@ usage(void)
            "usage: %s [OPTIONS] CONTROLLER\n"
            "where CONTROLLER is an active OpenFlow connection method.\n",
            program_name, program_name);
-    vconn_usage(true, false);
-    printf("\nOptions:\n"
+    vconn_usage(true, true);
+    printf("\nConfiguration options:\n"
            "  -i, --interfaces=NETDEV[,NETDEV]...\n"
            "                          add specified initial switch ports\n"
            "  -d, --datapath-id=ID    Use ID as the OpenFlow switch ID\n"
            "                          (ID must consist of 12 hex digits)\n"
+           "  -l, --listen=METHOD     allow management connections on METHOD\n"
+           "                          (a passive OpenFlow connection method)\n"
+           "\nOther options:\n"
+           "  -D, --detach            run in background as daemon\n"
+           "  -P, --pidfile[=FILE]    create pidfile (default: %s/switch.pid)\n"
+           "  -v, --verbose=MODULE:FACILITY:LEVEL  configure logging levels\n"
            "  -v, --verbose           set maximum verbosity level\n"
            "  -h, --help              display this help message\n"
-           "  -V, --version           display version information\n");
+           "  -V, --version           display version information\n",
+        RUNDIR);
     exit(EXIT_SUCCESS);
 }