All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Cody P Schafer <dev@codyps.com>,
	Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>,
	Jiri Olsa <jolsa@kernel.org>
Subject: [PATCH 4/9] perf tools: Allow overriding sysfs and proc finding with env var
Date: Tue,  3 Jun 2014 22:36:11 +0200	[thread overview]
Message-ID: <1401827776-4443-5-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1401827776-4443-1-git-send-email-jolsa@kernel.org>

From: Cody P Schafer <dev@codyps.com>

SYSFS_PATH and PROC_PATH environment variables now let the user override
the detection of sysfs and proc locations for testing purposes.

Signed-off-by: Cody P Schafer <dev@codyps.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1401236684-10579-2-git-send-email-dev@codyps.com
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/lib/api/fs/fs.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index 5b5eb78..c1b49c3 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -1,8 +1,10 @@
 /* TODO merge/factor in debugfs.c here */
 
+#include <ctype.h>
 #include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/vfs.h>
 
@@ -96,12 +98,51 @@ static bool fs__check_mounts(struct fs *fs)
 	return false;
 }
 
+static void mem_toupper(char *f, size_t len)
+{
+	while (len) {
+		*f = toupper(*f);
+		f++;
+		len--;
+	}
+}
+
+/*
+ * Check for "NAME_PATH" environment variable to override fs location (for
+ * testing). This matches the recommendation in Documentation/sysfs-rules.txt
+ * for SYSFS_PATH.
+ */
+static bool fs__env_override(struct fs *fs)
+{
+	char *override_path;
+	size_t name_len = strlen(fs->name);
+	/* name + "_PATH" + '\0' */
+	char upper_name[name_len + 5 + 1];
+	memcpy(upper_name, fs->name, name_len);
+	mem_toupper(upper_name, name_len);
+	strcpy(&upper_name[name_len], "_PATH");
+
+	override_path = getenv(upper_name);
+	if (!override_path)
+		return false;
+
+	fs->found = true;
+	strncpy(fs->path, override_path, sizeof(fs->path));
+	return true;
+}
+
 static const char *fs__get_mountpoint(struct fs *fs)
 {
+	if (fs__env_override(fs))
+		return fs->path;
+
 	if (fs__check_mounts(fs))
 		return fs->path;
 
-	return fs__read_mounts(fs) ? fs->path : NULL;
+	if (fs__read_mounts(fs))
+		return fs->path;
+
+	return NULL;
 }
 
 static const char *fs__mountpoint(int idx)
-- 
1.8.3.1


  parent reply	other threads:[~2014-06-03 20:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03 20:36 [GIT PULL 0/9] perf/core improvements and fixes Jiri Olsa
2014-06-03 20:36 ` [PATCH 1/9] perf trace: Warn the user when not available Jiri Olsa
2014-06-03 20:36 ` [PATCH 2/9] perf tools: Add warning when disabling perl scripting support due to missing devel files Jiri Olsa
2014-06-03 20:36 ` [PATCH 3/9] perf tools: Consider header files outside perf directory in tags target Jiri Olsa
2014-06-03 20:36 ` Jiri Olsa [this message]
2014-06-03 20:36 ` [PATCH 5/9] perf tools: Fix "==" into "=" in ui_browser__warning assignment Jiri Olsa
2014-06-03 20:36 ` [PATCH 6/9] perf tools: Remove elide setup for SORT_MODE__MEMORY mode Jiri Olsa
2014-06-03 20:36 ` [PATCH 7/9] perf tools: Move elide bool into perf_hpp_fmt struct Jiri Olsa
2014-06-03 20:36 ` [PATCH 8/9] perf record: Fix poll return value propagation Jiri Olsa
2014-06-03 20:36 ` [PATCH 9/9] perf tools: Fix 'make help' message error Jiri Olsa
2014-06-05  8:45 ` [GIT PULL 0/9] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1401827776-4443-5-git-send-email-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=dev@codyps.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=sukadev@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.