]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fix hwclock_apply_localtime_delta() to properly handle negative TZ offset
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 21 Jul 2011 18:28:27 +0000 (20:28 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Thu, 21 Jul 2011 18:28:27 +0000 (20:28 +0200)
Localtime may be a negative number, i.e. GMT-7. Fix based on a
patch from Kelly Anderson <kelly@silka.with-linux.com>.

src/main.c
src/timedated.c
src/util.c
src/util.h

index 0bcd09c4cf1686bba3a021d8c312389936f1bb4e..0a99e5a91612d381c6fbd714d50e8376406f466c 100644 (file)
@@ -1056,11 +1056,11 @@ int main(int argc, char *argv[]) {
                         goto finish;
 
                 if (hwclock_is_localtime() > 0) {
-                        int min;
+                        int err, min;
 
-                        min = hwclock_apply_localtime_delta();
-                        if (min < 0)
-                                log_error("Failed to apply local time delta: %s", strerror(-min));
+                        err = hwclock_apply_localtime_delta(&min);
+                        if (err < 0)
+                                log_error("Failed to apply local time delta: %s", strerror(-err));
                         else
                                 log_info("RTC configured in localtime, applying delta of %i minutes to system time.", min);
                 }
index 55cc904f0cd236d9ea99e8bb9e0e0fe90f1bcb43..4abcf1af73df3a88f0a48b3383cfabd15077ee62 100644 (file)
@@ -332,7 +332,7 @@ static DBusHandlerResult timedate_message_handler(
                                 struct tm *tm;
 
                                 /* 2. Teach kernel new timezone */
-                                hwclock_apply_localtime_delta();
+                                hwclock_apply_localtime_delta(NULL);
 
                                 /* 3. Sync RTC from system clock, with the new delta */
                                 assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0);
@@ -382,7 +382,7 @@ static DBusHandlerResult timedate_message_handler(
 
                         /* 2. Teach kernel new timezone */
                         if (local_rtc)
-                                hwclock_apply_localtime_delta();
+                                hwclock_apply_localtime_delta(NULL);
                         else
                                 hwclock_reset_localtime_delta();
 
index a0fbdc517e7167a7f85cfe4ecccdfb9afa22175f..3187ec37687a6c9709127468da4787e4a2cd4a4f 100644 (file)
@@ -4905,7 +4905,7 @@ int hwclock_is_localtime(void) {
         return local;
 }
 
-int hwclock_apply_localtime_delta(void) {
+int hwclock_apply_localtime_delta(int *min) {
         const struct timeval *tv_null = NULL;
         struct timespec ts;
         struct tm *tm;
@@ -4926,8 +4926,9 @@ int hwclock_apply_localtime_delta(void) {
          */
         if (settimeofday(tv_null, &tz) < 0)
                 return -errno;
-
-        return minuteswest;
+        if (min)
+                *min = minuteswest;
+        return 0;
 }
 
 int hwclock_reset_localtime_delta(void) {
index b8bbd23e8c09532cc92a80d85841eee98f3b8a5d..7a4bf81c8d1b063c92c99f3b6d299e2fa21752b9 100644 (file)
@@ -434,8 +434,7 @@ int fchmod_umask(int fd, mode_t mode);
 int conf_files_list(char ***strv, const char *suffix, const char *dir, ...);
 
 int hwclock_is_localtime(void);
-
-int hwclock_apply_localtime_delta(void);
+int hwclock_apply_localtime_delta(int *min);
 int hwclock_reset_localtime_delta(void);
 int hwclock_get_time(struct tm *tm);
 int hwclock_set_time(const struct tm *tm);