[PATCH] hwclock: fix --rtc option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Matthias Koenig <mkoenig@xxxxxxx>
---
 hwclock/rtc.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/hwclock/rtc.c b/hwclock/rtc.c
index f8e626e..2f35437 100644
--- a/hwclock/rtc.c
+++ b/hwclock/rtc.c
@@ -105,14 +105,24 @@ open_rtc(void) {
 		NULL
 	};
 	char **p = fls;
-	char *fname = rtc_dev_name ? : *p;
+	char *fname = *p;
+	int fd;
 
+	/* --rtc option has been given */
+	if (rtc_dev_name) {
+		fd = open(rtc_dev_name, O_RDONLY);
+
+		if (fd < 0 && errno == ENOENT)
+			return -1;
+		else
+			return fd;
+	}
+
+	/* try default devices */
 	do {
-		int fd = open(fname, O_RDONLY);
+		fd = open(fname, O_RDONLY);
 
 		if (fd < 0 && errno == ENOENT) {
-			if (fname == rtc_dev_name)
-				break;
 			fname = *++p;
 		} else {
 			rtc_dev_name = *p;
-- 
1.5.2.4

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux