]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: squash custom errno strings
authorJ William Piggott <elseifthen@gmx.com>
Sun, 23 Jul 2017 17:21:32 +0000 (13:21 -0400)
committerJ William Piggott <elseifthen@gmx.com>
Mon, 31 Jul 2017 20:10:47 +0000 (16:10 -0400)
hwclock previously used printf for custom errno messages.
Later they were converted to use warn(), but were not
squashed. One of the reasons for warn and errno is to avoid
making translators deal with a multitude custom strings.

Also the custom strings are incorrect:

hwclock --hctosys
hwclock: Must be superuser to set system clock.
Unable to set system clock.

We do not know what the system permissions are set to.  The
correct response is to simply say permission was denied; as
the default errno string does. The second line is redundant
and just adds noise the code and to logs.

Patched:

hwclock --hctosys
hwclock: settimeofday() failed: Operation not permitted

Signed-off-by: J William Piggott <elseifthen@gmx.com>
sys-utils/hwclock.c

index aadf1964ad381514e026d772597f5f893e0f43d8..c74e0e2649729aabd2a3a047689f742a74815413 100644 (file)
@@ -648,14 +648,8 @@ set_system_clock(const struct hwclock_control *ctl, const bool hclock_valid,
                        if (!rc)
                                rc = settimeofday(&newtime, &tz);
                        if (rc) {
-                               if (errno == EPERM) {
-                                       warnx(_
-                                             ("Must be superuser to set system clock."));
-                                       retcode = EX_NOPERM;
-                               } else {
-                                       warn(_("settimeofday() failed"));
-                                       retcode = 1;
-                               }
+                               warn(_("settimeofday() failed"));
+                               retcode = 1;
                        } else
                                retcode = 0;
                }
@@ -744,14 +738,8 @@ static int set_system_clock_timezone(const struct hwclock_control *ctl)
                        rc = settimeofday(tv_null, &tz);
 
                if (rc) {
-                       if (errno == EPERM) {
-                               warnx(_
-                                     ("Must be superuser to set system clock."));
-                               retcode = EX_NOPERM;
-                       } else {
-                               warn(_("settimeofday() failed"));
-                               retcode = 1;
-                       }
+                       warn(_("settimeofday() failed"));
+                       retcode = 1;
                } else
                        retcode = 0;
        }
@@ -1134,17 +1122,9 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
                        adjust_drift_factor(ctl, adjtime, nowtime,
                                            hclock_valid, hclocktime);
        } else if (ctl->hctosys) {
-               rc = set_system_clock(ctl, hclock_valid, hclocktime);
-               if (rc) {
-                       printf(_("Unable to set system clock.\n"));
-                       return rc;
-               }
+               return set_system_clock(ctl, hclock_valid, hclocktime);
        } else if (ctl->systz) {
-               rc = set_system_clock_timezone(ctl);
-               if (rc) {
-                       printf(_("Unable to set system clock.\n"));
-                       return rc;
-               }
+               return set_system_clock_timezone(ctl);
        } else if (ctl->predict) {
                hclocktime = time_inc(hclocktime, (double)
                                      -(tdrift.tv_sec + tdrift.tv_usec / 1E6));