]> granicus.if.org Git - sysstat/commitdiff
sar: Add new environment variable S_REPEAT_HEADER (#332)
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 17 Aug 2022 09:29:20 +0000 (11:29 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 17 Aug 2022 09:38:40 +0000 (11:38 +0200)
Add new environment variable S_REPEAT_HEADER.
This variable will contain the number of lines after which a header has
to be displayed by sar when stdout is not a terminal.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
common.c
common.h

index 94e94b50f2c4d912aa5b915deffddd46d088e6fc..b92be22973ecb2b334ea81976f6a66ec7e73b631 100644 (file)
--- a/common.c
+++ b/common.c
@@ -637,6 +637,8 @@ int print_gal_header(struct tm *rectime, char *sysname, char *release,
 /*
  ***************************************************************************
  * Get number of rows for current window.
+ * If stdout is not a terminal then use the value given by environment
+ * variable S_REPEAT_HEADER if existent.
  *
  * RETURNS:
  * Number of rows.
@@ -645,17 +647,28 @@ int print_gal_header(struct tm *rectime, char *sysname, char *release,
 int get_win_height(void)
 {
        struct winsize win;
+       char *e;
        /*
         * This default value will be used whenever STDOUT
-        * is redirected to a pipe or a file
+        * is redirected to a pipe or a file and S_REPEAT_HEADER variable is not set
         */
        int rows = 3600 * 24;
 
+       /* Get number of lines of current terminal */
        if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1) {
                if (win.ws_row > 2) {
                        rows = win.ws_row - 2;
                }
        }
+       /* STDOUT is not a terminal. Look for S_REPEAT_HEADER variable's value instead */
+       else if ((e = __getenv(ENV_REPEAT_HEADER)) != NULL) {
+               if (strspn(e, DIGITS) == strlen(e)) {
+                       int v = atol(e);
+                       if (v > 0) {
+                               rows = v;
+                       }
+               }
+       }
        return rows;
 }
 
index 9aed879e39e8a659ef0ec8bdc710520930e952bf..7efc7caae8751ecee6651afe26f76aeb02ccbbf0 100644 (file)
--- a/common.h
+++ b/common.h
 #define ENV_TIME_DEFTM         "S_TIME_DEF_TIME"
 #define ENV_COLORS             "S_COLORS"
 #define ENV_COLORS_SGR         "S_COLORS_SGR"
+#define ENV_REPEAT_HEADER      "S_REPEAT_HEADER"
 
 #define C_NEVER                        "never"
 #define C_ALWAYS               "always"