]> granicus.if.org Git - sysstat/blobdiff - sar.c
mpstat.h: Remove unneeded 'aligned' attribute
[sysstat] / sar.c
diff --git a/sar.c b/sar.c
index 372f486f4d3c31350415350df58b76589a9b7d51..c49e777074cbb5abe23852045e8a322bd90a1109 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -1,6 +1,6 @@
 /*
  * sar: report system activity
- * (C) 1999-2020 by Sebastien GODARD (sysstat <at> orange.fr)
+ * (C) 1999-2021 by Sebastien GODARD (sysstat <at> orange.fr)
  *
  ***************************************************************************
  * This program is free software; you can redistribute it and/or modify it *
@@ -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;
 
@@ -487,20 +487,15 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
        }
 
        /* Check time (2) */
-       if (use_tm_start && (datecmp(&rectime, &tm_start, cross_day) < 0))
-               /* it's too soon... */
-               return 0;
-
-       /* Get interval value in 1/100th of a second */
-       get_itv_value(&record_hdr[curr], &record_hdr[!curr], &itv);
-
-       /* Check time (3) */
        if (use_tm_end && (datecmp(&rectime, &tm_end, cross_day) > 0)) {
-               /* It's too late... */
+               /* End time exceeded */
                *cnt = 0;
                return 0;
        }
 
+       /* Get interval value in 1/100th of a second */
+       get_itv_value(&record_hdr[curr], &record_hdr[!curr], &itv);
+
        avg_count++;
 
        /* Test stdout */
@@ -514,10 +509,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 +697,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
@@ -788,7 +783,8 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf
                 * Start with reading current sample's record header.
                 */
                *eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[*curr],
-                                        &file_hdr, arch_64, endian_mismatch, UEOF_STOP, b_size, flags);
+                                        &file_hdr, arch_64, endian_mismatch, UEOF_STOP, b_size,
+                                        flags, &sar_fmt);
                rtype = record_hdr[*curr].record_type;
 
                if ((lines >= rows) || !lines) {
@@ -804,8 +800,10 @@ void handle_curr_act_stats(int ifd, off_t fpos, int *curr, long *cnt, int *eosaf
 
                if (rtype != R_COMMENT) {
                        /* Read the extra fields since it's not a special record */
-                       read_file_stat_bunch(act, *curr, ifd, file_hdr.sa_act_nr, file_actlst,
-                                            endian_mismatch, arch_64, file, file_magic, UEOF_STOP);
+                       if (read_file_stat_bunch(act, *curr, ifd, file_hdr.sa_act_nr, file_actlst,
+                                                endian_mismatch, arch_64, file, file_magic, UEOF_STOP))
+                               /* Error or unexpected EOF */
+                               break;
                }
                else {
                        /* Display comment */
@@ -936,7 +934,7 @@ void read_header_data(void)
        if ((file_hdr.act_size != FILE_ACTIVITY_SIZE) ||
            (file_hdr.rec_size != RECORD_HEADER_SIZE)) {
 #ifdef DEBUG
-               fprintf(stderr, "%s: act_size=%u/%lu rec_size=%u/%lu\n", __FUNCTION__,
+               fprintf(stderr, "%s: act_size=%u/%zu rec_size=%u/%zu\n", __FUNCTION__,
                        file_hdr.act_size, FILE_ACTIVITY_SIZE, file_hdr.rec_size, RECORD_HEADER_SIZE);
 #endif
                print_read_error(INCONSISTENT_INPUT_DATA);
@@ -1032,7 +1030,7 @@ void read_stats_from_file(char from_file[])
                 */
                do {
                        if (read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[0], &file_hdr,
-                                           arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags)) {
+                                           arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags, &sar_fmt)) {
                                /* End of sa data file */
                                return;
                        }
@@ -1049,9 +1047,12 @@ void read_stats_from_file(char from_file[])
                                 * OK: Previous record was not a special one.
                                 * So read now the extra fields.
                                 */
-                               read_file_stat_bunch(act, 0, ifd, file_hdr.sa_act_nr,
-                                                    file_actlst, endian_mismatch, arch_64,
-                                                    from_file, &file_magic, UEOF_STOP);
+                               if (read_file_stat_bunch(act, 0, ifd, file_hdr.sa_act_nr,
+                                                        file_actlst, endian_mismatch, arch_64,
+                                                        from_file, &file_magic, UEOF_STOP))
+                                       /* Possible unexpected EOF */
+                                       return;
+
                                if (sa_get_record_timestamp_struct(flags + S_F_LOCAL_TIME,
                                                                   &record_hdr[0], &rectime))
                                        /*
@@ -1130,19 +1131,21 @@ void read_stats_from_file(char from_file[])
                        do {
                                /* Read next record header */
                                eosaf = read_record_hdr(ifd, rec_hdr_tmp, &record_hdr[curr],
-                                                       &file_hdr, arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags);
+                                                       &file_hdr, arch_64, endian_mismatch, UEOF_STOP, sizeof(rec_hdr_tmp), flags, &sar_fmt);
                                rtype = record_hdr[curr].record_type;
 
                                if (eosaf || (rtype == R_RESTART))
                                        break;
 
                                if (rtype != R_COMMENT) {
-                                       read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr,
-                                                            file_actlst, endian_mismatch, arch_64,
-                                                            from_file, &file_magic, UEOF_STOP);
+                                       if (read_file_stat_bunch(act, curr, ifd, file_hdr.sa_act_nr,
+                                                                file_actlst, endian_mismatch, arch_64,
+                                                                from_file, &file_magic, UEOF_STOP))
+                                               /* Possible unexpected EOF */
+                                               break;
                                }
                                else {
-                                       /* This was a COMMENT record: print it */
+                                       /* This was a COMMENT record: Print it */
                                        print_special_record(&record_hdr[curr], flags + S_F_LOCAL_TIME,
                                                             &tm_start, &tm_end, R_COMMENT, ifd,
                                                             &rectime, from_file, 0,