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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3a351127
...@@ -184,3 +184,16 @@ int filename__read_int(const char *filename, int *value) ...@@ -184,3 +184,16 @@ int filename__read_int(const char *filename, int *value)
close(fd); close(fd);
return err; return err;
} }
int sysctl__read_int(const char *sysctl, int *value)
{
char path[PATH_MAX];
const char *procfs = procfs__mountpoint();
if (!procfs)
return -1;
snprintf(path, sizeof(path), "%s/sys/%s", procfs, sysctl);
return filename__read_int(path, value);
}
...@@ -13,4 +13,5 @@ const char *sysfs__mountpoint(void); ...@@ -13,4 +13,5 @@ const char *sysfs__mountpoint(void);
const char *procfs__mountpoint(void); const char *procfs__mountpoint(void);
int filename__read_int(const char *filename, int *value); int filename__read_int(const char *filename, int *value);
int sysctl__read_int(const char *sysctl, int *value);
#endif /* __API_FS__ */ #endif /* __API_FS__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment