]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: don't abort if cache size is unknown
authorRuediger Meier <ruediger.meier@ga-group.nl>
Wed, 26 Mar 2014 21:18:17 +0000 (22:18 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 23 Apr 2014 09:55:08 +0000 (11:55 +0200)
There are systems where the size file does not exist. Most badly even
lscpu -p would abort allthough it does not use the size:
$ lscpu -p
lscpu: error: cannot open
/sys/devices/system/cpu/cpu0/cache/index0/size: No such file or directory

This patch does not abort in this case and prints "unknown size" in
human-readable case. For examle on this qemu pcc test machine:
$ lscpu
Architecture:          ppc
CPU op-mode(s):        32-bit
Byte Order:            Big Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
Model:                 Power Macintosh
BogoMIPS:              33.25
L1d cache:             unknown size
L1i cache:             unknown size

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
sys-utils/lscpu.c

index 4760d4e3903daaaacd33e5ee3ed18d4f997efb06..3e0e1cf044986ea1cf030a4889ce4051d2dab566 100644 (file)
@@ -897,10 +897,13 @@ read_cache(struct lscpu_desc *desc, int idx)
                        ca->name = xstrdup(buf);
 
                        /* cache size */
-                       path_read_str(buf, sizeof(buf),
-                                       _PATH_SYS_CPU "/cpu%d/cache/index%d/size",
-                                       num, i);
-                       ca->size = xstrdup(buf);
+                       if (path_exist(_PATH_SYS_CPU "/cpu%d/cache/index%d/size",num, i)) {
+                               path_read_str(buf, sizeof(buf),
+                                       _PATH_SYS_CPU "/cpu%d/cache/index%d/size", num, i);
+                               ca->size = xstrdup(buf);
+                       } else {
+                               ca->size = xstrdup("unknown size");
+                       }
                }
 
                /* information about how CPUs share different caches */