]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: cleanup --summary semantic
authorKarel Zak <kzak@redhat.com>
Wed, 24 Nov 2021 14:00:45 +0000 (15:00 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 24 Nov 2021 14:00:45 +0000 (15:00 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsfd.1.adoc
misc-utils/lsfd.c

index 1a6149a9853a5f5daa9d96b848970531d27235da..a67fa4ab046f85b889f46661c2b8304a8ab1bd1f 100644 (file)
@@ -69,7 +69,7 @@ Print the files only satisfying with the condition represented by the _expr_.
 See also "FILTER EXAMPLES".
 
 *-C*, *--counter* _label_:_filter_expr_::
-Define a counter used in *--summary* output. *lsfd* makes a
+Define a custom counter used in *--summary* output. *lsfd* makes a
 counter named _label_. During collect information, *lsfd* counts files
 satisfying _filter_expr_, and stores the counted number to the
 counter named _label_. *lsfd* applies filters defined with *--filter*
@@ -83,7 +83,7 @@ See also "COUNTER EXAMPLES".
 
 *--summary*[=_when_]::
 This option controls summary lines output. The optional argument _when_
-can be *never*, *always* or *only*. If the _when_ argument is omitted,
+can be *only*, *append* or *never*. If the _when_ argument is omitted,
 it defaults to *"only"*.
 +
 The summary reports counters. A counter comes from a label and an
index bd18749ccd7629b82ab753bca6a3b162e0622658..1e05958a62527a43b24d4fd2234c390b86ff30ec 100644 (file)
@@ -263,11 +263,6 @@ static struct counter_spec default_counter_specs[] = {
        }
 };
 
-enum {
-       SUMMARY_EMIT = 1 << 0,
-       SUMMARY_ONLY = 1 << 1,
-};
-
 struct lsfd_control {
        struct libscols_table *tb;              /* output */
        struct list_head procs;                 /* list of all processes */
@@ -277,7 +272,8 @@ struct lsfd_control {
                        json : 1,
                        notrunc : 1,
                        threads : 1,
-                       summary: 2;
+                       show_main : 1,          /* print main table */
+                       show_summary : 1;       /* print summary/counters */
 
        struct lsfd_filter *filter;
        struct lsfd_counter **counters;         /* NULL terminated array. */
@@ -1144,9 +1140,9 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -Q, --filter <expr>   apply display filter\n"), out);
        fputs(_("     --debug-filter    dump the innternal data structure of filter and exit\n"), out);
        fputs(_(" -C, --counter <name>:<expr>\n"
-               "                       make a counter used in --summary output\n"), out);
+               "                       define custom counter for --summary output\n"), out);
        fputs(_("     --dump-counters   dump counter definitions\n"), out);
-       fputs(_("     --summary[=when]  print summary information (never,always or only)\n"), out);
+       fputs(_("     --summary[=when]  print summary information (only, append, or never)\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
        printf(USAGE_HELP_OPTIONS(23));
@@ -1393,7 +1389,6 @@ int main(int argc, char *argv[])
        int c;
        size_t i;
        char *outarg = NULL;
-       struct lsfd_control ctl = {};
        char  *filter_expr = NULL;
        bool debug_filter = false;
        bool dump_counters = false;
@@ -1401,6 +1396,10 @@ int main(int argc, char *argv[])
        int n_pids = 0;
        struct list_head counter_specs;
 
+       struct lsfd_control ctl = {
+               .show_main = 1
+       };
+
        INIT_LIST_HEAD(&counter_specs);
 
        enum {
@@ -1468,15 +1467,15 @@ int main(int argc, char *argv[])
                case OPT_SUMMARY:
                        if (optarg) {
                                if (strcmp(optarg, "never") == 0)
-                                       ctl.summary = 0;
+                                       ctl.show_summary = 0, ctl.show_main = 1;
                                else if (strcmp(optarg, "only") == 0)
-                                       ctl.summary |= (SUMMARY_ONLY|SUMMARY_EMIT);
-                               else if (strcmp(optarg, "always") == 0)
-                                       ctl.summary |= SUMMARY_EMIT;
+                                       ctl.show_summary = 1, ctl.show_main = 0;
+                               else if (strcmp(optarg, "append") == 0)
+                                       ctl.show_summary = 1, ctl.show_main = 1;
                                else
                                        errx(EXIT_FAILURE, _("unsupported --summary argument"));
                        } else
-                               ctl.summary |= SUMMARY_EMIT;
+                               ctl.show_summary = 1, ctl.show_main = 0;
                        break;
                case OPT_DUMP_COUNTERS:
                        dump_counters = true;
@@ -1549,7 +1548,7 @@ int main(int argc, char *argv[])
        }
 
        /* make counters */
-       if (ctl.summary & SUMMARY_EMIT) {
+       if (ctl.show_summary) {
                if (list_empty(&counter_specs))
                        ctl.counters = new_default_counters(&ctl);
                else {
@@ -1570,9 +1569,12 @@ int main(int argc, char *argv[])
        free(pids);
 
        convert(&ctl.procs, &ctl);
-       if (!(ctl.summary & SUMMARY_ONLY))
+
+       /* print */
+       if (ctl.show_main)
                emit(&ctl);
-       if (ctl.counters && (ctl.summary & SUMMARY_EMIT))
+
+       if (ctl.show_summary && ctl.counters)
                emit_summary(&ctl, ctl.counters);
 
        /* cleanup */