diff options
author | Sami Kerola | 2015-01-10 19:03:25 +0100 |
---|---|---|
committer | Karel Zak | 2015-06-29 13:39:37 +0200 |
commit | 3e5a54554dd1495d10427163e911c24ba4c9e558 (patch) | |
tree | d4a667f77e0d2c20d0fbb211e866c3f4dd6ac181 /sys-utils/rtcwake.c | |
parent | rtcwake: remove RTC_ALM_READ and RTC_ALM_SET compatibility (diff) | |
download | kernel-qcow2-util-linux-3e5a54554dd1495d10427163e911c24ba4c9e558.tar.gz kernel-qcow2-util-linux-3e5a54554dd1495d10427163e911c24ba4c9e558.tar.xz kernel-qcow2-util-linux-3e5a54554dd1495d10427163e911c24ba4c9e558.zip |
rtcwake: improve read_clock_mode()
Make skipping two lines more robust, and add message about unexpected
adjfile contents when running with --verbose.
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/rtcwake.c')
-rw-r--r-- | sys-utils/rtcwake.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/sys-utils/rtcwake.c b/sys-utils/rtcwake.c index 3c8238d27..6d67fc26a 100644 --- a/sys-utils/rtcwake.c +++ b/sys-utils/rtcwake.c @@ -47,7 +47,7 @@ #define RTC_AF 0x20 #define RTC_UF 0x10 -#define MAX_LINE 1024 +#define ADJTIME_ZONE_STRLEN 8 #define RTC_PATH "/sys/class/rtc/%s/device/power/wakeup" #define SYS_POWER_STATE_PATH "/sys/power/state" @@ -294,30 +294,23 @@ static void suspend_system(struct rtcwake_control *ctl, int suspend) errx(EXIT_FAILURE, _("write error")); } - static int read_clock_mode(struct rtcwake_control *ctl) { FILE *fp; - char linebuf[MAX_LINE]; + char linebuf[ADJTIME_ZONE_STRLEN]; fp = fopen(ctl->adjfile, "r"); if (!fp) return -1; - /* skip first line */ - if (!fgets(linebuf, MAX_LINE, fp)) { - fclose(fp); - return -1; - } - - /* skip second line */ - if (!fgets(linebuf, MAX_LINE, fp)) { + /* skip two lines */ + if (skip_fline(fp) || skip_fline(fp)) { fclose(fp); return -1; } /* read third line */ - if (!fgets(linebuf, MAX_LINE, fp)) { + if (!fgets(linebuf, sizeof linebuf, fp)) { fclose(fp); return -1; } @@ -326,6 +319,8 @@ static int read_clock_mode(struct rtcwake_control *ctl) ctl->clock_mode = CM_UTC; else if (strncmp(linebuf, "LOCAL", 5) == 0) ctl->clock_mode = CM_LOCAL; + else if (ctl->verbose) + warnx(_("unexpected third line in: %s: %s"), ctl->adjfile, linebuf); fclose(fp); |