diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-11 11:37:10 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-11 15:53:00 -0500 |
commit | 42e3c4a1274d49b42e9d4306ec096b282a6e14aa (patch) | |
tree | f87fd0437839d08c4b6fc1bbdfddfc5b278e362c /tools/lib | |
parent | 3a351127cbc682c3a0ae7383c4ff6fd0e8fee83c (diff) |
tools lib fs: Add sysctl__read_int helper
Will come in handy for tools, see next patches.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-nay9j62ztxpytt4ew1tkl4op@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/api/fs/fs.c | 13 | ||||
-rw-r--r-- | tools/lib/api/fs/fs.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c index b8d0df8878d1..65d9be3f9887 100644 --- a/tools/lib/api/fs/fs.c +++ b/tools/lib/api/fs/fs.c | |||
@@ -184,3 +184,16 @@ int filename__read_int(const char *filename, int *value) | |||
184 | close(fd); | 184 | close(fd); |
185 | return err; | 185 | return err; |
186 | } | 186 | } |
187 | |||
188 | int sysctl__read_int(const char *sysctl, int *value) | ||
189 | { | ||
190 | char path[PATH_MAX]; | ||
191 | const char *procfs = procfs__mountpoint(); | ||
192 | |||
193 | if (!procfs) | ||
194 | return -1; | ||
195 | |||
196 | snprintf(path, sizeof(path), "%s/sys/%s", procfs, sysctl); | ||
197 | |||
198 | return filename__read_int(path, value); | ||
199 | } | ||
diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h index 4d0aef6e7163..6caa2bbc6cec 100644 --- a/tools/lib/api/fs/fs.h +++ b/tools/lib/api/fs/fs.h | |||
@@ -13,4 +13,5 @@ const char *sysfs__mountpoint(void); | |||
13 | const char *procfs__mountpoint(void); | 13 | const char *procfs__mountpoint(void); |
14 | 14 | ||
15 | int filename__read_int(const char *filename, int *value); | 15 | int filename__read_int(const char *filename, int *value); |
16 | int sysctl__read_int(const char *sysctl, int *value); | ||
16 | #endif /* __API_FS__ */ | 17 | #endif /* __API_FS__ */ |