From 364cda4857f7dd5e2b4e2eb7583a2eaa279ef4ed Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 7 Dec 2006 00:25:48 +0100 Subject: Imported from util-linux-2.11f tarball. --- hwclock/hwclock.8 | 18 +++- hwclock/hwclock.c | 78 +++++++++++------ hwclock/kd.c | 42 +++++---- hwclock/rtc.c | 254 ++++++++++++++++++++++++++++++------------------------ 4 files changed, 232 insertions(+), 160 deletions(-) (limited to 'hwclock') diff --git a/hwclock/hwclock.8 b/hwclock/hwclock.8 index 07c4f8cd..d8cf5b03 100644 --- a/hwclock/hwclock.8 +++ b/hwclock/hwclock.8 @@ -20,7 +20,8 @@ hwclock \- query and set the hardware clock (RTC) .PP other options: .PP -.B "[\-u|\-\-utc] \-\-localtime \-\-directisa \-\-test \-\-debug" +.B "[\-u|\-\-utc] \-\-localtime \-\-noadjfile \-\-directisa" +.B "\-\-test [\-D|\-\-debug]" .PP and arcane options for DEC Alpha: .PP @@ -28,9 +29,7 @@ and arcane options for DEC Alpha: .PP Minimum unique abbreviations of all options are acceptable. .PP -Also, equivalent options \-r, \-w, \-s, \-a, \-v, \-u, -\-D, \-A, \-J, \-S, and \-F are accepted for compatibility -with the program "clock", while \-h asks for a help message. +Also, \-h asks for a help message. .SH DESCRIPTION .B hwclock @@ -171,6 +170,17 @@ or options), as recorded in the adjtime file. If the adjtime file doesn't exist, the default is local time. +.TP +.B \-\-noadjfile +disables the facilities provided by +.IR /etc/adjtime . +.B hwclock +will not read nor write to that file with this option. Either +.B \-\-utc +or +.B \-\-localtime +must be specified when using this option. + .TP .B \-\-directisa is meaningful only on an ISA machine or an Alpha (which implements enough diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c index 3a3a94e1..ba6bc77c 100644 --- a/hwclock/hwclock.c +++ b/hwclock/hwclock.c @@ -259,6 +259,7 @@ read_adjtime(struct adjtime *adjtime_p, int *rc_p) { char line1[81]; /* String: first line of adjtime file */ char line2[81]; /* String: second line of adjtime file */ char line3[81]; /* String: third line of adjtime file */ + long timeval; line1[0] = '\0'; /* In case fgets fails */ fgets(line1, sizeof(line1), adjfile); @@ -274,13 +275,16 @@ read_adjtime(struct adjtime *adjtime_p, int *rc_p) { adjtime_p->last_adj_time = 0; adjtime_p->not_adjusted = 0; adjtime_p->last_calib_time = 0; + timeval = 0; - sscanf(line1, "%f %d %f", + sscanf(line1, "%f %ld %f", &adjtime_p->drift_factor, - (int *) &adjtime_p->last_adj_time, + &timeval, &adjtime_p->not_adjusted); - - sscanf(line2, "%d", (int *) &adjtime_p->last_calib_time); + adjtime_p->last_adj_time = timeval; + + sscanf(line2, "%ld", &timeval); + adjtime_p->last_calib_time = timeval; if (!strcmp(line3, "UTC\n")) adjtime_p->local_utc = UTC; @@ -300,10 +304,10 @@ read_adjtime(struct adjtime *adjtime_p, int *rc_p) { adjtime_p->dirty = FALSE; if (debug) { - printf(_("Last drift adjustment done at %d seconds after 1969\n"), - (int) adjtime_p->last_adj_time); - printf(_("Last calibration done at %d seconds after 1969\n"), - (int) adjtime_p->last_calib_time); + printf(_("Last drift adjustment done at %ld seconds after 1969\n"), + (long) adjtime_p->last_adj_time); + printf(_("Last calibration done at %ld seconds after 1969\n"), + (long) adjtime_p->last_calib_time); printf(_("Hardware clock is on %s time\n"), (adjtime_p->local_utc == LOCAL) ? _("local") : (adjtime_p->local_utc == UTC) ? _("UTC") : _("unknown")); @@ -447,9 +451,9 @@ set_hardware_clock(const time_t newtime, if (debug) printf(_("Setting Hardware Clock to %.2d:%.2d:%.2d " - "= %d seconds since 1969\n"), + "= %ld seconds since 1969\n"), new_broken_time.tm_hour, new_broken_time.tm_min, - new_broken_time.tm_sec, (int) newtime); + new_broken_time.tm_sec, (long) newtime); if (testing) printf(_("Clock not changed - testing only.\n")); @@ -597,8 +601,8 @@ interpret_date_string(const char *date_opt, time_t * const time_p) { MYNAME, date_command, date_resp); retcode = 8; } else { - int seconds_since_epoch; - rc = sscanf(date_resp + sizeof(magic)-1, "%d", &seconds_since_epoch); + long seconds_since_epoch; + rc = sscanf(date_resp + sizeof(magic)-1, "%ld", &seconds_since_epoch); if (rc < 1) { fprintf(stderr, _("The date command issued by %s returned " "something other than an integer where the converted " @@ -610,8 +614,8 @@ interpret_date_string(const char *date_opt, time_t * const time_p) { retcode = 0; *time_p = seconds_since_epoch; if (debug) - printf(_("date string %s equates to %d seconds since 1969.\n"), - date_opt, (int) *time_p); + printf(_("date string %s equates to %ld seconds since 1969.\n"), + date_opt, (long) *time_p); } } fclose(date_child_fp); @@ -719,7 +723,7 @@ adjust_drift_factor(struct adjtime *adjtime_p, if (debug) printf(_("Not adjusting drift factor because it has been less than a " "day since the last calibration.\n")); - } else { + } else if (adjtime_p->last_calib_time != 0) { const float factor_adjust = ((float) (nowtime - hclocktime) / (hclocktime - adjtime_p->last_calib_time)) @@ -931,7 +935,7 @@ determine_clock_access_method(const bool user_requests_ISA) { } static void -manipulate_clock(const bool show, const bool adjust, +manipulate_clock(const bool show, const bool adjust, const bool noadjfile, const bool set, const time_t set_time, const bool hctosys, const bool systohc, const struct timeval startup_time, @@ -953,7 +957,7 @@ manipulate_clock(const bool show, const bool adjust, if (no_auth) *retcode_p = 1; else { - if (adjust || set || systohc || (!utc && !local_opt)) + if (!noadjfile && (adjust || set || systohc || (!utc && !local_opt))) read_adjtime(&adjtime, &rc); else { /* A little trick to avoid reading the file if we don't have to */ @@ -1025,7 +1029,9 @@ manipulate_clock(const bool show, const bool adjust, *retcode_p = 1; } else *retcode_p = 0; } - save_adjtime(adjtime, testing); + if (!noadjfile) { + save_adjtime(adjtime, testing); + } } } } @@ -1121,6 +1127,8 @@ usage( const char *fmt, ... ) { " --date specifies the time to which to set the hardware clock\n" " --epoch=year specifies the year which is the beginning of the \n" " hardware clock's epoch value\n" + " --noadjfile do not access /etc/adjtime. Requires the use of\n" + " either --utc or --localtime\n" ),RTC_DEV); #ifdef __alpha__ fprintf( usageto, _( @@ -1160,7 +1168,7 @@ main(int argc, char **argv) { may be modified after parsing is complete to effect an implied option. */ bool help, show, set, systohc, hctosys, adjust, getepoch, setepoch, version; - bool ARCconsole, utc, testing, directisa, Jensen, SRM, funky_toy; + bool ARCconsole, utc, testing, directisa, Jensen, SRM, funky_toy, noadjfile; bool local_opt; char *date_opt; @@ -1173,6 +1181,7 @@ main(int argc, char **argv) { { 0, (char *) "getepoch", OPT_FLAG, &getepoch, 0 }, { 0, (char *) "setepoch", OPT_FLAG, &setepoch, 0 }, { 'a', (char *) "adjust", OPT_FLAG, &adjust, 0 }, + { 0, (char *) "noadjfile", OPT_FLAG, &noadjfile, 0 }, { 'v', (char *) "version", OPT_FLAG, &version, 0 }, { 'V', (char *) "version", OPT_FLAG, &version, 0 }, { 0, (char *) "date", OPT_STRING, &date_opt, 0 }, @@ -1185,8 +1194,11 @@ main(int argc, char **argv) { { 'D', (char *) "debug", OPT_FLAG, &debug, 0 }, #ifdef __alpha__ { 'A', (char *) "ARC", OPT_FLAG, &ARCconsole,0 }, + { 'A', (char *) "arc", OPT_FLAG, &ARCconsole,0 }, { 'J', (char *) "Jensen", OPT_FLAG, &Jensen, 0 }, + { 'J', (char *) "jensen", OPT_FLAG, &Jensen, 0 }, { 'S', (char *) "SRM", OPT_FLAG, &SRM, 0 }, + { 'S', (char *) "srm", OPT_FLAG, &SRM, 0 }, { 'F', (char *) "funky-toy", OPT_FLAG, &funky_toy, 0 }, #endif { 0, (char *) NULL, OPT_END, NULL, 0 } @@ -1207,17 +1219,18 @@ main(int argc, char **argv) { textdomain(PACKAGE); /* set option defaults */ - help = show = set = systohc = hctosys = adjust = getepoch = setepoch = - version = utc = local_opt = ARCconsole = SRM = funky_toy = - directisa = badyear = Jensen = testing = debug = FALSE; + help = show = set = systohc = hctosys = adjust = noadjfile = + getepoch = setepoch = version = utc = local_opt = + ARCconsole = SRM = funky_toy = directisa = badyear = Jensen = + testing = debug = FALSE; date_opt = NULL; argc_parse = argc; argv_parse = argv; optParseOptions(&argc_parse, argv_parse, option_def, 0); /* Uses and sets argc_parse, argv_parse. Sets show, systohc, hctosys, adjust, utc, local_opt, version, - testing, debug, set, date_opt, getepoch, setepoch, epoch_option - */ + testing, debug, set, date_opt, getepoch, setepoch, epoch_option, + noadjtime */ /* This is an ugly routine - for example, if I give an incorrect option, it only says "unrecognized option" without telling me what options are recognized. Rewrite with standard @@ -1245,6 +1258,18 @@ main(int argc, char **argv) { exit(100); } + if (adjust && noadjfile) { + fprintf(stderr, _("%s: The --adjust and --noadjfile options are mutually " + "exclusive. You specified both.\n"), MYNAME); + exit(100); + } + + if (noadjfile && !(utc || local_opt)) { + fprintf(stderr, _("%s: With --noadjfile, you must specify either " + "--utc or --localtime\n"), MYNAME); + exit(100); + } + #ifdef __alpha__ set_cmos_epoch(ARCconsole, SRM); set_cmos_access(Jensen, funky_toy); @@ -1302,8 +1327,9 @@ main(int argc, char **argv) { _("Use the --debug option to see the details of our " "search for an access method.\n")); } else - manipulate_clock(show, adjust, set, set_time, hctosys, systohc, - startup_time, utc, local_opt, testing, &rc); + manipulate_clock(show, adjust, noadjfile, set, set_time, + hctosys, systohc, startup_time, utc, local_opt, + testing, &rc); } } exit(retcode); diff --git a/hwclock/kd.c b/hwclock/kd.c index a2f313f6..f3327e1c 100644 --- a/hwclock/kd.c +++ b/hwclock/kd.c @@ -9,6 +9,7 @@ static int con_fd = -1; /* opened by probe_for_kd_clock() */ /* never closed */ +static char *con_fd_filename; /* usually "/dev/tty1" */ /* Get defines for KDGHWCLK and KDSHWCLK (m68k) */ #include @@ -88,7 +89,7 @@ read_hardware_clock_kd(struct tm *tm) { struct hwclk_time t; if (ioctl(con_fd, KDGHWCLK, &t) == -1) { - outsyserr(_("ioctl() failed to read time from /dev/tty1")); + outsyserr(_("ioctl() failed to read time from %s"), con_fd_filename); exit(5); } @@ -146,22 +147,29 @@ static struct clock_ops kd = { /* return &kd if KDGHWCLK works, NULL otherwise */ struct clock_ops * probe_for_kd_clock() { - struct clock_ops *ret = NULL; - struct hwclk_time t; - - if (con_fd < 0) - con_fd = open("/dev/tty1", O_RDONLY); - if (con_fd >= 0) { - if (ioctl( con_fd, KDGHWCLK, &t ) == -1) { - if (errno != EINVAL) - outsyserr(_("KDGHWCLK ioctl failed")); - } else - ret = &kd; - } else { - /* probably KDGHWCLK exists on m68k only */ + struct clock_ops *ret = NULL; + struct hwclk_time t; + + if (con_fd < 0) { /* first time here */ + con_fd_filename = "/dev/tty1"; + con_fd = open(con_fd_filename, O_RDONLY); + } + if (con_fd < 0) { + /* perhaps they are using devfs? */ + con_fd_filename = "/dev/vc/1"; + con_fd = open(con_fd_filename, O_RDONLY); + } + if (con_fd < 0) { + /* probably KDGHWCLK exists on m68k only */ #ifdef __m68k__ - outsyserr(_("Can't open /dev/tty1")); + outsyserr(_("Can't open /dev/tty1 or /dev/vc/1")); #endif - } - return ret; + } else { + if (ioctl(con_fd, KDGHWCLK, &t) == -1) { + if (errno != EINVAL) + outsyserr(_("KDGHWCLK ioctl failed")); + } else + ret = &kd; + } + return ret; } diff --git a/hwclock/rtc.c b/hwclock/rtc.c index 06ac4360..2694d866 100644 --- a/hwclock/rtc.c +++ b/hwclock/rtc.c @@ -18,13 +18,6 @@ * used a struct rtc_time different from that used in mc146818rtc.h. */ -/* ia64 uses /dev/efirtc (char 10,136) */ -#if __ia64__ -#define RTC_DEV "/dev/efirtc" -#else -#define RTC_DEV "/dev/rtc" -#endif - /* On Sparcs, there is a that defines different ioctls (that are required on my machine). However, this include file does not exist on other architectures. */ @@ -87,38 +80,67 @@ struct linux_rtc_time { #endif +/* ia64 uses /dev/efirtc (char 10,136) */ +/* devfs uses /dev/misc/rtc */ +#if __ia64__ +#define RTC_DEVN "efirtc" +#else +#define RTC_DEVN "rtc" +#endif + +static char rtc_dev_name[40]; + +/* maybe we should not try /dev/misc/efirtc? + maybe we should reset rtc_dev_name to give better error messages */ +static int +open_rtc(void) { + int rtc_fd; + + sprintf(rtc_dev_name, "/dev/%s", RTC_DEVN); + rtc_fd = open(rtc_dev_name, O_RDONLY); + if (rtc_fd < 0) { + sprintf(rtc_dev_name, "/dev/misc/%s", RTC_DEVN); + rtc_fd = open(rtc_dev_name, O_RDONLY); + } + return rtc_fd; +} + static int do_rtc_read_ioctl(int rtc_fd, struct tm *tm) { - int rc; - char *ioctlname; -#ifdef __sparc__ - struct sparc_rtc_time stm; + int rc = -1; + char *ioctlname; - ioctlname = "RTCGET"; - rc = ioctl(rtc_fd, RTCGET, &stm); -#else - ioctlname = "RTC_RD_TIME"; - rc = ioctl(rtc_fd, RTC_RD_TIME, tm); -#endif - if (rc == -1) { - perror(ioctlname); - fprintf(stderr, _("ioctl() to %s to read the time failed.\n"),RTC_DEV); - exit(5); - } #ifdef __sparc__ - tm->tm_sec = stm.sec; - tm->tm_min = stm.min; - tm->tm_hour = stm.hour; - tm->tm_mday = stm.dom; - tm->tm_mon = stm.month - 1; - tm->tm_year = stm.year - 1900; - tm->tm_wday = stm.dow - 1; - tm->tm_yday = -1; /* day in the year */ + /* some but not all sparcs use a different ioctl and struct */ + struct sparc_rtc_time stm; + + ioctlname = "RTCGET"; + rc = ioctl(rtc_fd, RTCGET, &stm); + if (rc == 0) { + tm->tm_sec = stm.sec; + tm->tm_min = stm.min; + tm->tm_hour = stm.hour; + tm->tm_mday = stm.dom; + tm->tm_mon = stm.month - 1; + tm->tm_year = stm.year - 1900; + tm->tm_wday = stm.dow - 1; + tm->tm_yday = -1; /* day in the year */ + } #endif - tm->tm_isdst = -1; /* don't know whether it's daylight */ - return 0; -} - + if (rc == -1) { /* no sparc, or RTCGET failed */ + ioctlname = "RTC_RD_TIME"; + rc = ioctl(rtc_fd, RTC_RD_TIME, tm); + } + if (rc == -1) { + perror(ioctlname); + fprintf(stderr, _("ioctl() to %s to read the time failed.\n"), + rtc_dev_name); + exit(5); + } + + tm->tm_isdst = -1; /* don't know whether it's dst */ + return 0; +} static int busywait_for_rtc_clock_tick(const int rtc_fd) { @@ -133,7 +155,8 @@ busywait_for_rtc_clock_tick(const int rtc_fd) { int rc; if (debug) - printf(_("Waiting in loop for time from %s to change\n"),RTC_DEV); + printf(_("Waiting in loop for time from %s to change\n"), + rtc_dev_name); rc = do_rtc_read_ioctl(rtc_fd, &start_time); if (rc) @@ -167,9 +190,9 @@ synchronize_to_clock_tick_rtc(void) { int rtc_fd; /* File descriptor of /dev/rtc */ int ret; - rtc_fd = open(RTC_DEV,O_RDONLY); + rtc_fd = open(rtc_dev_name, O_RDONLY); if (rtc_fd == -1) { - outsyserr(_("open() of %s failed"),RTC_DEV); + outsyserr(_("open() of %s failed"), rtc_dev_name); ret = 1; } else { int rc; /* Return code from ioctl */ @@ -187,7 +210,8 @@ int ret; kernel for the system clock, so aren't at the user's disposal. */ if (debug) - printf(_("%s does not have interrupt functions. "),RTC_DEV); + printf(_("%s does not have interrupt functions. "), + rtc_dev_name); ret = busywait_for_rtc_clock_tick(rtc_fd); } else if (rc == 0) { unsigned long dummy; @@ -195,7 +219,8 @@ int ret; /* this blocks until the next update interrupt */ rc = read(rtc_fd, &dummy, sizeof(dummy)); if (rc == -1) { - outsyserr(_("read() to %s to wait for clock tick failed"),RTC_DEV); + outsyserr(_("read() to %s to wait for clock tick failed"), + rtc_dev_name); ret = 1; } else { ret = 0; @@ -203,11 +228,11 @@ int ret; /* Turn off update interrupts */ rc = ioctl(rtc_fd, RTC_UIE_OFF, 0); if (rc == -1) - outsyserr(_("ioctl() to %s to turn off update interrupts " - "failed"),RTC_DEV); + outsyserr(_("ioctl() to %s to turn off update interrupts failed"), + rtc_dev_name); } else { outsyserr(_("ioctl() to %s to turn on update interrupts " - "failed unexpectedly"),RTC_DEV); + "failed unexpectedly"), rtc_dev_name); ret = 1; } close(rtc_fd); @@ -218,69 +243,70 @@ int ret; static int read_hardware_clock_rtc(struct tm *tm) { -/*---------------------------------------------------------------------------- - Read the hardware clock and return the current time via - argument. Use ioctls to "rtc" device /dev/rtc. ------------------------------------------------------------------------------*/ - int rtc_fd; /* File descriptor of /dev/rtc */ + int rtc_fd; - rtc_fd = open(RTC_DEV,O_RDONLY); - if (rtc_fd == -1) { - outsyserr(_("open() of %s failed"),RTC_DEV); - exit(5); - } + rtc_fd = open_rtc(); + if (rtc_fd == -1) { + outsyserr(_("open() of %s failed"), rtc_dev_name); + exit(5); + } - /* Read the RTC time/date */ - do_rtc_read_ioctl(rtc_fd, tm); + /* Read the RTC time/date, return answer via tm */ + do_rtc_read_ioctl(rtc_fd, tm); - close(rtc_fd); - return 0; + close(rtc_fd); + return 0; } static int set_hardware_clock_rtc(const struct tm *new_broken_time) { -/*---------------------------------------------------------------------------- +/*------------------------------------------------------------------------- Set the Hardware Clock to the broken down time . Use ioctls to "rtc" device /dev/rtc. -----------------------------------------------------------------------------*/ - int rc; - int rtc_fd; - - rtc_fd = open(RTC_DEV, O_RDONLY); - if (rtc_fd < 0) { - outsyserr(_("Unable to open %s"),RTC_DEV); - exit(5); - } else { - char *ioctlname; + -------------------------------------------------------------------------*/ + int rc = -1; + int rtc_fd; + char *ioctlname; + + rtc_fd = open_rtc(); + if (rtc_fd < 0) { + outsyserr(_("Unable to open %s"), rtc_dev_name); + exit(5); + } #ifdef __sparc__ - struct sparc_rtc_time stm; - - stm.sec = new_broken_time->tm_sec; - stm.min = new_broken_time->tm_min; - stm.hour = new_broken_time->tm_hour; - stm.dom = new_broken_time->tm_mday; - stm.month = new_broken_time->tm_mon + 1; - stm.year = new_broken_time->tm_year + 1900; - stm.dow = new_broken_time->tm_wday + 1; - - ioctlname = "RTCSET"; - rc = ioctl(rtc_fd, RTCSET, &stm); -#else - ioctlname = "RTC_SET_TIME"; - rc = ioctl(rtc_fd, RTC_SET_TIME, new_broken_time); + { + struct sparc_rtc_time stm; + + stm.sec = new_broken_time->tm_sec; + stm.min = new_broken_time->tm_min; + stm.hour = new_broken_time->tm_hour; + stm.dom = new_broken_time->tm_mday; + stm.month = new_broken_time->tm_mon + 1; + stm.year = new_broken_time->tm_year + 1900; + stm.dow = new_broken_time->tm_wday + 1; + + ioctlname = "RTCSET"; + rc = ioctl(rtc_fd, RTCSET, &stm); + } #endif - if (rc == -1) { - perror(ioctlname); - fprintf(stderr, _("ioctl() to %s to set the time failed.\n"),RTC_DEV); - exit(5); - } else { - if (debug) - printf(_("ioctl(%s) was successful.\n"), ioctlname); - } - close(rtc_fd); - } - return 0; + if (rc == -1) { /* no sparc, or RTCSET failed */ + ioctlname = "RTC_SET_TIME"; + rc = ioctl(rtc_fd, RTC_SET_TIME, new_broken_time); + } + + if (rc == -1) { + perror(ioctlname); + fprintf(stderr, _("ioctl() to %s to set the time failed.\n"), + rtc_dev_name); + exit(5); + } + + if (debug) + printf(_("ioctl(%s) was successful.\n"), ioctlname); + + close(rtc_fd); + return 0; } @@ -290,7 +316,7 @@ get_permissions_rtc(void) { } static struct clock_ops rtc = { - RTC_DEV " interface to clock", + "/dev/" RTC_DEVN " interface to clock", get_permissions_rtc, read_hardware_clock_rtc, set_hardware_clock_rtc, @@ -300,14 +326,14 @@ static struct clock_ops rtc = { /* return &rtc if /dev/rtc can be opened, NULL otherwise */ struct clock_ops * probe_for_rtc_clock(){ - int rtc_fd = open(RTC_DEV, O_RDONLY); - if (rtc_fd > 0) { - close(rtc_fd); - return &rtc; - } - if (debug) - outsyserr(_("Open of %s failed"),RTC_DEV); - return NULL; + int rtc_fd = open_rtc(); + if (rtc_fd > 0) { + close(rtc_fd); + return &rtc; + } + if (debug) + outsyserr(_("Open of %s failed"), rtc_dev_name); + return NULL; } @@ -319,30 +345,31 @@ get_epoch_rtc(unsigned long *epoch_p, int silent) { ----------------------------------------------------------------------------*/ int rtc_fd; - rtc_fd = open(RTC_DEV, O_RDONLY); + rtc_fd = open_rtc(); if (rtc_fd < 0) { if (!silent) { if (errno == ENOENT) fprintf(stderr, _( "To manipulate the epoch value in the kernel, we must " "access the Linux 'rtc' device driver via the device special " - "file %s. This file does not exist on this system.\n"),RTC_DEV); + "file %s. This file does not exist on this system.\n"), + rtc_dev_name); else - outsyserr(_("Unable to open %s"),RTC_DEV); + outsyserr(_("Unable to open %s"), rtc_dev_name); } return 1; } if (ioctl(rtc_fd, RTC_EPOCH_READ, epoch_p) == -1) { if (!silent) - outsyserr(_("ioctl(RTC_EPOCH_READ) to %s failed"),RTC_DEV); + outsyserr(_("ioctl(RTC_EPOCH_READ) to %s failed"), rtc_dev_name); close(rtc_fd); return 1; } if (debug) printf(_("we have read epoch %ld from %s " - "with RTC_EPOCH_READ ioctl.\n"), *epoch_p,RTC_DEV); + "with RTC_EPOCH_READ ioctl.\n"), *epoch_p, rtc_dev_name); close(rtc_fd); return 0; @@ -366,27 +393,28 @@ set_epoch_rtc(unsigned long epoch) { return 1; } - rtc_fd = open(RTC_DEV, O_RDONLY); + rtc_fd = open_rtc(); if (rtc_fd < 0) { if (errno == ENOENT) fprintf(stderr, _("To manipulate the epoch value in the kernel, we must " "access the Linux 'rtc' device driver via the device special " - "file %s. This file does not exist on this system.\n"),RTC_DEV); + "file %s. This file does not exist on this system.\n"), + rtc_dev_name); else - outsyserr(_("Unable to open %s"),RTC_DEV); + outsyserr(_("Unable to open %s"), rtc_dev_name); return 1; } if (debug) printf(_("setting epoch to %ld " - "with RTC_EPOCH_SET ioctl to %s.\n"), epoch, RTC_DEV); + "with RTC_EPOCH_SET ioctl to %s.\n"), epoch, rtc_dev_name); if (ioctl(rtc_fd, RTC_EPOCH_SET, epoch) == -1) { if (errno == EINVAL) fprintf(stderr, _("The kernel device driver for %s " - "does not have the RTC_EPOCH_SET ioctl.\n"),RTC_DEV); + "does not have the RTC_EPOCH_SET ioctl.\n"), rtc_dev_name); else - outsyserr(_("ioctl(RTC_EPOCH_SET) to %s failed"),RTC_DEV); + outsyserr(_("ioctl(RTC_EPOCH_SET) to %s failed"), rtc_dev_name); close(rtc_fd); return 1; } -- cgit v1.2.3