From: Justin Pettit Date: Mon, 14 Dec 2009 21:59:58 +0000 (-0800) Subject: ovs-vsctl: Set timeout to a default value of five seconds X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a39a859a3066bb637de16edd4f26eab77fb594a6;p=openvswitch ovs-vsctl: Set timeout to a default value of five seconds 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. --- diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 0515760b..17214bd9 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -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 . diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 1ec49792..d24844bf 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -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;