]> granicus.if.org Git - sysstat/commitdiff
simtest: Update code so that environment variables can be tested
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 1 Nov 2019 08:36:10 +0000 (09:36 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 1 Nov 2019 08:36:10 +0000 (09:36 +0100)
Now read the contents of environment variables if option --getenv has
been entered on the command line (apply for sar, sadc, sadf and iostat
for now).

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
iostat.c
sa_common.c
sadc.c
sadf.c
sar.c
systest.c
systest.h

index be65a8ebb284df239745b35df4d6f06620c5a70e..5aa7a062b93f72387ad2be0d6394d53fa04111ba 100644 (file)
--- a/iostat.c
+++ b/iostat.c
 char *sccsid(void) { return (SCCSID); }
 #endif
 
+#ifdef TEST
+extern int __env;
+#endif
+
 struct stats_cpu *st_cpu[2];
 unsigned long long uptime_cs[2] = {0, 0};
 unsigned long long tot_jiffies[2] = {0, 0};
@@ -1849,9 +1853,6 @@ int main(int argc, char **argv)
        init_nls();
 #endif
 
-       /* Init color strings */
-       init_colors();
-
        /* Process args... */
        while (opt < argc) {
 
@@ -1905,6 +1906,13 @@ int main(int argc, char **argv)
                        opt++;
                }
 
+#ifdef TEST
+               else if (!strncmp(argv[opt], "--getenv", 8)) {
+                       __env = TRUE;
+                       opt++;
+               }
+#endif
+
                else if (!strncmp(argv[opt], "--dec=", 6) && (strlen(argv[opt]) == 7)) {
                        /* Get number of decimal places */
                        dplaces_nr = atoi(argv[opt] + 6);
@@ -2098,6 +2106,9 @@ int main(int argc, char **argv)
                count = 1;
        }
 
+       /* Init color strings */
+       init_colors();
+
        /* Default: Display CPU and DISK reports */
        if (!report_set) {
                flags |= I_D_CPU + I_D_DISK;
index d93f9682fd4771f6aca6897c26f554de711925b3..de9c28aa48f6dd1a6b2528bd2ab43959d4c74889 100644 (file)
@@ -244,6 +244,10 @@ int set_default_file(char *datafile, int d_off, int sa_name)
        datafile[MAX_FILE_LEN - 1] = '\0';
        default_file_used = TRUE;
 
+#ifdef DEBUG
+       fprintf(stderr, "%s: Datafile: %s\n", __FUNCTION__, datafile);
+#endif
+
        return ((err < 0) || (err >= MAX_FILE_LEN));
 }
 
diff --git a/sadc.c b/sadc.c
index 22e259c04494951211acfd8c6c5e5a44050f1c68..5516a81e52c7009e48b30b8d10838f1d2ee1ebd3 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -57,6 +57,7 @@ char *sccsid(void) { return (SCCSID); }
 
 #ifdef TEST
 extern time_t __unix_time;
+extern int __env;
 #endif
 
 extern char *tzname[2];
@@ -1252,6 +1253,10 @@ int main(int argc, char **argv)
                }
 
 #ifdef TEST
+               else if (!strncmp(argv[opt], "--getenv", 8)) {
+                       __env = TRUE;
+               }
+
                else if (!strncmp(argv[opt], "--unix_time=", 12)) {
                        if (strspn(argv[opt] + 12, DIGITS) != strlen(argv[opt] + 12)) {
                                usage(argv[0]);
diff --git a/sadf.c b/sadf.c
index 570bcf9c9c5ffe976d7b71a00f7e6a6c65677b15..a931b09b3903c07ba9f5246f96d0af3017c6ac81 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -50,6 +50,7 @@ char *sccsid(void) { return (SCCSID); }
 #endif
 
 #ifdef TEST
+extern int __env;
 void int_handler(int n) { return; }
 #endif
 
@@ -1569,6 +1570,13 @@ int main(int argc, char **argv)
                        }
                }
 
+#ifdef TEST
+               else if (!strncmp(argv[opt], "--getenv", 8)) {
+                       __env = TRUE;
+                       opt++;
+               }
+#endif
+
                else if (!strcmp(argv[opt], "-O")) {
                        /* Parse output options */
                        if (!argv[++opt] || sar_options) {
diff --git a/sar.c b/sar.c
index 07b879aef378be1febe222bab7169a4df1ee98d2..d946a497ee8c8bf6bd16661a74303247cb4af8b2 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -47,6 +47,7 @@ char *sccsid(void) { return (SCCSID); }
 
 #ifdef TEST
 extern time_t __unix_time;
+extern int __env;
 #endif
 
 /* Interval and count parameters */
@@ -1275,9 +1276,6 @@ int main(int argc, char **argv)
        init_nls();
 #endif
 
-       /* Init color strings */
-       init_colors();
-
        tm_start.use = tm_end.use = FALSE;
 
        /* Allocate and init activity bitmaps */
@@ -1435,6 +1433,11 @@ int main(int argc, char **argv)
                }
 
 #ifdef TEST
+               else if (!strncmp(argv[opt], "--getenv", 8)) {
+                       __env = TRUE;
+                       opt++;
+               }
+
                else if (!strncmp(argv[opt], "--unix_time=", 12)) {
                        if (strspn(argv[opt] + 12, DIGITS) != strlen(argv[opt] + 12)) {
                                usage(argv[0]);
@@ -1492,6 +1495,9 @@ int main(int argc, char **argv)
                }
        }
 
+       /* Init color strings */
+       init_colors();
+
        /* 'sar' is equivalent to 'sar -f' */
        if ((argc == 1) ||
            (((interval < 0) || INTERVAL_SET(flags)) && !from_file[0] && !to_file[0])) {
index 1058be9782a7d709a0be44313397512e38f528ac..4c762dd19273dad8ac4b2133f77180cb9d16fe6e 100644 (file)
--- a/systest.c
+++ b/systest.c
@@ -35,6 +35,8 @@
 #include "systest.h"
 
 time_t __unix_time = 0;
+int __env = 0;
+
 extern long interval;
 extern int sigint_caught;
 
@@ -102,9 +104,13 @@ int get_fs_stat(char *c, struct statvfs *buf)
  * Test mode: Ignore environment variable value.
  ***************************************************************************
  */
-char *get_env_value(char *c)
+char *get_env_value(const char *c)
 {
-       return NULL;
+       if (!__env)
+               return NULL;
+
+       fprintf(stderr, "Reading contents of %s\n", c);
+       return getenv(c);
 }
 
 /*
index 4cd82b4ce714857349152825b6ac2032229969fa..6407a12c9ed7f7bc340a412d6bae626ef2cccabd 100644 (file)
--- a/systest.h
+++ b/systest.h
@@ -62,7 +62,7 @@
 void close_list
        (DIR *);
 char *get_env_value
-       (char *);
+       (const char *);
 int get_fs_stat
        (char *, struct statvfs *);
 char *get_realname