tools lib fs: Add sysctl__read_int helper
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 11 Dec 2014 16:37:10 +0000 (13:37 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 11 Dec 2014 20:53:00 +0000 (17:53 -0300)
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>
tools/lib/api/fs/fs.c
tools/lib/api/fs/fs.h

index b8d0df8878d1e8847c0c62dfb999fb5f1f95854e..65d9be3f988747ae300db30d3b62cf0e8213dd69 100644 (file)
@@ -184,3 +184,16 @@ int filename__read_int(const char *filename, int *value)
        close(fd);
        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);
+}
index 4d0aef6e71639f3e43bbf5b5e3e3c041de48f87d..6caa2bbc6cecdc2f7fa39b69fa1cf30f8653f15e 100644 (file)
@@ -13,4 +13,5 @@ const char *sysfs__mountpoint(void);
 const char *procfs__mountpoint(void);
 
 int filename__read_int(const char *filename, int *value);
+int sysctl__read_int(const char *sysctl, int *value);
 #endif /* __API_FS__ */