Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1575317
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers |
| Date | 2017-02-07 02:50 +0100 |
| Message-ID | <t834R-4uf-1@gated-at.bofh.it> (permalink) |
| References | (2 earlier) <t7QU1-4ZM-3@gated-at.bofh.it> <t7QU1-4ZM-5@gated-at.bofh.it> <t7QU1-4ZM-1@gated-at.bofh.it> <t82sa-4gx-27@gated-at.bofh.it> <t82sa-4gx-25@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Em Tue, Feb 07, 2017 at 02:09:17AM +0100, Borislav Petkov escreveu:
> From: Borislav Petkov <bp@suse.de>
>
> Add helper functions to be able to read/write ints into proc files.
>
> Signed-off-by: Borislav Petkov <bp@suse.de>
> ---
> tools/lib/api/fs/fs.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> tools/lib/api/fs/fs.h | 3 +++
> 2 files changed, 45 insertions(+)
>
> diff --git a/tools/lib/api/fs/fs.c b/tools/lib/api/fs/fs.c
> index 4b6bfc43cccf..8e4b9fe18b75 100644
> --- a/tools/lib/api/fs/fs.c
> +++ b/tools/lib/api/fs/fs.c
> @@ -314,6 +314,22 @@ int filename__read_int(const char *filename, int *value)
> return err;
> }
>
> +int filename__write_int(const char *filename, int value)
> +{
> + char line[64];
> + int fd = open(filename, O_WRONLY), err = -1;
> +
> + if (fd < 0)
> + return -1;
> +
> + snprintf(line, sizeof(int), "%d", value);
> +
> + err = write(fd, line, strnlen(line, 64));
> +
> + close(fd);
> + return err;
> +}
> +
> /*
> * Parses @value out of @filename with strtoull.
> * By using 0 for base, the strtoull detects the
> @@ -400,6 +416,32 @@ int procfs__read_str(const char *entry, char **buf, size_t *sizep)
> return filename__read_str(path, buf, sizep);
> }
>
> +int procfs__read_int(const char *entry, int *value)
> +{
> + char path[PATH_MAX];
> + const char *procfs = procfs__mountpoint();
> +
> + if (!procfs)
> + return -1;
> +
> + snprintf(path, sizeof(path), "%s/%s", procfs, entry);
> +
> + return filename__read_int(path, value);
> +}
> +
> +int procfs__write_int(const char *entry, int value)
> +{
> + char path[PATH_MAX];
> + const char *procfs = procfs__mountpoint();
> +
> + if (!procfs)
> + return -1;
> +
> + snprintf(path, sizeof(path), "%s/%s", procfs, entry);
> +
> + return filename__write_int(path, value);
> +}
> +
> int sysfs__read_ull(const char *entry, unsigned long long *value)
> {
> char path[PATH_MAX];
> diff --git a/tools/lib/api/fs/fs.h b/tools/lib/api/fs/fs.h
> index 6b332dc74498..095f25d4c70f 100644
> --- a/tools/lib/api/fs/fs.h
> +++ b/tools/lib/api/fs/fs.h
> @@ -28,9 +28,12 @@ FS(bpf_fs)
>
>
> int filename__read_int(const char *filename, int *value);
> +int filename__write_int(const char *filename, int value);
> int filename__read_ull(const char *filename, unsigned long long *value);
> int filename__read_str(const char *filename, char **buf, size_t *sizep);
>
> +int procfs__read_int(const char *entry, int *value);
> +int procfs__write_int(const char *entry, int value);
> int procfs__read_str(const char *entry, char **buf, size_t *sizep);
>
> int sysctl__read_int(const char *sysctl, int *value);
Isn't sysctl__read_int() what you want?
See next patch...
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-06 13:20 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Ingo Molnar <mingo@kernel.org> - 2017-02-06 13:30 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-06 13:50 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-06 13:50 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Robert Richter <rric@kernel.org> - 2017-02-06 14:20 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-06 14:30 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Ingo Molnar <mingo@kernel.org> - 2017-02-07 08:30 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-07 12:00 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-07 16:10 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-11 18:10 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Ingo Molnar <mingo@kernel.org> - 2017-02-11 19:00 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-11 19:40 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Ingo Molnar <mingo@kernel.org> - 2017-02-11 21:50 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Vince Weaver <vince@deater.net> - 2017-02-06 15:30 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-06 18:10 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov <bp@alien8.de> - 2017-02-07 02:10 +0100
[PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers Borislav Petkov <bp@alien8.de> - 2017-02-07 02:10 +0100
Re: [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-07 02:50 +0100
Re: [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers Borislav Petkov <bp@alien8.de> - 2017-02-07 11:40 +0100
Re: [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers Borislav Petkov <bp@alien8.de> - 2017-02-07 16:10 +0100
Re: [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-07 16:40 +0100
Re: [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-07 16:10 +0100
[PATCH 2/2] perf stat: Disable HW watchdog around a perf stat session Borislav Petkov <bp@alien8.de> - 2017-02-07 02:20 +0100
Re: [PATCH 2/2] perf stat: Disable HW watchdog around a perf stat session Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-07 02:50 +0100
Re: [RFC PATCH] perf/stat: Add --disable-hwdt Ingo Molnar <mingo@kernel.org> - 2017-02-06 13:50 +0100
csiph-web