static int open_rtc_or_exit(const struct hwclock_control *ctl) { int rtc_fd = open_rtc(ctl); if (rtc_fd < 0) { warn(_("cannot open rtc device")); hwclock_exit(ctl, EXIT_FAILURE); } return rtc_fd; }
static int open_rtc_or_exit(void) { int rtc_fd = open_rtc(); if (rtc_fd < 0) { warn(_("cannot open %s"), rtc_dev_name); hwclock_exit(EX_OSFILE); } return rtc_fd; }
static int open_rtc_or_exit(void) { int rtc_fd = open_rtc(); if (rtc_fd < 0) { outsyserr(_("open() of %s failed"), rtc_dev_name); hwclock_exit(EX_OSFILE); } return rtc_fd; }
static int set_hardware_clock_rtc(const struct tm *new_broken_time) { /*------------------------------------------------------------------------- Set the Hardware Clock to the broken down time <new_broken_time>. Use ioctls to "rtc" device /dev/rtc. -------------------------------------------------------------------------*/ int rc = -1; int rtc_fd; char *ioctlname; rtc_fd = open_rtc_or_exit(); #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); } #endif 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); hwclock_exit(EX_IOERR); } if (debug) printf(_("ioctl(%s) was successful.\n"), ioctlname); return 0; }
/* * Set the Hardware Clock to the time <new_broken_time>. Use ioctls to * /dev/tty1 on what we assume is an m68k machine. * * Note that we don't use /dev/console here. That might be a serial console. */ static int set_hardware_clock_kd(const struct tm *new_broken_time) { struct hwclk_time t; t.sec = new_broken_time->tm_sec; t.min = new_broken_time->tm_min; t.hour = new_broken_time->tm_hour; t.day = new_broken_time->tm_mday; t.mon = new_broken_time->tm_mon; t.year = new_broken_time->tm_year; t.wday = new_broken_time->tm_wday; if (ioctl(con_fd, KDSHWCLK, &t) == -1) { warn(_("ioctl KDSHWCLK failed")); hwclock_exit(EX_IOERR); } return 0; }
/* * Read the hardware clock and return the current time via <tm> argument. * Use ioctls to /dev/tty1 on what we assume is an m68k machine. * * Note that we don't use /dev/console here. That might be a serial console. */ static int read_hardware_clock_kd(struct tm *tm) { struct hwclk_time t; if (ioctl(con_fd, KDGHWCLK, &t) == -1) { warn(_("ioctl() failed to read time from %s"), con_fd_filename); hwclock_exit(EX_IOERR); } tm->tm_sec = t.sec; tm->tm_min = t.min; tm->tm_hour = t.hour; tm->tm_mday = t.day; tm->tm_mon = t.mon; tm->tm_year = t.year; tm->tm_wday = t.wday; tm->tm_isdst = -1; /* Don't know if it's Daylight Savings Time */ return 0; }
/* * Set the Hardware Clock to the broken down time <new_broken_time>. Use * ioctls to "rtc" device /dev/rtc. */ static int set_hardware_clock_rtc(const struct hwclock_control *ctl, const struct tm *new_broken_time) { int rc = -1; int rtc_fd; char *ioctlname; rtc_fd = open_rtc_or_exit(ctl); ioctlname = "RTC_SET_TIME"; rc = ioctl(rtc_fd, RTC_SET_TIME, new_broken_time); #ifdef __sparc__ if (rc == -1) { /* sparc sbus */ 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) { warn(_("ioctl(%s) to %s to set the time failed"), ioctlname, rtc_dev_name); hwclock_exit(ctl, EXIT_FAILURE); } if (ctl->verbose) printf(_("ioctl(%s) was successful.\n"), ioctlname); return 0; }