]> granicus.if.org Git - sysstat/commitdiff
sadc.c: Stop if no activities are collected
authorSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 27 Dec 2017 13:18:05 +0000 (14:18 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Wed, 27 Dec 2017 13:18:05 +0000 (14:18 +0100)
Don't collect CPU stats by default if no other activities are collected:
sadc now stops in this case.

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

diff --git a/sa.h b/sa.h
index 8677e20eee222b39edee8d7aa2b6bb85991ad657..b9eb4119263258bb832bea6df2400e0d52690787 100644 (file)
--- a/sa.h
+++ b/sa.h
@@ -1257,6 +1257,8 @@ int parse_sar_n_opt
        (char * [], int *, struct activity * []);
 int parse_timestamp
        (char * [], int *, struct tstamp *, const char *);
+void print_collect_error
+       (void);
 void print_report_hdr
        (unsigned int, struct tm *, struct file_header *);
 void print_sar_comment
index 18f57afa3f2ec2726bb7f6f1f8a103c89147cf06..4ae504a81286f0a2cc07c73463c9299233376511 100644 (file)
@@ -1289,6 +1289,17 @@ void handle_invalid_sa_file(int *fd, struct file_magic *file_magic, char *file,
        exit(3);
 }
 
+/*
+ ***************************************************************************
+ * Display an error message then exit.
+ ***************************************************************************
+ */
+void print_collect_error(void)
+{
+       fprintf(stderr, _("Requested activities not available\n"));
+       exit(1);
+}
+
 /*
  ***************************************************************************
  * Move structures data.
diff --git a/sadc.c b/sadc.c
index 0e59a26fdb8c92f171451b46bc23fd2d56506a5f..5a32e7266c8b24316b64d1bafa2c32ad340348d9 100644 (file)
--- a/sadc.c
+++ b/sadc.c
@@ -1239,11 +1239,6 @@ int main(int argc, char **argv)
                }
        }
 
-       /* At least one activity must be collected (default is A_CPU) */
-       if (!get_activity_nr(act, AO_COLLECTED, COUNT_ACTIVITIES)) {
-               COLLECT_ACTIVITY(A_CPU);
-       }
-
        /* Process file entered on the command line */
        if (WANT_SA_ROTAT(flags)) {
                /* File name set to '-' */
@@ -1288,6 +1283,12 @@ int main(int argc, char **argv)
        /* Init structures according to machine architecture */
        sa_sys_init();
 
+       /* At least one activity must be collected */
+       if (!get_activity_nr(act, AO_COLLECTED, COUNT_ACTIVITIES)) {
+               /* Requested activities not available: Exit */
+               print_collect_error();
+       }
+
        if (!interval && !comment[0]) {
                /*
                 * Interval (and count) not set, and no comment given
diff --git a/sar.c b/sar.c
index f161b4484c811ad00e180f64c245b7b8fc74b193..2d6e4eda3d877bdb2e528d04969ecb84494bf521 100644 (file)
--- a/sar.c
+++ b/sar.c
@@ -1101,8 +1101,8 @@ void read_stats(void)
        read_header_data();
 
        if (!get_activity_nr(act, AO_SELECTED, COUNT_ACTIVITIES)) {
-               fprintf(stderr, _("Requested activities not available\n"));
-               exit(1);
+               /* Requested activities not available: Exit */
+               print_collect_error();
        }
 
        /* Determine if a stat line header has to be displayed */