From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753467AbbJFXAE (ORCPT ); Tue, 6 Oct 2015 19:00:04 -0400 Received: from [8.25.196.27] ([8.25.196.27]:61309 "EHLO ham-cannon.twitter.com" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753341AbbJFXAC (ORCPT ); Tue, 6 Oct 2015 19:00:02 -0400 X-Greylist: delayed 375 seconds by postgrey-1.27 at vger.kernel.org; Tue, 06 Oct 2015 19:00:02 EDT X-DKIM: Sendmail DKIM Filter v2.8.2 2452415620.twitter.com E81D8128606 X-DomainKeys: Sendmail DomainKeys Filter v1.0.2 2452415620.twitter.com E81D8128606 From: Matt Mullins To: acme@kernel.org Cc: Matt Mullins , Vinson Lee , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , Andi Kleen , linux-kernel@vger.kernel.org Subject: [PATCH] perf tools: get version from uname(2), not /proc Date: Tue, 6 Oct 2015 15:53:14 -0700 Message-Id: <1444171996-24030-1-git-send-email-mmullins@twopensource.com> X-Mailer: git-send-email 2.1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tools in kmod (e.g. modprobe) compose the module path from the release from uname(2). Because we use the UNAME26 personality, we need perf to find modules located at the same path as the system tools. Signed-off-by: Matt Mullins Cc: Vinson Lee --- tools/perf/util/machine.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 5ef90be2a249..51199bc271e9 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -11,6 +11,7 @@ #include "vdso.h" #include #include +#include #include "unwind.h" #include "linux/hash.h" @@ -903,31 +904,14 @@ static void map_groups__fixup_end(struct map_groups *mg) __map_groups__fixup_end(mg, i); } -static char *get_kernel_version(const char *root_dir) +static char *get_kernel_version(void) { - char version[PATH_MAX]; - FILE *file; - char *name, *tmp; - const char *prefix = "Linux version "; + struct utsname utsname; - sprintf(version, "%s/proc/version", root_dir); - file = fopen(version, "r"); - if (!file) + if (uname(&utsname)) return NULL; - version[0] = '\0'; - tmp = fgets(version, sizeof(version), file); - fclose(file); - - name = strstr(version, prefix); - if (!name) - return NULL; - name += strlen(prefix); - tmp = strchr(name, ' '); - if (tmp) - *tmp = '\0'; - - return strdup(name); + return strdup(utsname.release); } static bool is_kmod_dso(struct dso *dso) @@ -1027,7 +1011,7 @@ static int machine__set_modules_path(struct machine *machine) char *version; char modules_path[PATH_MAX]; - version = get_kernel_version(machine->root_dir); + version = get_kernel_version(); if (!version) return -1; -- 2.1.0