Fix bug in r253719: fix command line watchdog disable.

r253719 disallowed watchdog(8) from disabling the watchdog
by breaking the ability to pass 0 as a timeout arg.  Fix this.
This commit is contained in:
Alfred Perlstein 2013-08-10 01:48:15 +00:00
parent 477f81c83e
commit 907745a810
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=254173

View File

@ -60,7 +60,8 @@ __FBSDID("$FreeBSD$");
#include <getopt.h> #include <getopt.h>
static long fetchtimeout(int opt, const char *longopt, const char *myoptarg); static long fetchtimeout(int opt,
const char *longopt, const char *myoptarg, int zero_ok);
static void parseargs(int, char *[]); static void parseargs(int, char *[]);
static int seconds_to_pow2ns(int); static int seconds_to_pow2ns(int);
static void sighandler(int); static void sighandler(int);
@ -219,7 +220,7 @@ parse_timeout_to_pow2ns(char opt, const char *longopt, const char *myoptarg)
if (!longopt) if (!longopt)
shortopt[1] = opt; shortopt[1] = opt;
a = fetchtimeout(opt, longopt, myoptarg); a = fetchtimeout(opt, longopt, myoptarg, 1);
if (a == 0) if (a == 0)
rv = WD_TO_NEVER; rv = WD_TO_NEVER;
@ -487,7 +488,7 @@ usage(void)
} }
static long static long
fetchtimeout(int opt, const char *longopt, const char *myoptarg) fetchtimeout(int opt, const char *longopt, const char *myoptarg, int zero_ok)
{ {
const char *errstr; const char *errstr;
char *p; char *p;
@ -499,7 +500,7 @@ fetchtimeout(int opt, const char *longopt, const char *myoptarg)
rv = strtol(myoptarg, &p, 0); rv = strtol(myoptarg, &p, 0);
if ((p != NULL && *p != '\0') || errno != 0) if ((p != NULL && *p != '\0') || errno != 0)
errstr = "is not a number"; errstr = "is not a number";
if (rv <= 0) if (rv < 0 || (!zero_ok && rv == 0))
errstr = "must be greater than zero"; errstr = "must be greater than zero";
if (errstr) { if (errstr) {
if (longopt) if (longopt)
@ -721,7 +722,7 @@ parseargs(int argc, char *argv[])
break; break;
#endif #endif
case 's': case 's':
nap = fetchtimeout(c, NULL, optarg); nap = fetchtimeout(c, NULL, optarg, 0);
break; break;
case 'S': case 'S':
do_syslog = 0; do_syslog = 0;
@ -734,7 +735,8 @@ parseargs(int argc, char *argv[])
timeout); timeout);
break; break;
case 'T': case 'T':
carp_thresh_seconds = fetchtimeout(c, "NULL", optarg); carp_thresh_seconds =
fetchtimeout(c, "NULL", optarg, 0);
break; break;
case 'w': case 'w':
do_timedog = 1; do_timedog = 1;
@ -742,7 +744,7 @@ parseargs(int argc, char *argv[])
case 0: case 0:
lopt = longopts[longindex].name; lopt = longopts[longindex].name;
if (!strcmp(lopt, "pretimeout")) { if (!strcmp(lopt, "pretimeout")) {
pretimeout = fetchtimeout(0, lopt, optarg); pretimeout = fetchtimeout(0, lopt, optarg, 0);
} else if (!strcmp(lopt, "pretimeout-action")) { } else if (!strcmp(lopt, "pretimeout-action")) {
pretimeout_act = timeout_act_str2int(lopt, pretimeout_act = timeout_act_str2int(lopt,
optarg); optarg);