From: Ruediger Meier Date: Wed, 26 Mar 2014 21:18:17 +0000 (+0100) Subject: lscpu: don't abort if cache size is unknown X-Git-Tag: v2.25-rc1~400^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=10d927ab3ba442084283db670364045bca61dbb8;p=thirdparty%2Futil-linux.git lscpu: don't abort if cache size is unknown 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 --- diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 4760d4e390..3e0e1cf044 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -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 */