Rename utility functions to avoid partner namespace conflicts.
[openvswitch] / switch / switch.c
index 61fbfb98590b07c3b16b2fa72903587ad7790d21..cd14f051ea06e55ea4656d0debf868a9abdc3fb4 100644 (file)
 
 
 /* Strings to describe the manufacturer, hardware, and software.  This data 
- * is queriable through the version stats message. */
-char mfr_desc[VERSION_STR_LEN] = "Nicira Networks";
-char hw_desc[VERSION_STR_LEN] = "Reference User-Space Switch";
-char sw_desc[VERSION_STR_LEN] = VERSION;
+ * is queriable through the switch description stats message. */
+char mfr_desc[DESC_STR_LEN] = "Nicira Networks";
+char hw_desc[DESC_STR_LEN] = "Reference User-Space Switch";
+char sw_desc[DESC_STR_LEN] = VERSION;
+char serial_num[SERIAL_NUM_LEN] = "None";
 
 static void parse_options(int argc, char *argv[]);
 static void usage(void) NO_RETURN;
@@ -92,13 +93,13 @@ main(int argc, char *argv[])
     signal(SIGPIPE, SIG_IGN);
 
     if (argc - optind != 1) {
-        fatal(0, "missing controller argument; use --help for usage");
+        ofp_fatal(0, "missing controller argument; use --help for usage");
     }
 
     rconn = rconn_create(60, max_backoff);
     error = rconn_connect(rconn, argv[optind]);
     if (error == EAFNOSUPPORT) {
-        fatal(0, "no support for %s vconn", argv[optind]);
+        ofp_fatal(0, "no support for %s vconn", argv[optind]);
     }
     error = dp_new(&dp, dpid, rconn);
     if (listen_vconn_name) {
@@ -107,15 +108,15 @@ main(int argc, char *argv[])
         
         retval = vconn_open(listen_vconn_name, &listen_vconn);
         if (retval && retval != EAGAIN) {
-            fatal(retval, "opening %s", listen_vconn_name);
+            ofp_fatal(retval, "opening %s", listen_vconn_name);
         }
         if (!vconn_is_passive(listen_vconn)) {
-            fatal(0, "%s is not a passive vconn", listen_vconn_name);
+            ofp_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");
+        ofp_fatal(error, "could not create datapath");
     }
     if (port_list) {
         add_ports(dp, port_list); 
@@ -123,9 +124,10 @@ main(int argc, char *argv[])
 
     error = vlog_server_listen(NULL, NULL);
     if (error) {
-        fatal(error, "could not listen for vlog connections");
+        ofp_fatal(error, "could not listen for vlog connections");
     }
 
+    die_if_already_running();
     daemonize();
 
     for (;;) {
@@ -150,7 +152,7 @@ add_ports(struct datapath *dp, char *port_list)
          port = strtok_r(NULL, ",,", &save_ptr)) {
         int error = dp_add_port(dp, port);
         if (error) {
-            fatal(error, "failed to add port %s", port);
+            ofp_fatal(error, "failed to add port %s", port);
         }
     }
 }
@@ -162,7 +164,8 @@ parse_options(int argc, char *argv[])
         OPT_MAX_BACKOFF = UCHAR_MAX + 1,
         OPT_MFR_DESC,
         OPT_HW_DESC,
-        OPT_SW_DESC
+        OPT_SW_DESC,
+        OPT_SERIAL_NUM
     };
 
     static struct option long_options[] = {
@@ -172,12 +175,14 @@ parse_options(int argc, char *argv[])
         {"listen",      required_argument, 0, 'l'},
         {"detach",      no_argument, 0, 'D'},
         {"pidfile",     optional_argument, 0, 'P'},
+        {"force",       no_argument, 0, 'f'},
         {"verbose",     optional_argument, 0, 'v'},
         {"help",        no_argument, 0, 'h'},
         {"version",     no_argument, 0, 'V'},
         {"mfr-desc",    required_argument, 0, OPT_MFR_DESC},
         {"hw-desc",     required_argument, 0, OPT_HW_DESC},
         {"sw-desc",     required_argument, 0, OPT_SW_DESC},
+        {"serial_num",  required_argument, 0, OPT_SERIAL_NUM},
         VCONN_SSL_LONG_OPTIONS
         {0, 0, 0, 0},
     };
@@ -196,12 +201,13 @@ parse_options(int argc, char *argv[])
         case 'd':
             if (strlen(optarg) != 12
                 || strspn(optarg, "0123456789abcdefABCDEF") != 12) {
-                fatal(0, "argument to -d or --datapath-id must be "
-                      "exactly 12 hex digits");
+                ofp_fatal(0, "argument to -d or --datapath-id must be "
+                          "exactly 12 hex digits");
             }
             dpid = strtoll(optarg, NULL, 16);
             if (!dpid) {
-                fatal(0, "argument to -d or --datapath-id must be nonzero");
+                ofp_fatal(0, "argument to -d or --datapath-id must "
+                          "be nonzero");
             }
             break;
 
@@ -220,6 +226,10 @@ parse_options(int argc, char *argv[])
             set_pidfile(optarg);
             break;
 
+        case 'f':
+            ignore_existing_pidfile();
+            break;
+
         case 'v':
             vlog_set_verbosity(optarg);
             break;
@@ -235,7 +245,7 @@ parse_options(int argc, char *argv[])
         case OPT_MAX_BACKOFF:
             max_backoff = atoi(optarg);
             if (max_backoff < 1) {
-                fatal(0, "--max-backoff argument must be at least 1");
+                ofp_fatal(0, "--max-backoff argument must be at least 1");
             } else if (max_backoff > 3600) {
                 max_backoff = 3600;
             }
@@ -253,9 +263,13 @@ parse_options(int argc, char *argv[])
             strncpy(sw_desc, optarg, sizeof sw_desc);
             break;
 
+        case OPT_SERIAL_NUM:
+            strncpy(serial_num, optarg, sizeof serial_num);
+            break;
+
         case 'l':
             if (listen_vconn_name) {
-                fatal(0, "-l or --listen may be only specified once");
+                ofp_fatal(0, "-l or --listen may be only specified once");
             }
             listen_vconn_name = optarg;
             break;
@@ -292,6 +306,7 @@ usage(void)
            "\nOther options:\n"
            "  -D, --detach            run in background as daemon\n"
            "  -P, --pidfile[=FILE]    create pidfile (default: %s/switch.pid)\n"
+           "  -f, --force             with -P, start even if already running\n"
            "  -v, --verbose=MODULE[:FACILITY[:LEVEL]]  set logging levels\n"
            "  -v, --verbose           set maximum verbosity level\n"
            "  -h, --help              display this help message\n"