]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: use symbolic magic values passed in between functions
authorSami Kerola <kerolasa@iki.fi>
Sun, 17 Jul 2016 15:14:16 +0000 (16:14 +0100)
committerSami Kerola <kerolasa@iki.fi>
Sat, 4 Feb 2017 23:39:37 +0000 (23:39 +0000)
The manipulate_clock() is seeing return value from
busywait_for_rtc_clock_tick().

And the get_permissions_cmos() can see i386_iopl() return value.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/hwclock-cmos.c
sys-utils/hwclock-rtc.c
sys-utils/hwclock.c
sys-utils/hwclock.h

index 6595725fd1b18fed5c953c08ed92260720e504b5..30f8765a572e1683c5a7fb33678037da37916d86 100644 (file)
@@ -104,6 +104,8 @@ static int inb(int c __attribute__ ((__unused__)))
 #define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 #define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
 
+#define IOPL_NOT_IMPLEMENTED -2
+
 /*
  * The epoch.
  *
@@ -633,7 +635,7 @@ static int i386_iopl(const int level __attribute__ ((__unused__)))
 #else
 static int i386_iopl(const int level __attribute__ ((__unused__)))
 {
-       return -2;
+       return IOPL_NOT_IMPLEMENTED;
 }
 #endif
 
@@ -649,7 +651,7 @@ static int get_permissions_cmos(void)
                        rc = 0;
        } else {
                rc = i386_iopl(3);
-               if (rc == -2) {
+               if (rc == IOPL_NOT_IMPLEMENTED) {
                        warnx(_("I failed to get permission because I didn't try."));
                } else if (rc != 0) {
                        rc = errno;
index b974cc2aa59aa8039e769e8484157d50cff641f3..48a6f4d586d15601118601162952ae1d04fa3371 100644 (file)
@@ -208,7 +208,7 @@ static int busywait_for_rtc_clock_tick(const struct hwclock_control *ctl,
 
        rc = do_rtc_read_ioctl(rtc_fd, &start_time);
        if (rc)
-               return 1;
+               return RTC_BUSYWAIT_FAILED;
 
        /*
         * Wait for change.  Should be within a second, but in case
@@ -223,13 +223,13 @@ static int busywait_for_rtc_clock_tick(const struct hwclock_control *ctl,
                gettimeofday(&now, NULL);
                if (time_diff(now, begin) > 1.5) {
                        warnx(_("Timed out waiting for time change."));
-                       return 2;
+                       return RTC_BUSYWAIT_TIMEOUT;
                }
        } while (1);
 
        if (rc)
-               return 3;
-       return 0;
+               return RTC_BUSYWAIT_FAILED;
+       return RTC_BUSYWAIT_OK;
 }
 
 /*
index 7b363b5671be00a8742e17fc01f91800b3a43fa1..e4885d56314bcfadce5f815ed20d777464f3c42a 100644 (file)
@@ -1226,14 +1226,12 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
                rc = synchronize_to_clock_tick(ctl);
 
                /*
-                * 2 = synchronization timeout. We don't
-                * error out if the user is attempting to
-                * set the RTC - the RTC could be
-                * functioning but contain invalid time data
-                * so we still want to allow a user to set
-                * the RTC time.
+                * We don't error out if the user is attempting to set the
+                * RTC and synchronization timeout happens - the RTC could
+                * be functioning but contain invalid time data so we still
+                * want to allow a user to set the RTC time.
                 */
-               if (rc && rc != 2 && !ctl->set && !ctl->systohc)
+               if (rc == RTC_BUSYWAIT_FAILED && !ctl->set && !ctl->systohc)
                        return EX_IOERR;
                gettimeofday(&read_time, NULL);
 
index c76068c881af5e7496b6d04e23ef707cbe59c726..cd1d3b6cfaf7f9990004357a6ef5730af340c22a 100644 (file)
@@ -9,6 +9,12 @@
 
 #include "c.h"
 
+enum {
+       RTC_BUSYWAIT_OK = 0,
+       RTC_BUSYWAIT_FAILED,
+       RTC_BUSYWAIT_TIMEOUT
+};
+
 struct hwclock_control {
        char *date_opt;
        unsigned long epoch_option;