From af03fcfeccdec0aa537dd4373a773cdf0d6d7892 Mon Sep 17 00:00:00 2001 From: Matthias Koenig Date: Thu, 20 Sep 2007 11:11:18 +0200 Subject: [PATCH] hwclock: fix --rtc option The --rtc option does not set the name of the device correctly. It still uses /dev/rtc even if the --rtc option is given. Testcase: $ mv /dev/rtc /dev/foo $ hwclock --show --debug --rtc=/dev/foo hwclock from util-linux-2.13-rc2 Using /dev interface to clock. Last drift adjustment done at 1190198135 seconds after 1969 Last calibration done at 1190198135 seconds after 1969 Hardware clock is on local time Assuming hardware clock is kept in local time. Waiting for clock tick... hwclock: open() of /dev/rtc failed, errno=2: No such file or directory. ...got clock tick Co-Author: Karel Zak Signed-off-by: Matthias Koenig Signed-off-by: Karel Zak --- hwclock/rtc.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/hwclock/rtc.c b/hwclock/rtc.c index f8e626eb..724daf99 100644 --- a/hwclock/rtc.c +++ b/hwclock/rtc.c @@ -104,24 +104,21 @@ open_rtc(void) { "/dev/misc/rtc", NULL }; - char **p = fls; - char *fname = rtc_dev_name ? : *p; - - do { - int fd = open(fname, O_RDONLY); - - if (fd < 0 && errno == ENOENT) { - if (fname == rtc_dev_name) - break; - fname = *++p; - } else { - rtc_dev_name = *p; - return fd; - } - } while(fname); - - if (!rtc_dev_name) - rtc_dev_name = *fls; + char **p; + + /* --rtc option has been given */ + if (rtc_dev_name) + return open(rtc_dev_name, O_RDONLY); + + for (p=fls; *p; ++p) { + int fd = open(*p, O_RDONLY); + + if (fd < 0 && errno == ENOENT) + continue; + rtc_dev_name = *p; + return fd; + } + rtc_dev_name = *fls; /* default */ return -1; } -- 2.39.5