]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: use libc error printing functions
authorSami Kerola <kerolasa@iki.fi>
Sun, 24 Jul 2011 18:30:29 +0000 (20:30 +0200)
committerSami Kerola <kerolasa@iki.fi>
Tue, 26 Jul 2011 15:54:30 +0000 (17:54 +0200)
In addition numeric exit values are converted to defined strings.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
hwclock/clock.h
hwclock/cmos.c
hwclock/hwclock.c
hwclock/kd.c
hwclock/rtc.c

index 8d1befe8f9cdad911b4faa98c2b5a0bd55c42c59..363541bbdd34edb2fb2ec595d83ea207dbfcfb3f 100644 (file)
@@ -27,12 +27,6 @@ typedef int bool;
 extern char *progname;
 extern int debug;
 extern int epoch_option;
-extern void outsyserr(char *msg, ...)
-#ifdef __GNUC__
-    __attribute__ ((format(printf, 1, 2)));
-#else
-    ;
-#endif
 extern double time_diff(struct timeval subtrahend, struct timeval subtractor);
 /* cmos.c */
 extern void set_cmos_epoch(int ARCconsole, int SRM);
index 8c4ccbe0d908189796fb01c2c9ed4a3e1b059f6a..89bcc50f9a47034593363e0d13d2c4e24434050c 100644 (file)
@@ -287,9 +287,8 @@ atomic(const char *name, unsigned long (*op) (unsigned long), unsigned long arg)
                        return v;
                }
        }
-       fprintf(stderr, _("%s: atomic %s failed for 1000 iterations!"),
-               progname, name);
-       exit(1);
+       errx(EXIT_FAILURE, _("atomic %s failed for 1000 iterations!"),
+               name);
 }
 #else
 
@@ -626,26 +625,20 @@ static int get_permissions_cmos(void)
        if (use_dev_port) {
                if ((dev_port_fd = open("/dev/port", O_RDWR)) < 0) {
                        int errsv = errno;
-                       fprintf(stderr, _("Cannot open /dev/port: %s"),
-                               strerror(errsv));
+                       warn(_("Cannot open /dev/port"));
                        rc = 1;
                } else
                        rc = 0;
        } else {
                rc = i386_iopl(3);
                if (rc == -2) {
-                       fprintf(stderr,
-                               _
-                               ("I failed to get permission because I didn't try.\n"));
+                       warnx(_("I failed to get permission because I didn't try."));
                } else if (rc != 0) {
                        rc = errno;
-                       fprintf(stderr,
-                               _("%s is unable to get I/O port access:  "
-                                 "the iopl(3) call failed.\n"), progname);
+                       warn(_("unable to get I/O port access:  "
+                               "the iopl(3) call failed."));
                        if (rc == EPERM && geteuid())
-                               fprintf(stderr,
-                                       _
-                                       ("Probably you need root privileges.\n"));
+                               warnx(_("Probably you need root privileges.\n"));
                }
        }
        return rc ? 1 : 0;
index 3211b8f8ea77c11c322dc33d9c57b496c4ab3de5..88281f4484e21fd44b8c9d52ec28305f3f8dd731 100644 (file)
@@ -79,10 +79,6 @@ static int hwaudit_fd = -1;
 static int hwaudit_on;
 #endif
 
-#define MYNAME "hwclock"
-
-char *progname = MYNAME;
-
 /* The struct that holds our hardware access routines */
 struct clock_ops *ur;
 
@@ -157,7 +153,7 @@ static void write_date_to_file(struct tm *tm)
                        tm->tm_year + 1900);
                fclose(fp);
        } else
-               perror(LASTDATE);
+               warn(_("cannot write %s"), LASTDATE);
 }
 
 static void read_date_from_file(struct tm *tm)
@@ -265,7 +261,7 @@ static int read_adjtime(struct adjtime *adjtime_p)
 
        adjfile = fopen(adj_file_name, "r");    /* open file for reading */
        if (adjfile == NULL) {
-               outsyserr("cannot open file %s", adj_file_name);
+               warn("cannot open file %s", adj_file_name);
                return EX_OSFILE;
        }
 
