Add ability to specify watch interval using environment variable WATCH_INTERVAL
This commit is contained in:
parent
48a201c46f
commit
f0a3cd4b1f
14
watch.c
14
watch.c
@ -671,6 +671,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int optc;
|
int optc;
|
||||||
double interval = 2;
|
double interval = 2;
|
||||||
|
char *interval_string;
|
||||||
char *command;
|
char *command;
|
||||||
char **command_argv;
|
char **command_argv;
|
||||||
int command_length = 0; /* not including final \0 */
|
int command_length = 0; /* not including final \0 */
|
||||||
@ -704,6 +705,10 @@ int main(int argc, char *argv[])
|
|||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
atexit(close_stdout);
|
atexit(close_stdout);
|
||||||
|
|
||||||
|
interval_string = getenv("WATCH_INTERVAL");
|
||||||
|
if(interval_string != NULL)
|
||||||
|
interval = strtod_nol_or_err(interval_string, _("Could not parse interval from WATCH_INTERVAL"));
|
||||||
|
|
||||||
while ((optc =
|
while ((optc =
|
||||||
getopt_long(argc, argv, "+bced::ghn:pvtx", longopts, (int *)0))
|
getopt_long(argc, argv, "+bced::ghn:pvtx", longopts, (int *)0))
|
||||||
!= EOF) {
|
!= EOF) {
|
||||||
@ -733,10 +738,6 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
interval = strtod_nol_or_err(optarg, _("failed to parse argument"));
|
interval = strtod_nol_or_err(optarg, _("failed to parse argument"));
|
||||||
if (interval < 0.1)
|
|
||||||
interval = 0.1;
|
|
||||||
if (interval > UINT_MAX)
|
|
||||||
interval = UINT_MAX;
|
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
precise_timekeeping = 1;
|
precise_timekeeping = 1;
|
||||||
@ -753,6 +754,11 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (interval < 0.1)
|
||||||
|
interval = 0.1;
|
||||||
|
if (interval > UINT_MAX)
|
||||||
|
interval = UINT_MAX;
|
||||||
|
|
||||||
if (optind >= argc)
|
if (optind >= argc)
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user