]> granicus.if.org Git - procps-ng/commitdiff
Add ability to specify watch interval using environment variable WATCH_INTERVAL
authorHarry Wagstaff <harry.wagstaff@gmail.com>
Mon, 23 Apr 2018 10:34:08 +0000 (11:34 +0100)
committerCraig Small <csmall@dropbear.xyz>
Tue, 12 May 2020 09:12:21 +0000 (19:12 +1000)
watch.c

diff --git a/watch.c b/watch.c
index a73eab5959810f881ee37ababe62f11c536d6aac..a66beb9703b00280ebab1923845d462ee288ebc8 100644 (file)
--- a/watch.c
+++ b/watch.c
@@ -668,6 +668,7 @@ int main(int argc, char *argv[])
 {
        int optc;
        double interval = 2;
+       char *interval_string;
        char *command;
        char **command_argv;
        int command_length = 0; /* not including final \0 */
@@ -701,6 +702,10 @@ int main(int argc, char *argv[])
        textdomain(PACKAGE);
        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 =
                getopt_long(argc, argv, "+bced::ghn:pvtx", longopts, (int *)0))
               != EOF) {
@@ -730,10 +735,6 @@ int main(int argc, char *argv[])
                        break;
                case 'n':
                        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;
                case 'p':
                        precise_timekeeping = 1;
@@ -750,6 +751,11 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (interval < 0.1)
+               interval = 0.1;
+       if (interval > UINT_MAX)
+               interval = UINT_MAX;
+
        if (optind >= argc)
                usage(stderr);