]> granicus.if.org Git - sysstat/commitdiff
sar: Fix return code sent by write_stats() function
authorSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 22 Dec 2020 11:22:30 +0000 (12:22 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Tue, 22 Dec 2020 11:22:30 +0000 (12:22 +0100)
Make sure that a line of statistics has actually been displayed to
return 1 for the status code value.
When an activity has no item at all for current sample, we should not
return a status code of 1 else we won't display the header line for
next sample.

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

diff --git a/sar.c b/sar.c
index 5d36ebd5b1a5998496cc4e994ea72c8e214c8ee1..4dc6a8d858b9ed66394762c5aeb4cfe85c556bd3 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -435,7 +435,7 @@ void write_stats_avg(int curr, int read_from_file, unsigned int act_id)
 int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
                int use_tm_end, int reset, unsigned int act_id, int reset_cd)
 {
-       int i, prev_hour;
+       int i, prev_hour, rc = 0;
        unsigned long long itv;
        static int cross_day = FALSE;
 
@@ -514,10 +514,11 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
                if (IS_SELECTED(act[i]->options) && (act[i]->nr[curr] > 0)) {
                        /* Display current activity statistics */
                        (*act[i]->f_print)(act[i], !curr, curr, itv);
+                       rc = 1;
                }
        }
 
-       return 1;
+       return rc;
 }
 
 /*
@@ -701,7 +702,6 @@ void read_sadc_stat_bunch(int curr)
                                reallocate_all_buffers(act[p], act[p]->nr[curr]);
                        }
 
-
                        /*
                         * For persistent activities, we must make sure that no statistics
                          * from a previous iteration remain, especially if the number