]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: fix last caches separator in -e and -p output
authorKarel Zak <kzak@redhat.com>
Mon, 2 Nov 2020 09:34:53 +0000 (10:34 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 08:19:02 +0000 (09:19 +0100)
Note that cxt->ncaches is number of all instances, but we split
output according to split output according to caches names.

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

index 654c3b51401c17fa95d71264abe3dad839a8d896..50412b859dbdcfc3bfbf9993867d3a7608706dd4 100644 (file)
@@ -362,14 +362,14 @@ static char *get_cell_data(
                                return NULL;
                        p += x;
                        sz -= x;
-                       if (i + 1 < cxt->ncaches) {
-                               if (sz < 2)
-                                       return NULL;
-                               *p++ = cxt->show_compatible ? ',' : ':';
-                               *p = '\0';
-                               sz--;
-                       }
+                       if (sz < 2)
+                               return NULL;
+                       *p++ = cxt->show_compatible ? ',' : ':';
+                       *p = '\0';
+                       sz--;
                }
+               if (p > buf && (*(p - 1) == ',' || *(p - 1) == ':'))
+                       *(p - 1) = '\0';
                break;
        }
        case COL_CPU_POLARIZATION:
@@ -442,14 +442,14 @@ static char *get_cell_header(
                                return NULL;
                        sz -= x;
                        p += x;
-                       if (i + 1 < cxt->ncaches) {
-                               if (sz < 2)
-                                       return NULL;
-                               *p++ = cxt->show_compatible ? ',' : ':';
-                               *p = '\0';
-                               sz--;
-                       }
+                       if (sz < 2)
+                               return NULL;
+                       *p++ = cxt->show_compatible ? ',' : ':';
+                       *p = '\0';
+                       sz--;
                }
+               if (p > buf && (*(p - 1) == ',' || *(p - 1) == ':'))
+                       *(p - 1) = '\0';
                if (cxt->ncaches)
                        return buf;
        }
index 935734ce7ff972bdb049ef21f02e84eb5c40a24a..d76e1379026ac18ce197e557f09372da2663d4a6 100644 (file)
@@ -50,7 +50,6 @@ struct lscpu_cache {
        unsigned int    number_of_sets;
        unsigned int    coherency_line_size;
 
-       size_t          nsharedmaps;
        cpu_set_t       *sharedmap;
 };