]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/lscpu.c
Merge branch 'patch-23' of https://github.com/mariobl/util-linux
[thirdparty/util-linux.git] / sys-utils / lscpu.c
index 8333dcbea628bfd67ceb69b6e19184c67450e6e6..a65ccad5e435b93686c478aa197adb7dc71fa28c 100644 (file)
@@ -1,24 +1,16 @@
 /*
- * lscpu - CPU architecture information helper
- *
- * Copyright (C) 2008 Cai Qian <qcai@redhat.com>
- * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
+ * SPDX-License-Identifier: GPL-2.0-or-later
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Copyright (C) 2008 Cai Qian <qcai@redhat.com>
+ * Copyright (C) 2008-2023 Karel Zak <kzak@redhat.com>
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * lscpu - CPU architecture information helper
  */
-
 #include <assert.h>
 #include <ctype.h>
 #include <dirent.h>
@@ -855,13 +847,15 @@ print_cpuset(struct lscpu_cxt *cxt,
             const char *key, cpu_set_t *set)
 {
        size_t setbuflen = 7 * cxt->maxcpus;
-       char setbuf[setbuflen], *p;
+       char *setbuf, *p;
 
        assert(set);
        assert(key);
        assert(tb);
        assert(cxt);
 
+       setbuf = xmalloc(setbuflen);
+
        if (cxt->hex) {
                p = cpumask_create(setbuf, setbuflen, set, cxt->setsize);
                add_summary_s(tb, sec, key, p);
@@ -869,6 +863,8 @@ print_cpuset(struct lscpu_cxt *cxt,
                p = cpulist_create(setbuf, setbuflen, set, cxt->setsize);
                add_summary_s(tb, sec, key, p);
        }
+
+       free(setbuf);
 }
 
 static void
@@ -1194,7 +1190,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("     --hierarchic[=when] use subsections in summary (auto, never, always)\n"), out);
        fputs(_("     --output-all        print all available columns for -e, -p or -C\n"), out);
        fputs(USAGE_SEPARATOR, out);
-       printf(USAGE_HELP_OPTIONS(25));
+       fprintf(out, USAGE_HELP_OPTIONS(25));
 
        fputs(_("\nAvailable output columns for -e or -p:\n"), out);
        for (i = 0; i < ARRAY_SIZE(coldescs_cpu); i++)
@@ -1204,7 +1200,7 @@ static void __attribute__((__noreturn__)) usage(void)
        for (i = 0; i < ARRAY_SIZE(coldescs_cache); i++)
                fprintf(out, " %13s  %s\n", coldescs_cache[i].name, _(coldescs_cache[i].help));
 
-       printf(USAGE_MAN_TAIL("lscpu(1)"));
+       fprintf(out, USAGE_MAN_TAIL("lscpu(1)"));
 
        exit(EXIT_SUCCESS);
 }
@@ -1455,10 +1451,13 @@ int main(int argc, char *argv[])
                        columns[ncolumns++] = COL_CPU_NODE;
                        columns[ncolumns++] = COL_CPU_CACHE;
                }
-               if (outarg && string_add_to_idarray(outarg, columns,
+               if (outarg) {
+                       if (string_add_to_idarray(outarg, columns,
                                        ARRAY_SIZE(columns),
                                        &ncolumns, cpu_column_name_to_id) < 0)
-                       return EXIT_FAILURE;
+                               return EXIT_FAILURE;
+                       cxt->show_compatible = 0;
+               }
 
                print_cpus_parsable(cxt, columns, ncolumns);
                break;