ovs-vsctl: Set timeout to a default value of five seconds
authorJustin Pettit <jpettit@nicira.com>
Mon, 14 Dec 2009 21:59:58 +0000 (13:59 -0800)
committerJustin Pettit <jpettit@nicira.com>
Mon, 14 Dec 2009 22:51:17 +0000 (14:51 -0800)
In general, we don't want ovs-vsctl to wait forever to connect to the
database, as ovs-vsctl is used extensively in init scripts and the
system will not boot.  Use a default value of five seconds as a
stop-gap.  Eventually, we'll switch to a model of connection attempts,
since using time-based approach is kind of a hack.

utilities/ovs-vsctl.8.in
utilities/ovs-vsctl.c

index 0515760..17214bd 100644 (file)
@@ -101,9 +101,11 @@ Prevents \fBovs\-vsctl\fR from actually modifying the database.
 .
 .IP "\fB-t \fIsecs\fR"
 .IQ "\fB--timeout=\fIsecs\fR"
-Limits runtime to approximately \fIsecs\fR seconds.  If the timeout
-expires, \fBovs\-vsctl\fR will exit with a \fBSIGALRM\fR signal.
-(This would normally happen only if the database cannot be contacted.)
+Limits runtime to approximately \fIsecs\fR seconds.  A value of 
+zero will cause \fBovs\-vsctl\fR to wait forever.  If the timeout expires, 
+\fBovs\-vsctl\fR will exit with a \fBSIGALRM\fR signal.  If this option is
+not used, \fBovs\-vsctl\fR uses a timeout of five seconds.
+(A timeout would normally happen only if the database cannot be contacted.)
 .
 .so lib/vlog.man
 .
index 1ec4979..d24844b 100644 (file)
@@ -48,6 +48,9 @@ static bool oneline;
 /* --dry-run: Do not commit any changes. */
 static bool dry_run;
 
+/* --timeout: Time to wait for a connection to 'db'. */
+static int timeout = 5;
+
 static void vsctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
 static char *default_db(void);
 static void usage(void) NO_RETURN;
@@ -74,6 +77,10 @@ main(int argc, char *argv[])
     vlog_set_levels(VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN);
     parse_options(argc, argv);
 
+    if (timeout) {
+        time_alarm(timeout);
+    }
+
     /* Log our arguments.  This is often valuable for debugging systems. */
     ds_init(&args);
     for (i = 1; i < argc; i++) {
@@ -197,11 +204,9 @@ parse_options(int argc, char *argv[])
 
         case 't':
             timeout = strtoul(optarg, NULL, 10);
-            if (timeout <= 0) {
-                ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
+            if (timeout < 0) {
+                ovs_fatal(0, "value %s on -t or --timeout is invalid",
                           optarg);
-            } else {
-                time_alarm(timeout);
             }
             break;