* [PATCH v2] tools/perf: allow overriding sysfs and proc finding with env var
@ 2014-04-16 20:39 Cody P Schafer
2014-04-17 18:04 ` Jiri Olsa
0 siblings, 1 reply; 2+ messages in thread
From: Cody P Schafer @ 2014-04-16 20:39 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Borislav Petkov, Cody P Schafer, Jiri Olsa; +Cc: LKML
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 <cody@linux.vnet.ibm.com>
---
Since v1: rebased onto acme's perf/core
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..10783a6 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;
+ strcpy(fs->path, override_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.9.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] tools/perf: allow overriding sysfs and proc finding with env var
2014-04-16 20:39 [PATCH v2] tools/perf: allow overriding sysfs and proc finding with env var Cody P Schafer
@ 2014-04-17 18:04 ` Jiri Olsa
0 siblings, 0 replies; 2+ messages in thread
From: Jiri Olsa @ 2014-04-17 18:04 UTC (permalink / raw)
To: Cody P Schafer; +Cc: Arnaldo Carvalho de Melo, Borislav Petkov, LKML
On Wed, Apr 16, 2014 at 01:39:46PM -0700, Cody P Schafer wrote:
SNIP
> +
> +/*
> + * 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;
> + strcpy(fs->path, override_path);
please use strncpy with size of fs->path
thanks,
jirka
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-04-17 18:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-16 20:39 [PATCH v2] tools/perf: allow overriding sysfs and proc finding with env var Cody P Schafer
2014-04-17 18:04 ` Jiri Olsa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®