@@ -301,11 +297,8 @@ static int read_adjtime(struct adjtime *adjtime_p)
        } else {
                adjtime_p->local_utc = UNKNOWN;
                if (line3[0]) {
-                       fprintf(stderr,
-                               _("%s: Warning: unrecognized third line in adjtime file\n"),
-                               MYNAME);
-                       fprintf(stderr,
-                               _("(Expected: `UTC' or `LOCAL' or nothing.)\n"));
+                       warnx(_("Warning: unrecognized third line in adjtime file\n"
+                               "(Expected: `UTC' or `LOCAL' or nothing.)"));
                }
        }
 
@@ -570,11 +563,10 @@ display_time(const bool hclock_valid, const time_t systime,
             const double sync_duration)
 {
        if (!hclock_valid)
-               fprintf(stderr,
-                       _
-                       ("The Hardware Clock registers contain values that are "
-                        "either invalid (e.g. 50th day of month) or beyond the range "
-                        "we can handle (e.g. Year 2095).\n"));
+               warnx(_
+                     ("The Hardware Clock registers contain values that are "
+                      "either invalid (e.g. 50th day of month) or beyond the range "
+                      "we can handle (e.g. Year 2095)."));
        else {
                struct tm *lt;
                char *format = "%c";
@@ -613,22 +605,21 @@ static int interpret_date_string(const char *date_opt, time_t * const time_p)
        int rc;                 /* local return code */
 
        if (date_opt == NULL) {
-               fprintf(stderr, _("No --date option specified.\n"));
+               warnx(_("No --date option specified."));
                return 14;
        }
 
        /* prevent overflow - a security risk */
        if (strlen(date_opt) > sizeof(date_command) - 50) {
-               fprintf(stderr, _("--date argument too long\n"));
+               warnx(_("--date argument too long"));
                return 13;
        }
 
        /* Quotes in date_opt would ruin the date command we construct. */
        if (strchr(date_opt, '"') != NULL) {
-               fprintf(stderr,
-                       _
-                       ("The value of the --date option is not a valid date.\n"
-                        "In particular, it contains quotation marks.\n"));
+               warnx(_
+                     ("The value of the --date option is not a valid date.\n"
+                      "In particular, it contains quotation marks."));
                return 12;
        }
 
@@ -639,7 +630,7 @@ static int interpret_date_string(const char *date_opt, time_t * const time_p)
 
        date_child_fp = popen(date_command, "r");
        if (date_child_fp == NULL) {
-               outsyserr(_("Unable to run 'date' program in /bin/sh shell. "
+               warn(_("Unable to run 'date' program in /bin/sh shell. "
                            "popen() failed"));
                return 10;
        }
@@ -649,24 +640,24 @@ static int interpret_date_string(const char *date_opt, time_t * const time_p)
        if (debug)
                printf(_("response from date command = %s\n"), date_resp);
        if (strncmp(date_resp, magic, sizeof(magic) - 1) != 0) {
-               fprintf(stderr, _("The date command issued by %s returned "
+               warnx(_("The date command issued by %s returned "
                                  "unexpected results.\n"
                                  "The command was:\n  %s\n"
-                                 "The response was:\n  %s\n"),
-                       MYNAME, date_command, date_resp);
+                                 "The response was:\n  %s"),
+                       program_invocation_short_name, date_command, date_resp);
                retcode = 8;
        } else {
                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 time value was expected.\n"
-                                 "The command was:\n  %s\n"
-                                 "The response was:\n %s\n"),
-                               MYNAME, date_command, date_resp);
+                       warnx(_("The date command issued by %s returned "
+                               "something other than an integer where the "
+                               "converted time value was expected.\n"
+                               "The command was:\n  %s\n"
+                               "The response was:\n %s\n"),
+                             program_invocation_short_name, date_command,
+                             date_resp);
                        retcode = 6;
                } else {
                        retcode = 0;
@@ -703,10 +694,9 @@ set_system_clock(const bool hclock_valid, const time_t newtime,
        int retcode;
 
        if (!hclock_valid) {
-               fprintf(stderr,
-                       _
-                       ("The Hardware Clock does not contain a valid time, so "
-                        "we cannot set the System Time from it.\n"));
+               warnx(_
+                     ("The Hardware Clock does not contain a valid time, so "
+                      "we cannot set the System Time from it."));
                retcode = 1;
        } else {
                struct timeval tv;
@@ -742,12 +732,11 @@ set_system_clock(const bool hclock_valid, const time_t newtime,
                        rc = settimeofday(&tv, &tz);
                        if (rc) {
                                if (errno == EPERM) {
-                                       fprintf(stderr,
-                                               _
-                                               ("Must be superuser to set system clock.\n"));
+                                       warnx(_
+                                             ("Must be superuser to set system clock."));
                                        retcode = EX_NOPERM;
                                } else {
-                                       outsyserr(_("settimeofday() failed"));
+                                       warn(_("settimeofday() failed"));
                                        retcode = 1;
                                }
                        } else
@@ -825,12 +814,11 @@ static int set_system_clock_timezone(const bool universal, const bool testing)
                rc = settimeofday(&tv, &tz);
                if (rc) {
                        if (errno == EPERM) {
-                               fprintf(stderr,
-                                       _
-                                       ("Must be superuser to set system clock.\n"));
+                               warnx(_
+                                     ("Must be superuser to set system clock."));
                                retcode = EX_NOPERM;
                        } else {
-                               outsyserr(_("settimeofday() failed"));
+                               warn(_("settimeofday() failed"));
                                retcode = 1;
                        }
                } else
@@ -1005,31 +993,29 @@ static void save_adjtime(const struct adjtime adjtime, const bool testing)
 
                        adjfile = fopen(adj_file_name, "w");
                        if (adjfile == NULL) {
-                               outsyserr(_
-                                         ("Could not open file with the clock adjustment parameters "
-                                          "in it (%s) for writing"),
-                                         adj_file_name);
+                               warn(_
+                                    ("Could not open file with the clock adjustment parameters "
+                                     "in it (%s) for writing"), adj_file_name);
                                err = 1;
                        } else {
                                if (fputs(newfile, adjfile) < 0) {
-                                       outsyserr(_
-                                                 ("Could not update file with the clock adjustment "
-                                                  "parameters (%s) in it"),
-                                                 adj_file_name);
+                                       warn(_
+                                            ("Could not update file with the clock adjustment "
+                                             "parameters (%s) in it"),
+                                            adj_file_name);
                                        err = 1;
                                }
                                if (fclose(adjfile) < 0) {
-                                       outsyserr(_
-                                                 ("Could not update file with the clock adjustment "
-                                                  "parameters (%s) in it"),
-                                                 adj_file_name);
+                                       warn(_
+                                            ("Could not update file with the clock adjustment "
+                                             "parameters (%s) in it"),
+                                            adj_file_name);
                                        err = 1;
                                }
                        }
                        if (err)
-                               fprintf(stderr,
-                                       _
-                                       ("Drift adjustment parameters not updated.\n"));
+                               warnx(_
+                                     ("Drift adjustment parameters not updated."));
                }
        }
 }
@@ -1068,9 +1054,8 @@ do_adjustment(struct adjtime *adjtime_p,
              const bool universal, const bool testing)
 {
        if (!hclock_valid) {
-               fprintf(stderr,
-                       _("The Hardware Clock does not contain a valid time, "
-                         "so we cannot adjust it.\n"));
+               warnx(_("The Hardware Clock does not contain a valid time, "
+                       "so we cannot adjust it."));
                adjtime_p->last_calib_time = 0; /* calibration startover is required */
                adjtime_p->last_adj_time = 0;
                adjtime_p->not_adjusted = 0;
@@ -1304,28 +1289,25 @@ manipulate_epoch(const bool getepoch, const bool setepoch,
         * should be changed.
         */
 #ifndef __alpha__
-       fprintf(stderr,
-               _("The kernel keeps an epoch value for the Hardware Clock "
-                 "only on an Alpha machine.\nThis copy of hwclock was built for "
-                 "a machine other than Alpha\n(and thus is presumably not running "
-                 "on an Alpha now).  No action taken.\n"));
+       warnx(_("The kernel keeps an epoch value for the Hardware Clock "
+               "only on an Alpha machine.\nThis copy of hwclock was built for "
+               "a machine other than Alpha\n(and thus is presumably not running "
+               "on an Alpha now).  No action taken."));
 #else
        if (getepoch) {
                unsigned long epoch;
 
                if (get_epoch_rtc(&epoch, 0))
-                       fprintf(stderr,
-                               _
-                               ("Unable to get the epoch value from the kernel.\n"));
+                       warnx(_
+                             ("Unable to get the epoch value from the kernel."));
                else
                        printf(_("Kernel is assuming an epoch value of %lu\n"),
                               epoch);
        } else if (setepoch) {
                if (epoch_opt == -1)
-                       fprintf(stderr,
-                               _
-                               ("To set the epoch value, you must use the 'epoch' "
-                                "option to tell to what value to set it.\n"));
+                       warnx(_
+                             ("To set the epoch value, you must use the 'epoch' "
+                              "option to tell to what value to set it."));
                else if (testing)
                        printf(_
                               ("Not setting the epoch to %d - testing only.\n"),
@@ -1346,7 +1328,7 @@ manipulate_epoch(const bool getepoch, const bool setepoch,
 
 static void out_version(void)
 {
-       printf(_("%s from %s\n"), MYNAME, PACKAGE_STRING);
+       printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING);
 }
 
 /*
@@ -1408,7 +1390,7 @@ static void usage(const char *fmt, ...)
                           "\n"));
 #endif
 
-       fflush(stdout);
+       fflush(usageto);
        if (fmt) {
                usageto = stderr;
                va_start(ap, fmt);
@@ -1416,7 +1398,7 @@ static void usage(const char *fmt, ...)
                va_end(ap);
        }
 
-       hwclock_exit(fmt ? EX_USAGE : 0);
+       hwclock_exit(fmt ? EX_USAGE : EX_OK);
 }
 
 static const struct option longopts[] = {
@@ -1499,8 +1481,7 @@ int main(int argc, char **argv)
                 * You get these error codes only when the kernel doesn't
                 * have audit compiled in.
                 */
-               fprintf(stderr, _("%s: Unable to connect to audit system\n"),
-                       MYNAME);
+               warnx(_("Unable to connect to audit system"));
                return EX_NOPERM;
        }
 #endif
@@ -1630,43 +1611,40 @@ int main(int argc, char **argv)
 #endif
        if (argc > 0) {
                usage(_("%s takes no non-option arguments.  "
-                       "You supplied %d.\n"), MYNAME, argc);
+                       "You supplied %d.\n"), program_invocation_short_name,
+                     argc);
        }
 
        if (show + set + systohc + hctosys + systz + adjust + getepoch
            + setepoch + predict > 1) {
-               fprintf(stderr, _("You have specified multiple functions.\n"
-                                 "You can only perform one function "
-                                 "at a time.\n"));
+               warnx(_("You have specified multiple functions.\n"
+                       "You can only perform one function at a time."));
                hwclock_exit(EX_USAGE);
        }
 
        if (utc && local_opt) {
-               fprintf(stderr, _("%s: The --utc and --localtime options "
-                                 "are mutually exclusive.  You specified "
-                                 "both.\n"), MYNAME);
+               warnx(_("The --utc and --localtime options "
+                       "are mutually exclusive.  You specified both."));
                hwclock_exit(EX_USAGE);
        }
 
        if (adjust && noadjfile) {
-               fprintf(stderr, _("%s: The --adjust and --noadjfile options "
-                                 "are mutually exclusive.  You specified "
-                                 "both.\n"), MYNAME);
+               warnx(_("The --adjust and --noadjfile options "
+                       "are mutually exclusive.  You specified both."));
                hwclock_exit(EX_USAGE);
        }
 
        if (adj_file_name && noadjfile) {
-               fprintf(stderr, _("%s: The --adjfile and --noadjfile options "
-                                 "are mutually exclusive.  You specified "
-                                 "both.\n"), MYNAME);
+               warnx(_("The --adjfile and --noadjfile options "
+                       "are mutually exclusive.  You specified both."));
                hwclock_exit(EX_USAGE);
        }
        if (!adj_file_name)
                adj_file_name = ADJPATH;
 
        if (noadjfile && !(utc || local_opt)) {
-               fprintf(stderr, _("%s: With --noadjfile, you must specify "
-                                 "either --utc or --localtime\n"), MYNAME);
+               warnx(_("With --noadjfile, you must specify "
+                       "either --utc or --localtime"));
                hwclock_exit(EX_USAGE);
        }
 #ifdef __alpha__
@@ -1678,8 +1656,8 @@ int main(int argc, char **argv)
                rc = interpret_date_string(date_opt, &set_time);
                /* (time-consuming) */
                if (rc != 0) {
-                       fprintf(stderr, _("No usable set-to time.  "
-                                         "Cannot set clock.\n"));
+                       warnx(_("No usable set-to time.  "
+                               "Cannot set clock."));
                        hwclock_exit(EX_USAGE);
                }
        }
@@ -1693,19 +1671,16 @@ int main(int argc, char **argv)
        else {
                /* program is designed to run setuid (in some situations) */
                if (set || systohc || adjust) {
-                       fprintf(stderr,
-                               _("Sorry, only the superuser can change "
-                                 "the Hardware Clock.\n"));
+                       warnx(_("Sorry, only the superuser can change "
+                               "the Hardware Clock."));
                        permitted = FALSE;
                } else if (systz || hctosys) {
-                       fprintf(stderr,
-                               _("Sorry, only the superuser can change "
-                                 "the System Clock.\n"));
+                       warnx(_("Sorry, only the superuser can change "
+                               "the System Clock."));
                        permitted = FALSE;
                } else if (setepoch) {
-                       fprintf(stderr,
-                               _("Sorry, only the superuser can change the "
-                                 "Hardware Clock epoch in the kernel.\n"));
+                       warnx(_("Sorry, only the superuser can change the "
+                               "Hardware Clock epoch in the kernel."));
                        permitted = FALSE;
                } else
                        permitted = TRUE;
@@ -1717,24 +1692,23 @@ int main(int argc, char **argv)
 #ifdef __linux__
        if (getepoch || setepoch) {
                manipulate_epoch(getepoch, setepoch, epoch_option, testing);
-               hwclock_exit(0);
+               hwclock_exit(EX_OK);
        }
 #endif
 
        if (debug)
                out_version();
+
        if (!systz && !predict) {
                determine_clock_access_method(directisa);
                if (!ur) {
-                       fprintf(stderr,
-                               _("Cannot access the Hardware Clock via "
-                                 "any known method.\n"));
+                       warnx(_("Cannot access the Hardware Clock via "
+                               "any known method."));
                        if (!debug)
-                               fprintf(stderr,
-                                       _("Use the --debug option to see the "
-                                         "details of our search for an access "
-                                         "method.\n"));
-                       hwclock_exit(1);
+                               warnx(_("Use the --debug option to see the "
+                                       "details of our search for an access "
+                                       "method."));
+                       hwclock_exit(EX_SOFTWARE);
                }
        }
 
@@ -1745,21 +1719,12 @@ int main(int argc, char **argv)
        return rc;              /* Not reached */
 }
 
-/* A single routine for greater uniformity */
-void outsyserr(char *msg, ...)
-{
-       va_list args;
-       int errsv = errno;
-
-       fprintf(stderr, "%s: ", progname);
-       va_start(args, msg);
-       vfprintf(stderr, msg, args);
-       va_end(args);
-       fprintf(stderr, ", errno=%d: %s.\n", errsv, strerror(errsv));
-}
-
 #ifdef HAVE_LIBAUDIT
-void hwaudit_exit(int status)
+/*
+ * hwclock_exit calls either this function or plain exit depending
+ * HAVE_LIBAUDIT, see also clock.h
+ */
+void __attribute__((__noreturn__)) hwaudit_exit(int status)
 {
        if (hwaudit_on) {
                audit_log_user_message(hwaudit_fd, AUDIT_USYS_CONFIG,
index 62643178e870c31bb53dd1b189cedee7e800c0c8..4bbca9cd6fefd083253e9adc9185ef73f68528fb 100644 (file)
@@ -49,7 +49,7 @@ static int synchronize_to_clock_tick_kd(void)
                printf(_("Waiting in loop for time from KDGHWCLK to change\n"));
 
        if (ioctl(con_fd, KDGHWCLK, &start_time) == -1) {
-               outsyserr(_("KDGHWCLK ioctl to read time failed"));
+               warn(_("KDGHWCLK ioctl to read time failed"));
                return 3;
        }
 
@@ -71,16 +71,14 @@ static int synchronize_to_clock_tick_kd(void)
                usleep(1);
 
                if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
-                       outsyserr(_
-                                 ("KDGHWCLK ioctl to read time failed in loop"));
+                       warn(_("KDGHWCLK ioctl to read time failed in loop"));
                        return 3;
                }
                if (start_time.tm_sec != nowtime.tm_sec)
                        break;
                gettimeofday(&now, NULL);
                if (time_diff(now, begin) > 1.5) {
-                       fprintf(stderr,
-                               _("Timed out waiting for time change.\n"));
+                       warnx(_("Timed out waiting for time change."));
                        return 2;
                }
        } while (1);
@@ -99,7 +97,7 @@ static int 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 %s"),
+               warn(_("ioctl() failed to read time from %s"),
                          con_fd_filename);
                hwclock_exit(EX_IOERR);
        }
@@ -135,8 +133,8 @@ static int set_hardware_clock_kd(const struct tm *new_broken_time)
        t.wday = new_broken_time->tm_wday;
 
        if (ioctl(con_fd, KDSHWCLK, &t) == -1) {
-               outsyserr(_("ioctl KDSHWCLK failed"));
-               hwclock_exit(1);
+               warn(_("ioctl KDSHWCLK failed"));
+               hwclock_exit(EX_IOERR);
        }
        return 0;
 }
@@ -171,11 +169,11 @@ struct clock_ops *probe_for_kd_clock()
        }
        if (con_fd < 0) {
                /* probably KDGHWCLK exists on m68k only */
-               outsyserr(_("Can't open /dev/tty1 or /dev/vc/1"));
+               warn(_("Can't open /dev/tty1 or /dev/vc/1"));
        } else {
                if (ioctl(con_fd, KDGHWCLK, &t) == -1) {
                        if (errno != EINVAL)
-                               outsyserr(_("KDGHWCLK ioctl failed"));
+                               warn(_("KDGHWCLK ioctl failed"));
                } else
                        ret = &kd;
        }
index a76b95c6532027da978af10adac0017d51bb2e0c..79b94962586d7e73cd5f0842879ba917f4b8546c 100644 (file)
@@ -158,7 +158,7 @@ static int open_rtc_or_exit(void)
        int rtc_fd = open_rtc();
 
        if (rtc_fd < 0) {
-               outsyserr(_("open() of %s failed"), rtc_dev_name);
+               warn(_("open() of %s failed"), rtc_dev_name);
                hwclock_exit(EX_OSFILE);
        }
        return rtc_fd;
@@ -191,9 +191,8 @@ static int do_rtc_read_ioctl(int rtc_fd, struct tm *tm)
                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);
+               warn(_("ioctl(%s) to %s to read the time failed"),
+                       ioctlname, rtc_dev_name);
                return -1;
        }
 
