Prepare for post-2.2.0 (2.2.90).
[sliver-openvswitch.git] / utilities / ovs-appctl.c
index 241b6c0..a6fbebd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -63,13 +63,14 @@ main(int argc, char *argv[])
     }
 
     if (cmd_error) {
+        jsonrpc_close(client);
         fputs(cmd_error, stderr);
         ovs_error(0, "%s: server returned an error", target);
         exit(2);
     } else if (cmd_result) {
         fputs(cmd_result, stdout);
     } else {
-        NOT_REACHED();
+        OVS_NOT_REACHED();
     }
 
     jsonrpc_close(client);
@@ -97,6 +98,7 @@ Common commands:\n\
       'off', 'emer', 'err', 'warn', 'info', or 'dbg' ('dbg', bydefault)\n\
   vlog/reopen        Make the program reopen its log file\n\
 Other options:\n\
+  --timeout=SECS     wait at most SECS seconds for a response\n\
   -h, --help         Print this helpful information\n\
   -V, --version      Display ovs-appctl version information\n",
            program_name, program_name);
@@ -111,6 +113,7 @@ parse_command_line(int argc, char *argv[])
         {"execute", no_argument, NULL, 'e'},
         {"help", no_argument, NULL, 'h'},
         {"version", no_argument, NULL, 'V'},
+        {"timeout", required_argument, NULL, 'T'},
         {NULL, 0, NULL, 0},
     };
     const char *target;
@@ -147,6 +150,10 @@ parse_command_line(int argc, char *argv[])
             usage();
             break;
 
+        case 'T':
+            time_alarm(atoi(optarg));
+            break;
+
         case 'V':
             ovs_print_version(0, 0);
             exit(EXIT_SUCCESS);
@@ -155,7 +162,7 @@ parse_command_line(int argc, char *argv[])
             exit(EXIT_FAILURE);
 
         default:
-            NOT_REACHED();
+            OVS_NOT_REACHED();
         }
     }
 
@@ -174,6 +181,7 @@ connect_to_target(const char *target)
     char *socket_name;
     int error;
 
+#ifndef _WIN32
     if (target[0] != '/') {
         char *pidfile_name;
         pid_t pid;
@@ -186,6 +194,12 @@ connect_to_target(const char *target)
         free(pidfile_name);
         socket_name = xasprintf("%s/%s.%ld.ctl",
                                 ovs_rundir(), target, (long int) pid);
+#else
+    /* On windows, if the 'target' contains ':', we make an assumption that
+     * it is an absolute path. */
+    if (!strchr(target, ':')) {
+        socket_name = xasprintf("%s/%s.ctl", ovs_rundir(), target);
+#endif
     } else {
         socket_name = xstrdup(target);
     }