]> 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 97be5db30249991f438e12ae54efdbc74d82f7d6..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 *
@@ -486,9 +486,6 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
                cross_day = TRUE;
        }
 
-       /* Get interval value in 1/100th of a second */
-       get_itv_value(&record_hdr[curr], &record_hdr[!curr], &itv);
-
        /* Check time (2) */
        if (use_tm_end && (datecmp(&rectime, &tm_end, cross_day) > 0)) {
                /* End time exceeded */
@@ -496,6 +493,9 @@ int write_stats(int curr, int read_from_file, long *cnt, int use_tm_start,
                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 */
@@ -800,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 */
@@ -1045,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))
                                        /*
@@ -1133,9 +1138,11 @@ void read_stats_from_file(char from_file[])
                                        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 */