From: Karel Zak <kzak@redhat.com>
To: Sami Kerola <kerolasa@iki.fi>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 09/13] rtcwake: do not overwrite device name
Date: Tue, 24 Feb 2015 14:00:02 +0100 [thread overview]
Message-ID: <20150224130002.GR19430@ws.net.home> (raw)
In-Reply-To: <1424616139-638-10-git-send-email-kerolasa@iki.fi>
On Sun, Feb 22, 2015 at 02:42:15PM +0000, Sami Kerola wrote:
> This improves error messaging, and allows freeing path to device when it
> is not needed.
>
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> sys-utils/rtcwake.c | 44 +++++++++++++++++++++++---------------------
> 1 file changed, 23 insertions(+), 21 deletions(-)
>
> diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c
> index f951c9c..7f1e351 100644
> --- a/sys-utils/rtcwake.c
> +++ b/sys-utils/rtcwake.c
> @@ -49,7 +49,7 @@
>
> #define RTC_PATH "/sys/class/rtc/%s/device/power/wakeup"
This is really bad name, what about SYS_WAKEUP_PATH_TEMPLATE ?
> +static int open_dev_rtc(const char *devname)
> +{
> + int fd;
> + char *devpath;
> + size_t len = strlen(devname);
> +
> + devpath = xmalloc(sizeof "/dev/" + len);
> + memcpy(devpath, "/dev/", sizeof "/dev/");
> + memcpy(devpath + strlen("/dev/"), devname, len + 1);
if (startswith(devname, "/dev"))
devpath = devname;
else
xasprintf(&devpath, "/dev/%s", devname);
> +#ifdef O_CLOEXEC
> + fd = open(devpath, O_RDONLY | O_CLOEXEC);
> +#else
> + fd = open(devpath, O_RDONLY);
> +#endif
we use O_CLOEXEC everywhere, #ifdef is unecessary
> + if (fd < 0)
> + err(EXIT_FAILURE, _("%s: unable to find device"), devpath);
if (devname != devpath)
free(devpath);
> + free(devpath);
> + return fd;
> +}
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
next prev parent reply other threads:[~2015-02-24 13:00 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-22 14:42 [PATCH 00/13] pull: rtcwake changes Sami Kerola
2015-02-22 14:42 ` [PATCH 01/13] rtcwake: add rtcwake_control and remove global variables Sami Kerola
2015-02-22 14:42 ` [PATCH 02/13] rtcwake: enumerate constant mode strings Sami Kerola
2015-02-24 12:34 ` Karel Zak
2015-03-01 12:23 ` Sami Kerola
2015-02-22 14:42 ` [PATCH 03/13] rtcwake: replace long if else statement with switch case Sami Kerola
2015-02-22 14:42 ` [PATCH 04/13] rtcwake: remove RTC_ALM_READ and RTC_ALM_SET compatibility Sami Kerola
2015-02-23 20:37 ` Benno Schulenberg
2015-03-01 11:24 ` Sami Kerola
2015-02-22 14:42 ` [PATCH 05/13] rtcwake: improve read_clock_mode() Sami Kerola
2015-02-22 14:42 ` [PATCH 06/13] rtcwake: add human readable --date timestamp format Sami Kerola
2015-02-23 20:32 ` Benno Schulenberg
2015-02-22 14:42 ` [PATCH 07/13] rtcwake: fix preprocessor redefinition Sami Kerola
2015-02-22 14:42 ` [PATCH 08/13] rtcwake: clean up struct tm initializations Sami Kerola
2015-02-22 14:42 ` [PATCH 09/13] rtcwake: do not overwrite device name Sami Kerola
2015-02-24 13:00 ` Karel Zak [this message]
2015-03-01 12:24 ` Sami Kerola
2015-02-22 14:42 ` [PATCH 10/13] bash-completion: add freeze mode to rtcwake Sami Kerola
2015-02-24 13:01 ` Karel Zak
2015-03-01 12:26 ` Sami Kerola
2015-02-22 14:42 ` [PATCH 11/13] rtcwake: improve coding style Sami Kerola
2015-02-23 20:40 ` Benno Schulenberg
2015-03-01 11:33 ` Sami Kerola
2015-03-02 20:48 ` Benno Schulenberg
2015-02-22 14:42 ` [PATCH 12/13] rtcwake: make some command line options mutually exclusive Sami Kerola
2015-02-22 14:42 ` [PATCH 13/13] rtcwake: read accepted mode strings from /sys/power/state Sami Kerola
2015-06-02 12:48 ` [PATCH 00/13] pull: rtcwake changes Karel Zak
2015-06-07 20:41 ` Sami Kerola
2015-06-29 13:21 ` Karel Zak
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=20150224130002.GR19430@ws.net.home \
--to=kzak@redhat.com \
--cc=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/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