From: Vlastimil Babka <vbabka@suse.cz>
To: Rong Tao <rtoax@foxmail.com>, akpm@linux-foundation.org
Cc: "Rong Tao" <rongtao@cestc.cn>,
"Stéphane Graber" <stgraber@ubuntu.com>,
"Yuanzheng Song" <songyuanzheng@huawei.com>,
linux-kernel@vger.kernel.org, "Christoph Lameter" <cl@linux.com>,
"David Rientjes" <rientjes@google.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"Joonsoo Kim" <iamjoonsoo.kim@lge.com>,
"Pekka Enberg" <penberg@kernel.org>,
"Hyeonggon Yoo" <42.hyeyoo@gmail.com>,
"Roman Gushchin" <roman.gushchin@linux.dev>
Subject: Re: [PATCH] tools/vm/slabinfo: indicates the cause of the EACCES error
Date: Thu, 10 Nov 2022 10:40:52 +0100 [thread overview]
Message-ID: <e3fc40c9-6e4e-d8de-63ce-ce34d78fa883@suse.cz> (raw)
In-Reply-To: <tencent_C9D7A6D118445E036021CE2CB4CB4495E207@qq.com>
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);
parent reply other threads:[~2022-11-10 9:40 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <tencent_C9D7A6D118445E036021CE2CB4CB4495E207@qq.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3fc40c9-6e4e-d8de-63ce-ce34d78fa883@suse.cz \
--to=vbabka@suse.cz \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=rongtao@cestc.cn \
--cc=rtoax@foxmail.com \
--cc=songyuanzheng@huawei.com \
--cc=stgraber@ubuntu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox