public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Borislav Petkov <bp@alien8.de>
Cc: Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Robert Richter <rric@kernel.org>, Vince Weaver <vince@deater.net>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers
Date: Mon, 6 Feb 2017 22:43:56 -0300	[thread overview]
Message-ID: <20170207014356.GE24988@kernel.org> (raw)
In-Reply-To: <20170207010917.36ysrh6p7yktxwhc@pd.tnic>

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...

  reply	other threads:[~2017-02-07  1:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-06 12:15 [RFC PATCH] perf/stat: Add --disable-hwdt Borislav Petkov
2017-02-06 12:22 ` Ingo Molnar
2017-02-06 12:41   ` Borislav Petkov
2017-02-06 12:44     ` Ingo Molnar
2017-02-06 12:49       ` Borislav Petkov
2017-02-06 13:18         ` Robert Richter
2017-02-06 13:23           ` Borislav Petkov
2017-02-07  7:25             ` Ingo Molnar
2017-02-07 10:54               ` Borislav Petkov
2017-02-07 15:06                 ` Borislav Petkov
2017-02-11 17:03                   ` Borislav Petkov
2017-02-11 17:59                     ` Ingo Molnar
2017-02-11 18:32                       ` Borislav Petkov
2017-02-11 20:41                         ` Ingo Molnar
2017-03-07  7:21                         ` [tip:perf/core] perf stat: Issue a HW watchdog disable hint tip-bot for Borislav Petkov
2017-02-06 14:23           ` [RFC PATCH] perf/stat: Add --disable-hwdt Vince Weaver
2017-02-06 17:02             ` Borislav Petkov
2017-02-07  1:08         ` Borislav Petkov
2017-02-07  1:09           ` [PATCH 1/2] tools/lib/api/fs: Add procfs int read/write helpers Borislav Petkov
2017-02-07  1:43             ` Arnaldo Carvalho de Melo [this message]
2017-02-07 10:30               ` Borislav Petkov
2017-02-07 15:00                 ` Arnaldo Carvalho de Melo
2017-02-07 15:08                   ` Borislav Petkov
2017-02-07 15:34                     ` Arnaldo Carvalho de Melo
2017-02-07  1:10           ` [PATCH 2/2] perf stat: Disable HW watchdog around a perf stat session Borislav Petkov
2017-02-07  1:45             ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170207014356.GE24988@kernel.org \
    --to=acme@kernel.org \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rric@kernel.org \
    --cc=vince@deater.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox