Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp485648img; Thu, 28 Feb 2019 03:02:15 -0800 (PST) X-Google-Smtp-Source: AHgI3IbW4Yg41X38IOUerKBYf/ux4lBqMm+wc9Dju00CItQF54KVnEUW4/AhT4T6ZDCPkqCzDtIy X-Received: by 2002:a62:1b03:: with SMTP id b3mr6849469pfb.218.1551351735161; Thu, 28 Feb 2019 03:02:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551351735; cv=none; d=google.com; s=arc-20160816; b=ftKeeUpArnFfgV7D8tvS0uhFgA4u9DYc8VJR5upgcdob/B+JZ6BYiQE3nB4hk2J+vl xPg0AmKJIwHVBMxRENTTYsuTdYnIHunVglGmrokWYF0k138WTPWSsGAO1f3d4JiUaWy+ j6rgDoHgh35HafVygbmcmgh6Dnbz7zoxbnwQhi1RpsD17lS94fABDRIN2hGoISNWq7cf q9vw+aVwUMYm7t/DLFH37CgjkBbJdQcyv26zjNkwfJb74WwsX/a1KRj+jroAn/yzU2md VbsCW1T8p9F3OK4RJcXE0Pt0IpfrFfi0Q8XH7jv8Lchc22I9c5MPsK6Dh2YuulIEIv+8 oi/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=VpVe9yfOKiFnM9h9aw/ih9g+HVAQmRkF9/desDkIC7c=; b=RRwlMLiER0nQqATa8yXeOXImXOrOYFZJYEuhTG/oSplIiYtWMPxdNTa/9qjM/EGCWj WSTAFurriCiY2d9oHsNUV6WhDx98IuJmwltmr1j2Z+I74FR6qlAVNStoRFNhDJyvv4V8 HaFVhVMGChMSQ0ksebJuyj73QYzf28AvDX5xCP6Ovp3ntG/jtvWa1WZU9ginusr+CvFu Ij7Tm6OIPNiHuBr/O/GL7mKz9lbDmGKt0fBomj9fzF5kvHamkebVJkFuyM3Cwp1HlrmR p00XIwcYYTT3WsQn6GFT/2uxYW081vWqNzOUJBB13XGAsXobkVGNJaAB5M7ZurwIy/Hx Z5Qg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si17537430pgu.566.2019.02.28.03.01.58; Thu, 28 Feb 2019 03:02:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731856AbfB1IGe (ORCPT + 99 others); Thu, 28 Feb 2019 03:06:34 -0500 Received: from terminus.zytor.com ([198.137.202.136]:40421 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730263AbfB1IGe (ORCPT ); Thu, 28 Feb 2019 03:06:34 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x1S85O4w2954976 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 28 Feb 2019 00:05:24 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x1S85OWC2954973; Thu, 28 Feb 2019 00:05:24 -0800 Date: Thu, 28 Feb 2019 00:05:24 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Andi Kleen Message-ID: Cc: acme@redhat.com, mingo@kernel.org, eranian@google.com, hpa@zytor.com, ak@linux.intel.com, tglx@linutronix.de, jolsa@kernel.org, linux-kernel@vger.kernel.org, namhyung@kernel.org Reply-To: hpa@zytor.com, eranian@google.com, mingo@kernel.org, acme@redhat.com, linux-kernel@vger.kernel.org, jolsa@kernel.org, namhyung@kernel.org, ak@linux.intel.com, tglx@linutronix.de In-Reply-To: <20190224153722.27020-9-andi@firstfloor.org> References: <20190224153722.27020-9-andi@firstfloor.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Add perf_exe() helper to find perf binary Git-Commit-ID: 94816add0005595ea33fc8456519be582330401e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 94816add0005595ea33fc8456519be582330401e Gitweb: https://git.kernel.org/tip/94816add0005595ea33fc8456519be582330401e Author: Andi Kleen AuthorDate: Sun, 24 Feb 2019 07:37:19 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 25 Feb 2019 10:58:28 -0300 perf tools: Add perf_exe() helper to find perf binary Also convert one existing user. Signed-off-by: Andi Kleen Acked-by: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20190224153722.27020-9-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/header.c | 12 +++--------- tools/perf/util/util.c | 10 ++++++++++ tools/perf/util/util.h | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index a2323d777dae..01b324c275b9 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -527,17 +527,11 @@ static int write_event_desc(struct feat_fd *ff, static int write_cmdline(struct feat_fd *ff, struct perf_evlist *evlist __maybe_unused) { - char buf[MAXPATHLEN]; - u32 n; - int i, ret; + char pbuf[MAXPATHLEN], *buf; + int i, ret, n; /* actual path to perf binary */ - ret = readlink("/proc/self/exe", buf, sizeof(buf) - 1); - if (ret <= 0) - return -1; - - /* readlink() does not add null termination */ - buf[ret] = '\0'; + buf = perf_exe(pbuf, MAXPATHLEN); /* account for binary path */ n = perf_env.nr_cmdline + 1; diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 706818693086..d388f80d8703 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -568,3 +568,13 @@ out: return tip; } + +char *perf_exe(char *buf, int len) +{ + int n = readlink("/proc/self/exe", buf, len); + if (n > 0) { + buf[n] = 0; + return buf; + } + return strcpy(buf, "perf"); +} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 01c538027c6f..09c1b0f91f65 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -77,6 +77,8 @@ extern bool perf_singlethreaded; void perf_set_singlethreaded(void); void perf_set_multithreaded(void); +char *perf_exe(char *buf, int len); + #ifndef O_CLOEXEC #ifdef __sparc__ #define O_CLOEXEC 0x400000