From patchwork Tue Jan 10 22:20:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 41682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2997404wrt; Tue, 10 Jan 2023 14:24:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXt6qWgprhv2xxFuynxpNCaUE/HeQGzFTOsTLuKX5BTuXOVff2hrPAUM+kw7sHxo+PQMYmvI X-Received: by 2002:aa7:d28c:0:b0:497:4311:59c7 with SMTP id w12-20020aa7d28c000000b00497431159c7mr13990776edq.18.1673389450047; Tue, 10 Jan 2023 14:24:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673389450; cv=none; d=google.com; s=arc-20160816; b=GhHNTZ4HBQ7/fVeA3O+jYvH5geXa7QMiyJWDPXxX65BVTrS+mRgw1HNWMdZha5O9MJ Gz0ZHDuAnQyAJjg+YQwh5OMxx6Dyw8DWNK3yWLjcXqgAocEsogomJRV88JMpIU73ZGIE Zt7mMqYr0xQYtGXccmjts7FuMM+5XI3xJH0ebLwYGNHnEH8VZrL2VgRoQweS+DgtFt/b LFcSnpDrBaLWPOLAW/ePVduJ1eLLFTQcLtu+EFSwOGIe4Fy/UPKXYYYVh4UNfbpF2Xt4 j8JqkkLDxyidf0JZd3onLJFqpgqmEPibB5rvAwDPqNk4ds3gqxVTCNPoi62Tc+TiGC6y vegw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=/FtIYr0/RheXwrssHV0cFATW8LMtUvVk/N1uI6ptIqc=; b=ZOWLKMIBuk8uuzrnQ7yqaP3J3OFFPXckwQg2SXs52SS26nsyfJ9+FKvoDdIQR9PnzS ocbI/zU23/WfRyiR02/ZFJ9wuMoOII30Mm0G/7uBgpUBp7TkoH7gb3OEAglwgcCkkePd IyfFALDzkLLmn+VZRCb886OPMnyEfVwZ76P8NAe878o/zaeWJ+EtBINAHdlnrfoQGoYi e9LtKQyGUjWiL5hoOUxr2XyLW6RG/2xV1qNMemORXJiopO270OQ1FIc9san0g7qtPXVW vsI4Xmtnlt2IEwO2TPn82hLtRF/UW/6jNaW+cwKrDL9DqfH7Pn/7mH+8Be1zMsURC8Yr 4U2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=RNYP627o; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a05640235ce00b00498af0a0ce7si10641667edc.466.2023.01.10.14.23.45; Tue, 10 Jan 2023 14:24:10 -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=@google.com header.s=20210112 header.b=RNYP627o; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234848AbjAJWWv (ORCPT + 99 others); Tue, 10 Jan 2023 17:22:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235275AbjAJWWH (ORCPT ); Tue, 10 Jan 2023 17:22:07 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D7341A3B1 for ; Tue, 10 Jan 2023 14:21:21 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4d336074463so25498887b3.12 for ; Tue, 10 Jan 2023 14:21:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/FtIYr0/RheXwrssHV0cFATW8LMtUvVk/N1uI6ptIqc=; b=RNYP627ovo2gwEzsZZbFylrtQb+tRstmx8+kwVlpER/K5C5tNb2oBe50zVPZpE1xuZ NU9zXXblOxx6EAKLVYDrvaw3SP0ZyRrbegvCU8UFWhy7tdpYKJsjdqHS8Q8fCYTB2AA1 XfxIcjNfCJVewHShT9ogfUdkxa5rGgTTPcO795wa5pyopE3PY7OwUHSfWNK2py18qEHb lU9rAZ5slO3ij3YjOrOQ5FnhJPYOoz0FdvRAzlSJcgOtT3Q85Tvra/8+nQofX8xCCpMS FEo/8EYdWVgxNvEjlwcyYar4md8dE1bKiVeg7zyJe6xTPO25BRQ85Hz4YMsQr4Ew/YJj ifFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/FtIYr0/RheXwrssHV0cFATW8LMtUvVk/N1uI6ptIqc=; b=m5mUBevCkZfDXDcUMsE0KNi2CGkZ8s7Od8SLZPS8ZQ/S1/2r6NeiroWQHU7xlkPrW2 f0B6zgZCDSAus4DJx1b1uK66nI9dYzzEnFw8XbuNvGwyN8TP3Rqu6gXSrO6fyHDJ6s8q T0QgzGLpmTE/e4HTS6tnmx97NFSu8R68X+Kaqpwh8u4NISC17Z3qfKMjGHkqyqAGkhy+ OZqS5mw1MXktt5PaECtAACxuQTJLMJg/B2Py9wbVFcr0+8MXc7bwvq8kvvwIvk3VLIXC YukauB5TE+BhTzI0rA9CEU/6E7MlbevHGixAc9vhYDJSl8iQHQub7/OKQ9esKR2hyuFc YD1w== X-Gm-Message-State: AFqh2koWvwok5cphPdAO9BTdhQJAhmNt5oRpNxYC+/Bo/hdA9EvLFtw4 D2U1y8EqgYMKoVawttScoblcgPR8cEEB X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:cebf:c37e:8184:56]) (user=irogers job=sendgmr) by 2002:a25:8110:0:b0:6f6:ec71:8ede with SMTP id o16-20020a258110000000b006f6ec718edemr5909003ybk.422.1673389272586; Tue, 10 Jan 2023 14:21:12 -0800 (PST) Date: Tue, 10 Jan 2023 14:20:02 -0800 In-Reply-To: <20230110222003.1591436-1-irogers@google.com> Message-Id: <20230110222003.1591436-7-irogers@google.com> Mime-Version: 1.0 References: <20230110222003.1591436-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v1 6/7] perf help: Use run_command_strbuf From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Nathan Chancellor , Nick Desaulniers , Tom Rix , Nicolas Schier , Masahiro Yamada , Athira Rajeev , Christy Lee , Andrii Nakryiko , Ravi Bangoria , Leo Yan , Yang Jihong , Qi Liu , James Clark , Adrian Hunter , "Masami Hiramatsu (Google)" , Kan Liang , Sean Christopherson , Zhengjun Xing , Rob Herring , Xin Gao , Zechuan Chen , Jason Wang , Christophe JAILLET , Stephane Eranian , German Gomez , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754676016077287910?= X-GMAIL-MSGID: =?utf-8?q?1754676016077287910?= Remove boiler plate by using library routine. Signed-off-by: Ian Rogers --- tools/perf/builtin-help.c | 47 ++++++++++++--------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c index 8874e1e0335b..1cb87358cd20 100644 --- a/tools/perf/builtin-help.c +++ b/tools/perf/builtin-help.c @@ -70,46 +70,27 @@ static const char *get_man_viewer_info(const char *name) static int check_emacsclient_version(void) { struct strbuf buffer = STRBUF_INIT; - struct child_process ec_process; - const char *argv_ec[] = { "emacsclient", "--version", NULL }; - int version; int ret = -1; - /* emacsclient prints its version number on stderr */ - memset(&ec_process, 0, sizeof(ec_process)); - ec_process.argv = argv_ec; - ec_process.err = -1; - ec_process.stdout_to_stderr = 1; - if (start_command(&ec_process)) { - fprintf(stderr, "Failed to start emacsclient.\n"); - return -1; - } - if (strbuf_read(&buffer, ec_process.err, 20) < 0) { - fprintf(stderr, "Failed to read emacsclient version\n"); - goto out; - } - close(ec_process.err); - /* - * Don't bother checking return value, because "emacsclient --version" - * seems to always exits with code 1. + * emacsclient may print its version number on stderr. Don't bother + * checking return value, because some "emacsclient --version" commands + * seem to always exits with code 1. */ - finish_command(&ec_process); + run_command_strbuf("emacsclient --version 2>&1", &buffer); - if (!strstarts(buffer.buf, "emacsclient")) { + if (!strstarts(buffer.buf, "emacsclient")) fprintf(stderr, "Failed to parse emacsclient version.\n"); - goto out; - } - - version = atoi(buffer.buf + strlen("emacsclient")); + else { + int version = atoi(buffer.buf + strlen("emacsclient")); - if (version < 22) { - fprintf(stderr, - "emacsclient version '%d' too old (< 22).\n", - version); - } else - ret = 0; -out: + if (version < 22) { + fprintf(stderr, + "emacsclient version '%d' too old (< 22).\n", + version); + } else + ret = 0; + } strbuf_release(&buffer); return ret; }