ovsdb-server: Make database command-line argument optional.
[sliver-openvswitch.git] / ovsdb / ovsdb-server.c
index 5477e86..9c01c4e 100644 (file)
@@ -25,6 +25,7 @@
 #include "column.h"
 #include "command-line.h"
 #include "daemon.h"
+#include "dirs.h"
 #include "file.h"
 #include "json.h"
 #include "jsonrpc.h"
@@ -105,6 +106,7 @@ main(int argc, char *argv[])
     if (error) {
         ovs_fatal(0, "%s", ovsdb_error_to_string(error));
     }
+    free(file_name);
 
     jsonrpc = ovsdb_jsonrpc_server_create(db);
     reconfigure_from_db(jsonrpc, db, &remotes);
@@ -738,14 +740,19 @@ parse_options(int argc, char *argv[], char **file_namep,
     argc -= optind;
     argv += optind;
 
-    if (argc > 1) {
+    switch (argc) {
+    case 0:
+        *file_namep = xasprintf("%s/openvswitch/conf.db", ovs_sysconfdir());
+        break;
+
+    case 1:
+        *file_namep = xstrdup(argv[0]);
+        break;
+
+    default:
         ovs_fatal(0, "database file is only non-option argument; "
                 "use --help for usage");
-    } else if (argc < 1) {
-        ovs_fatal(0, "missing database file argument; use --help for usage");
     }
-
-    *file_namep = argv[0];
 }
 
 static void