@@ -233,8 +232,7 @@ static int busywait_for_rtc_clock_tick(const int rtc_fd)
                        break;
                gettimeofday(&now, NULL);
                if (time_diff(now, begin) > 1.5) {
-                       fprintf(stderr,
-                               _("Timed out waiting for time change.\n"));
+                       warnx(_("Timed out waiting for time change."));
                        return 2;
                }
        } while (1);
@@ -254,7 +252,7 @@ static int synchronize_to_clock_tick_rtc(void)
 
        rtc_fd = open_rtc();
        if (rtc_fd == -1) {
-               outsyserr(_("open() of %s failed"), rtc_dev_name);
+               warn(_("open() of %s failed"), rtc_dev_name);
                ret = 1;
        } else {
                int rc;         /* Return code from ioctl */
@@ -289,9 +287,9 @@ static int synchronize_to_clock_tick_rtc(void)
                        rc = read(rtc_fd, &dummy, sizeof(dummy));
                        ret = 1;
                        if (rc == -1)
-                               outsyserr(_
-                                         ("read() to %s to wait for clock tick failed"),
-                                         rtc_dev_name);
+                               warn(_
+                                    ("read() to %s to wait for clock tick failed"),
+                                    rtc_dev_name);
                        else
                                ret = 0;
 #else
@@ -314,14 +312,13 @@ static int synchronize_to_clock_tick_rtc(void)
                        rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv);
                        ret = 1;
                        if (rc == -1)
