Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/vm/slabinfo: indicates the cause of the EACCES error

If you don't run slabinfo with a superuser, return 0 when read_slab_dir()
reads get_obj_and_str("slabs", &t), because fopen() fails (sometimes
EACCES), causing slabcache() to return directly, without any error during
this time, we should tell the user about the EACCES problem instead of
running successfully($?=0) without any error printing.

For example:
$ ./slabinfo
Permission denied, Try using superuser <== What this submission did
$ sudo ./slabinfo
Name Objects Objsize Space Slabs/Part/Cpu O/S O %Fr %Ef Flg
Acpi-Namespace 5950 48 286.7K 65/0/5 85 0 0 99
Acpi-Operand 13664 72 999.4K 231/0/13 56 0 0 98
...

Signed-off-by: Rong Tao <rongtao@cestc.cn>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

authored by

Rong Tao and committed by
Vlastimil Babka
654058e6 247f34f7

+4 -2
+4 -2
tools/vm/slabinfo.c
··· 157 157 { 158 158 FILE *f = fopen(name, "r"); 159 159 160 - if (!f) 160 + if (!f) { 161 161 buffer[0] = 0; 162 - else { 162 + if (errno == EACCES) 163 + fatal("%s, Try using superuser\n", strerror(errno)); 164 + } else { 163 165 if (!fgets(buffer, sizeof(buffer), f)) 164 166 buffer[0] = 0; 165 167 fclose(f);