From patchwork Sun Sep 25 16:18:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyi Liu X-Patchwork-Id: 12988031 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9240CC04A95 for ; Sun, 25 Sep 2022 16:19:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232779AbiIYQTd (ORCPT ); Sun, 25 Sep 2022 12:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbiIYQTb (ORCPT ); Sun, 25 Sep 2022 12:19:31 -0400 Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2155.outbound.protection.outlook.com [40.92.62.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF5202CDE1 for ; Sun, 25 Sep 2022 09:19:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eq75c/AyEA136CQiTm7Wc0sYuJ6EkP8WBc7Y7kJh8uui06zartjlPqV3QPPQztiytR4g0e7gzcV2JVZxl4mOif7O/g2RvW4uhzrbwc76IiXk+zs0Ge0+0xvpVmrI6+fDqdIqkRjys3E5kcgXZjsYc7ZJB5at/oyw5A1mqy++kodHjjzU0rDdp6qWQeTx0W++49NH6RckX8zPFzCCk6F2+2VWHlL4KLY9sTsRz/AF4DoLWAh35z4jf7fXYwqFYqRuSgB1oo7z/Nqg5/yzuxsYlEVoJ9YIsoAfFYVRqSTqFUN4YQgpwemxGd7bBDrJPZQe+lmSWJ6Rj+nAuPHsr7DPeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kxltH0MFHN0yv1rtGpfijsCqddouXP8UoSbs5Ejq35o=; b=J5GfZvR/YBCFhUyRKiuWIKZd4ojpyDb1Fq8de4/3Rmix5sq2jlsEdb4ffNFO7tYRSHnNgJFEzpnYK9WcklQFKlZe0HHUgg3BpW6miQ6kgYwkgOVat81ZWIdWED5O6IagBoMFSqvgvkO1WjXt1wjuokMIICJA/wAH8nPwjGdf+LaPYFFOXkrIDWv1WQsImhFfH0mqMPB3KhsEo4+okFpeXt9XOHb4ZNw+E/0Mg3DVsL2VQMP/88JEaCstNTrav8RhgMNEkL6M/FvBFhjt2sxnMGsuqb98o20v+nV+aJCvzW5GJ2RMjBVdjb1iXq6oY4LvskUWeS2r6JwbYa7YUFVrNA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kxltH0MFHN0yv1rtGpfijsCqddouXP8UoSbs5Ejq35o=; b=grhoNPbyJlxM+uEm2g1XnRHiMH3V7jVtdbVV14QAHi+TiRTOufxM0cbQNAARnlvURM5VeVhkregOYK8uA0UxHKHwEP2nGnLuPgNysNXWDWb0znd/+g6+b4v85TbNg7ssRVBUBG1xHrELJmnVlNxD+p++LvG/ZkMh2StZRph4qe9hd55eVogpG4v0/A2oUmqASlm7xnZtQkwyJ3S4IBxbyyZtDMuWmD38R+FobVSU8DXXy4B0XYJw20PnvP0bp7Pu55qCqR5G7fQkeNhbCtx0mCkqZ/855oo+gRiuG+g4Avw5A854mF+Fulk0DoWSQMNcLtv0izhy4/JZaFwinBN0jg== Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) by SYBP282MB2462.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:11a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.15; Sun, 25 Sep 2022 16:19:25 +0000 Received: from SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::549a:65d7:eae8:3983]) by SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM ([fe80::549a:65d7:eae8:3983%7]) with mapi id 15.20.5654.024; Sun, 25 Sep 2022 16:19:25 +0000 From: Tianyi Liu To: quentin@isovalent.com Cc: bpf@vger.kernel.org, Tianyi Liu Subject: [PATCH] bpftool: Fix error prompt of strerror Date: Mon, 26 Sep 2022 00:18:32 +0800 Message-ID: X-Mailer: git-send-email 2.37.3 X-TMN: [cAYRFQl6/BhKkP4L3/e+mocWHw6iFLIa0UceDIUmLuSzOUcgWnh0jQ==] X-ClientProxiedBy: SI2PR04CA0015.apcprd04.prod.outlook.com (2603:1096:4:197::21) To SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:ac::13) X-Microsoft-Original-Message-ID: <20220925161832.1516141-1-i.pear@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SY4P282MB1084:EE_|SYBP282MB2462:EE_ X-MS-Office365-Filtering-Correlation-Id: 16441a9f-e0a5-4535-3732-08da9f11b65a X-MS-Exchange-SLBlob-MailProps: C/ir7cSdGlsxpxllHOv5HbamrC1c36SANxPm11wguevW9SP54lG6MYWpJ9xk5LyRBHWHqFIDN6H2tl909m5T8LNEMI+0WpCpaTEtjVX5Ffnctk2CwQsdIaTAToMrBYJZA6TnSOEZ48GShCbiLHry1/34Td2ebsnyBAAPZQuE2EWjFHQsCp9hnn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QzPuJA3PjZcvX+XM8pD910bE0gpp66eP+qwqc7q0WWYATSSCLkozdDPOtULnni3tBFHiJhXF4Wn/uGC/v1MK2FLQdt/M6GK0yp8CJvotKNJe5VNsU+VXWXwxEcH151A0819XOqYs2Xmr54v20wFPZl9W8RZhwk3zzhQhyKK/WpEkEjM+u4AOsBkP4/1FeWF71NrjT3qjI/tCVR4ZuWdooPaa110jeigPlw3je11xaRc540RVSMdRwktVcT7+57tyFGRmiodS9FyJgeQD8AZwB8PYOMLP/b9e0DwHkirwNYVd4gl5sjYYOptk0kFTiV5IWg58MpECQCQQXwhlWt0QaiurXKdo/iAvzZXcsKP4q9OsXZoJUntCY1JDQ7T3frgvVWLWNvH7EIv1so81wE7V8yYJwyeuYbCLDm75mAYbG58YRzgpUpcTqgMZCxyVk/6vsyBJlXa7WzlnHfdb+gH/TZTXv2O9YpY1KDO+gsQ+jpkCViyVnbLB0I= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 16441a9f-e0a5-4535-3732-08da9f11b65a X-MS-Exchange-CrossTenant-AuthSource: SY4P282MB1084.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2022 16:19:25.3503 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SYBP282MB2462 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net strerror() excepts a posivite errno, however libbpf_get_error() or variable err will never be positive when an error occurs. This causes bpftool to output too many "unknown error", even a simple "file not exist" error can't get an accurate prompt. This patch fixed all "strerror(err)" patten in bpftool. Signed-off-by: Tianyi Liu --- tools/bpf/bpftool/btf.c | 6 +++--- tools/bpf/bpftool/gen.c | 4 ++-- tools/bpf/bpftool/map_perf_ring.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index 0744bd115..ac586c0e5 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -643,7 +643,7 @@ static int do_dump(int argc, char **argv) if (err) { btf = NULL; p_err("failed to load BTF from %s: %s", - *argv, strerror(err)); + *argv, strerror(errno)); goto done; } NEXT_ARG(); @@ -689,7 +689,7 @@ static int do_dump(int argc, char **argv) btf = btf__load_from_kernel_by_id_split(btf_id, base_btf); err = libbpf_get_error(btf); if (err) { - p_err("get btf by id (%u): %s", btf_id, strerror(err)); + p_err("get btf by id (%u): %s", btf_id, strerror(errno)); goto done; } } @@ -825,7 +825,7 @@ build_btf_type_table(struct hashmap *tab, enum bpf_obj_type type, u32_as_hash_field(id)); if (err) { p_err("failed to append entry to hashmap for BTF ID %u, object ID %u: %s", - btf_id, id, strerror(errno)); + btf_id, id, strerror(-err)); goto err_free; } } diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c index 7070dcffa..0783069f6 100644 --- a/tools/bpf/bpftool/gen.c +++ b/tools/bpf/bpftool/gen.c @@ -1594,14 +1594,14 @@ static int do_object(int argc, char **argv) err = bpf_linker__add_file(linker, file, NULL); if (err) { - p_err("failed to link '%s': %s (%d)", file, strerror(err), err); + p_err("failed to link '%s': %s (%d)", file, strerror(errno), err); goto out; } } err = bpf_linker__finalize(linker); if (err) { - p_err("failed to finalize ELF file: %s (%d)", strerror(err), err); + p_err("failed to finalize ELF file: %s (%d)", strerror(errno), err); goto out; } diff --git a/tools/bpf/bpftool/map_perf_ring.c b/tools/bpf/bpftool/map_perf_ring.c index 6b0c41015..1650b7127 100644 --- a/tools/bpf/bpftool/map_perf_ring.c +++ b/tools/bpf/bpftool/map_perf_ring.c @@ -198,7 +198,7 @@ int do_event_pipe(int argc, char **argv) err = libbpf_get_error(pb); if (err) { p_err("failed to create perf buffer: %s (%d)", - strerror(err), err); + strerror(errno), err); goto err_close_map; } @@ -213,7 +213,7 @@ int do_event_pipe(int argc, char **argv) err = perf_buffer__poll(pb, 200); if (err < 0 && err != -EINTR) { p_err("perf buffer polling failed: %s (%d)", - strerror(err), err); + strerror(errno), err); goto err_close_pb; } }