]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsmem: make --split optional, follow output by default
authorKarel Zak <kzak@redhat.com>
Fri, 3 Nov 2017 09:58:33 +0000 (10:58 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Nov 2017 09:58:33 +0000 (10:58 +0100)
Let's keep lsmem backwardly compatible (<=v2.30) and create ranges
according to the output columns by default. This default behavior may
be modified by --split command line option.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lsmem.1
sys-utils/lsmem.c

index af65c2abb52e9e231f6e69e4b7b720004f094124..8f72bbc1ebda213c672d6c2a45c350229ee110b1 100644 (file)
@@ -16,14 +16,12 @@ Always explicitly define expected columns by using the \fB\-\-output\fR option
 together with a columns list in environments where a stable output is required.
 
 The \fBlsmem\fP command lists a new memory range always when the current memory
-block distinguish from the previous block by STATE, REMOVABLE, NODE or ZONES
-attribute.  This default behavior is possible to override by the
-\fB\-\-split\fR option (e.g. \fBlsmem \-\-split=STATE,ZONES\fR).  The special
-word "none" may be used to ignore all differences between memory blocks and to
-create as large as possible continuous ranges.  The opposite semantic is
-\fB\-\-all\fR to list individual memory blocks.  The default split policy is
-subject to change.  Always explicitly use \fB\-\-split\fR in environments where
-a stable output is required.
+block distinguish from the previous block by some output column.  This default
+behavior is possible to override by the \fB\-\-split\fR option (e.g. \fBlsmem
+\-\-split=ZONES\fR).  The special word "none" may be used to ignore all
+differences between memory blocks and to create as large as possible continuous
+ranges.  The opposite semantic is \fB\-\-all\fR to list individual memory
+blocks.
 
 Note that some output columns may provide inaccurate information if a split policy
 forces \fBlsmem\fP to ignore diffrences in some attributes. For example if you
index 97376de38728c71748b32bc931160b0bc4542abc..19a727465605fb10177e5f2466315ebea2f09abe 100644 (file)
@@ -203,6 +203,32 @@ static inline void reset_split_policy(struct lsmem *l, int enable)
        l->split_by_zones = enable;
 }
 
+static void set_split_policy(struct lsmem *l, int cols[], size_t ncols)
+{
+       size_t i;
+
+       reset_split_policy(l, 0);
+
+       for (i = 0; i < ncols; i++) {
+               switch (cols[i]) {
+               case COL_STATE:
+                       l->split_by_state = 1;
+                       break;
+               case COL_NODE:
+                       l->split_by_node = 1;
+                       break;
+               case COL_REMOVABLE:
+                       l->split_by_removable = 1;
+                       break;
+               case COL_ZONES:
+                       l->split_by_zones = 1;
+                       break;
+               default:
+                       break;
+               }
+       }
+}
+
 static void add_scols_line(struct lsmem *lsmem, struct memory_block *blk)
 {
        size_t i;
@@ -649,32 +675,17 @@ int main(int argc, char **argv)
                int split[ARRAY_SIZE(coldescs)] = { 0 };
                static size_t nsplits = 0;
 
-               reset_split_policy(lsmem, 0);   /* disable all */
-
                if (strcasecmp(splitarg, "none") == 0)
                        ;
                else if (string_add_to_idarray(splitarg, split, ARRAY_SIZE(split),
                                        &nsplits, column_name_to_id) < 0)
                        return EXIT_FAILURE;
 
-               for (i = 0; i < nsplits; i++) {
-                       switch (split[i]) {
-                       case COL_STATE:
-                               lsmem->split_by_state = 1;
-                               break;
-                       case COL_NODE:
-                               lsmem->split_by_node = 1;
-                               break;
-                       case COL_REMOVABLE:
-                               lsmem->split_by_removable = 1;
-                               break;
-                       case COL_ZONES:
-                               lsmem->split_by_zones = 1;
-                               break;
-                       }
-               }
+               set_split_policy(lsmem, split, nsplits);
+
        } else
-               reset_split_policy(lsmem, 1); /* enable all */
+               /* follow output columns */
+               set_split_policy(lsmem, columns, ncolumns);
 
        /*
         * Read data and print output