Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3467302rwb; Tue, 8 Nov 2022 05:03:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM7X68Q94MVPH6f+sW4YvjD8wMIvhFPAX3bnW3YYQpce/f8FrI5jtez6lSjX7oXtoC9LJvZl X-Received: by 2002:a05:6a00:4c16:b0:56d:2634:c28e with SMTP id ea22-20020a056a004c1600b0056d2634c28emr53071456pfb.8.1667912618973; Tue, 08 Nov 2022 05:03:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667912618; cv=none; d=google.com; s=arc-20160816; b=qSIw6OHAJK61BPTU10/sirmlKmHmC6i9p7+DqsyiZ/3PERALqgwyM6r6rhrPQZ9XQp vbqRomyndabmUodtA4Bw2GqyX4F3FvftdI4+hsfBoi6WOlrWuFU1+CvhvKr8Q3KVWpdk gQergQ+XMVYCy7UrrN6Ygbpz/U0Mo1fe6uelmtTgEEDSj+CO6ZWbpzGCWjs4167jutMk c7prO2DEON3g5qk31nRR2aY3JI/OO4NZhATY2DravUjHmqZpBrt8JsGrl2bYaxk/ZZd/ +luE3q6Apl9PoTWbrzPKBA7QpODRaA3XuwKVuKQTua9CvBPYY9JBVTmxseBlYbDeBzBB 1Ubw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:cc:to:from:message-id:dkim-signature; bh=oVLc4gaktdNCNVvwWLVkFb2ZvH20wWVNUBsMSq/8jp0=; b=X2rYMhfdDnCrro0rSQZGGxQ5j6zvpa39GuT8xUwaR5ryTrZz9+BR9TSawMH0d/JECr oACymhBf0OJP8u4M4/nyvBQTQLVwMQbJ8VMsczz7YV4A5pdwc7l5uawtflmRAN1+W3m4 EaI+JsFeSYfDwWr/jPG8N6Sxo6uaonxtBpZVi0wt/zVXKHP19ghYa/QW8SjTvY37DICN n33mDDzsz7y9+D2xELj1mZGZZExYqGrRg+4pFqxf1TJq0O5FJBOb9c2GVr72+O9KjhOZ LqlSz8fd2BrN5ubMiS5IF5h0EwIVy3Xyw3QrrzFFFsM4GhZXfGyzOa+0V9BswNr1ZbVD SnLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=p2uJJhg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a170903228600b00178431e09bdsi15523439plh.230.2022.11.08.05.03.27; Tue, 08 Nov 2022 05:03:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=p2uJJhg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233869AbiKHMsv (ORCPT + 89 others); Tue, 8 Nov 2022 07:48:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234279AbiKHMsT (ORCPT ); Tue, 8 Nov 2022 07:48:19 -0500 Received: from out162-62-57-137.mail.qq.com (out162-62-57-137.mail.qq.com [162.62.57.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96FE853EDF for ; Tue, 8 Nov 2022 04:48:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1667911694; bh=oVLc4gaktdNCNVvwWLVkFb2ZvH20wWVNUBsMSq/8jp0=; h=From:To:Cc:Subject:Date; b=p2uJJhg41B0S76vGxe88P+iivQGF2oFPGqLrQ/VYbtEtAfGUBZW7kmdUc/2EXdDL+ TLPJATz2rir4rgxUvjIxRQZCILYV+gpPEqj91lOi+aFOeyHeQYVEksJjtYk/s+1lKn WTPnqnA6fbs9C4geNYTXfpIAduy7535qG/dWdFt0= Received: from localhost.localdomain ([111.199.191.46]) by newxmesmtplogicsvrszb1-0.qq.com (NewEsmtp) with SMTP id C0BAF88A; Tue, 08 Nov 2022 20:48:11 +0800 X-QQ-mid: xmsmtpt1667911691tuo6mpdjb Message-ID: X-QQ-XMAILINFO: M7uElAZZZMmFNpXVH2eRjE7JTPiOgzhK0+tfEcnsEo7BhLIgc0wKXQ+SgIjF+H 1Vrbuk1XzFMRi43EVGYY80TZNohlUE2f4iGSDtuqtIJB8nZhl3tAkvPIuHchUMf9B071iiWZ03Cc O+Vm4fAB8Or5mnlKb5qbBjGgPYpIkAh3YFK5R63CwPvH5jj4r9y+VUCr9de71vQtbyfe4t8fUPKq qJL+H+kykgycJD1GAioNzY8bQzb3ue8bUrZvTVJb8RZiv2CJhvhp+kfBkZCPzPn5w8l1D9b5KxHK ekOmRxE+VJybiNfUiqyAcawp6I991iNvq/PcH+lzQtUVVO98cnF+xj0huVTrXqcCUYbx6Ji/rnsj iKaZrEcVy1sXF/PmYug8esjM6T5ln0DgtEIHI7p7YNw8DTF3bVrJcs3BZEkbbZa89UvG5jLE7Au6 I6GrpXEvqFcu2zLuNoUmkxSibxZ1kfv4ZE2gZcIJUB3CicWuuPoX3o9xRqCmICIH16ZlYoaHABBx bXUDoCEUM4/5L1XSGtBCx9wa6Jgx8eIS8IIrBVLp6iqvVZiuqiVY9jOl0OKxjljH7AuoqmvWt3zy 76e0qaf+2r6Y+5F8ayoMJlPogapPNp9ZF4pv/Kd73XLDxbN13bBgwqhypCdAYCo5Ghv7NgGlpzCC lfUOHYIJ1VNPmjz7RrgMHwt55ipd091kXRWDwCcrwGU3XxBWoGaZ5+8Gf8iac8A6R/4LfWTG0R2r WrxLg9j5nmwQM4O1Cn21I5BV3VM9hIu+SehQwsvrQCdOCAPOTBSoKM40CnChyix+Moas0lQA34d9 M++X2c4jwaP61h65/dKXkr2JOKMrNfuakcMOE68TSM+i42v6QzYNvqbKylYRgK39OIKZOT3kQT/A Ogiro9QKJ1qSldmoVVgYOpgOKVZmn5QdhrQTZFb9eUzZiRiRPKnzlgs37LF1gjJo3ihc/kxm4Aab b2tEOgh/F4mYmQP5j4Hn+x3z1d7EUNK/sWIjZFLvoS2984VrVOmHWKyrwLbhnFe9QL3KcekSNqVH F0kpSWdA== From: Rong Tao To: akpm@linux-foundation.org Cc: Rong Tao , Vlastimil Babka , =?UTF-8?q?St=C3=A9phane=20Graber?= , Yuanzheng Song , linux-kernel@vger.kernel.org Subject: [PATCH] tools/vm/slabinfo: indicates the cause of the EACCES error Date: Tue, 8 Nov 2022 20:47:57 +0800 X-OQ-MSGID: <20221108124758.33198-1-rtoax@foxmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,RDNS_DYNAMIC, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rong Tao 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 --- 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