mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tools/vm/slabinfo: indicates the cause of the EACCES error
@ 2022-11-08 12:47 Rong Tao
  2022-11-10  9:40 ` Vlastimil Babka
  0 siblings, 1 reply; 2+ messages in thread
From: Rong Tao @ 2022-11-08 12:47 UTC (permalink / raw)
  To: akpm
  Cc: Rong Tao, Vlastimil Babka, Stéphane Graber, Yuanzheng Song,
	linux-kernel

From: Rong Tao <rongtao@cestc.cn>

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>
---
 tools/vm/slabinfo.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c
index 0fffaeedee76..cfaeaea71042 100644
--- a/tools/vm/slabinfo.c
+++ b/tools/vm/slabinfo.c
@@ -157,9 +157,11 @@ static unsigned long read_obj(const char *name)
 {
 	FILE *f = fopen(name, "r");
 
-	if (!f)
+	if (!f) {
 		buffer[0] = 0;
-	else {
+		if (errno == EACCES)
+			fatal("%s, Try using superuser\n", strerror(errno));
+	} else {
 		if (!fgets(buffer, sizeof(buffer), f))
 			buffer[0] = 0;
 		fclose(f);
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/vm/slabinfo: indicates the cause of the EACCES error
  2022-11-08 12:47 [PATCH] tools/vm/slabinfo: indicates the cause of the EACCES error Rong Tao
@ 2022-11-10  9:40 ` Vlastimil Babka
  0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka @ 2022-11-10  9:40 UTC (permalink / raw)
  To: Rong Tao, akpm
  Cc: Rong Tao, Stéphane Graber, Yuanzheng Song, linux-kernel,
	Christoph Lameter, David Rientjes, linux-mm, Joonsoo Kim,
	Pekka Enberg, Hyeonggon Yoo, Roman Gushchin

On 11/8/22 13:47, Rong Tao wrote:
> From: Rong Tao <rongtao@cestc.cn>
> 
> 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>

Thanks, added to slab.git slab/for-6.2/tools

> ---
>  tools/vm/slabinfo.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c
> index 0fffaeedee76..cfaeaea71042 100644
> --- a/tools/vm/slabinfo.c
> +++ b/tools/vm/slabinfo.c
> @@ -157,9 +157,11 @@ static unsigned long read_obj(const char *name)
>  {
>  	FILE *f = fopen(name, "r");
>  
> -	if (!f)
> +	if (!f) {
>  		buffer[0] = 0;
> -	else {
> +		if (errno == EACCES)
> +			fatal("%s, Try using superuser\n", strerror(errno));
> +	} else {
>  		if (!fgets(buffer, sizeof(buffer), f))
>  			buffer[0] = 0;
>  		fclose(f);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-10  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 12:47 [PATCH] tools/vm/slabinfo: indicates the cause of the EACCES error Rong Tao
2022-11-10  9:40 ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®