summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorCody P Schafer <dev@codyps.com>2014-05-27 20:21:56 -0400
committerJiri Olsa <jolsa@kernel.org>2014-06-03 15:34:29 -0400
commitf2d9627b2b31506204417bb6842a7ea88970b700 (patch)
tree3f829a11914629a01008d0ce525f1177cc361e4f /tools
parent16a6433615c14097fd8d406b10ce6393aebb7017 (diff)
perf tools: Allow overriding sysfs and proc finding with env var
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/api/fs/fs.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
index 5b5eb788996e..c1b49c36a951 100644
--- a/tools/lib/api/fs/fs.c
+++ b/tools/lib/api/fs/fs.c
@@ -1,8 +1,10 @@
1/* TODO merge/factor in debugfs.c here */ 1/* TODO merge/factor in debugfs.c here */
2 2
3#include <ctype.h>
3#include <errno.h> 4#include <errno.h>
4#include <stdbool.h> 5#include <stdbool.h>
5#include <stdio.h> 6#include <stdio.h>
7#include <stdlib.h>
6#include <string.h> 8#include <string.h>
7#include <sys/vfs.h> 9#include <sys/vfs.h>
8 10
@@ -96,12 +98,51 @@ static bool fs__check_mounts(struct fs *fs)
96 return false; 98 return false;
97} 99}
98 100
101static void mem_toupper(char *f, size_t len)
102{
103 while (len) {
104 *f = toupper(*f);
105 f++;
106 len--;
107 }
108}
109
110/*
111 * Check for "NAME_PATH" environment variable to override fs location (for
112 * testing). This matches the recommendation in Documentation/sysfs-rules.txt
113 * for SYSFS_PATH.
114 */
115static bool fs__env_override(struct fs *fs)
116{
117 char *override_path;
118 size_t name_len = strlen(fs->name);
119 /* name + "_PATH" + '\0' */
120 char upper_name[name_len + 5 + 1];
121 memcpy(upper_name, fs->name, name_len);
122 mem_toupper(upper_name, name_len);
123 strcpy(&upper_name[name_len], "_PATH");
124
125 override_path = getenv(upper_name);
126 if (!override_path)
127 return false;
128
129 fs->found = true;
130 strncpy(fs->path, override_path, sizeof(fs->path));
131 return true;
132}
133
99static const char *fs__get_mountpoint(struct fs *fs) 134static const char *fs__get_mountpoint(struct fs *fs)
100{ 135{
136 if (fs__env_override(fs))
137 return fs->path;
138
101 if (fs__check_mounts(fs)) 139 if (fs__check_mounts(fs))
102 return fs->path; 140 return fs->path;
103 141
104 return fs__read_mounts(fs) ? fs->path : NULL; 142 if (fs__read_mounts(fs))
143 return fs->path;
144
145 return NULL;
105} 146}
106 147
107static const char *fs__mountpoint(int idx) 148static const char *fs__mountpoint(int idx)