-                               outsyserr(_
-                                         ("select() to %s to wait for clock tick failed"),
-                                         rtc_dev_name);
+                               warn(_
+                                    ("select() to %s to wait for clock tick failed"),
+                                    rtc_dev_name);
                        else if (rc == 0)
-                               fprintf(stderr,
-                                       _
-                                       ("select() to %s to wait for clock tick timed out\n"),
-                                       rtc_dev_name);
+                               warn(_
+                                    ("select() to %s to wait for clock tick timed out"),
+                                    rtc_dev_name);
                        else
                                ret = 0;
 #endif
@@ -329,13 +326,13 @@ static int synchronize_to_clock_tick_rtc(void)
                        /* 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_name);
+                               warn(_
+                                    ("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_name);
+                       warn(_
+                            ("ioctl() to %s to turn on update interrupts "
+                             "failed unexpectedly"), rtc_dev_name);
                        ret = 1;
                }
        }
@@ -388,9 +385,8 @@ static int set_hardware_clock_rtc(const struct tm *new_broken_time)
        }
 
        if (rc == -1) {
-               perror(ioctlname);
-               fprintf(stderr, _("ioctl() to %s to set the time failed.\n"),
-                       rtc_dev_name);
+               warn(_("ioctl(%s) to %s to set the time failed."),
+                       ioctlname, rtc_dev_name);
                hwclock_exit(EX_IOERR);
        }
 
@@ -420,7 +416,7 @@ struct clock_ops *probe_for_rtc_clock()
        if (rtc_fd >= 0)
                return &rtc;
        if (debug)
-               outsyserr(_("Open of %s failed"), rtc_dev_name);
+               warn(_("Open of %s failed"), rtc_dev_name);
        return NULL;
 }
 
@@ -435,21 +431,20 @@ int get_epoch_rtc(unsigned long *epoch_p, int silent)
        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_name);
+                               warnx(_
+                                     ("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."),
+                                     rtc_dev_name);
                        else
-                               outsyserr(_("Unable to open %s"), rtc_dev_name);
+                               warn(_("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"),
+                       warn(_("ioctl(RTC_EPOCH_READ) to %s failed"),
                                  rtc_dev_name);
                return 1;
        }
@@ -475,22 +470,21 @@ int set_epoch_rtc(unsigned long epoch)
                 * Bad habit, deciding not to do what the user asks just
                 * because one believes that the kernel might not like it.
                 */
-               fprintf(stderr, _("The epoch value may not be less than 1900.  "
-                                 "You requested %ld\n"), epoch);
+               warnx(_("The epoch value may not be less than 1900.  "
+                       "You requested %ld"), epoch);
                return 1;
        }
 
        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_name);
+                       warnx(_
+                             ("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."),
+                             rtc_dev_name);
                else
-                       outsyserr(_("Unable to open %s"), rtc_dev_name);
+                       warn(_("Unable to open %s"), rtc_dev_name);
                return 1;
        }
 
@@ -501,11 +495,11 @@ int set_epoch_rtc(unsigned long epoch)
 
        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_name);
+                       warnx(_("The kernel device driver for %s "
+                               "does not have the RTC_EPOCH_SET ioctl."),
+                             rtc_dev_name);
                else
-                       outsyserr(_("ioctl(RTC_EPOCH_SET) to %s failed"),
+                       warn(_("ioctl(RTC_EPOCH_SET) to %s failed"),
                                  rtc_dev_name);
                return 1;
        }