From 7e965f506df723e0253980218bc3ce819b7736e4 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Tue, 3 Aug 2010 23:02:57 +0000 Subject: [PATCH] More consolidation of timezone code: * dropped DaylightSavingTime from real_time_clock code in kernel, it was never really being used for what it meant (and just being referred to by gettimeofday(), which put a different meaning to it * adjusted the syscalls get_timezone() & set_timezone() as well as their callers accordingly * got rid of get_rtc_info() and rtc_info struct in kernel, as it was only being referred to by the FAT add-on and that one (like gettimeofday()) put a different meaning to tz_minuteswest. Added a comment to FAT's util.c showing a possible solution, should the hardcoded GMT timezone pose a problem. * fixed declaration of gettimeofday() to match POSIX base specs, issue 7 * changed implementation of gettimeofday() to not bother trying to fill struct timezone - it was using wrong values before, anyway. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37888 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/posix/sys/time.h | 4 +- headers/private/kernel/real_time_clock.h | 14 +------ headers/private/system/syscalls.h | 6 +-- src/add-ons/kernel/file_systems/fat/util.c | 20 ++++++---- src/bin/clockconfig.cpp | 2 +- src/preferences/time/ZoneView.cpp | 2 +- src/system/kernel/real_time_clock.cpp | 42 ++------------------- src/system/libroot/posix/sys/gettimeofday.c | 12 ++---- 8 files changed, 27 insertions(+), 75 deletions(-) diff --git a/headers/posix/sys/time.h b/headers/posix/sys/time.h index 9e8fa67fc1..02f46a0e94 100644 --- a/headers/posix/sys/time.h +++ b/headers/posix/sys/time.h @@ -1,6 +1,6 @@ #ifndef _SYS_TIME_H #define _SYS_TIME_H -/* +/* ** Distributed under the terms of the OpenBeOS License. */ @@ -40,7 +40,7 @@ extern "C" { extern int getitimer(int which, struct itimerval *value); extern int setitimer(int which, const struct itimerval *value, struct itimerval *oldValue); -extern int gettimeofday(struct timeval *tv, struct timezone *tz); +extern int gettimeofday(struct timeval *tv, void *tz); extern int utimes(const char *name, const struct timeval times[2]); /* legacy */ diff --git a/headers/private/kernel/real_time_clock.h b/headers/private/kernel/real_time_clock.h index 2a18b4a1a0..f6997a97ff 100644 --- a/headers/private/kernel/real_time_clock.h +++ b/headers/private/kernel/real_time_clock.h @@ -15,14 +15,6 @@ #define RTC_EPOCH_BASE_YEAR 1970 -typedef struct rtc_info { - uint32 time; - bool is_gmt; - int32 tz_minuteswest; - bool tz_dsttime; -} rtc_info; - - #ifdef __cplusplus extern "C" { #endif @@ -31,8 +23,6 @@ status_t rtc_init(kernel_args *args); bigtime_t rtc_boot_time(void); // Returns the time at which the system was booted in microseconds since Jan 1, 1970 UTC. -status_t get_rtc_info(rtc_info *info); - // Both functions use the passed struct tm only partially // (no tm_wday, tm_yday, tm_isdst). uint32 rtc_tm_to_secs(const struct tm *t); @@ -40,8 +30,8 @@ void rtc_secs_to_tm(uint32 seconds, struct tm *t); bigtime_t _user_system_time(void); status_t _user_set_real_time_clock(uint32 time); -status_t _user_set_timezone(int32 timezoneOffset, bool daylightSavingTime); -status_t _user_get_timezone(int32 *_timezoneOffset, bool *_daylightSavingTime); +status_t _user_set_timezone(int32 timezoneOffset); +status_t _user_get_timezone(int32 *_timezoneOffset); status_t _user_set_real_time_clock_is_gmt(bool isGMT); status_t _user_get_real_time_clock_is_gmt(bool *_isGMT); diff --git a/headers/private/system/syscalls.h b/headers/private/system/syscalls.h index a3d754dafd..9cfbb60090 100644 --- a/headers/private/system/syscalls.h +++ b/headers/private/system/syscalls.h @@ -363,10 +363,8 @@ extern status_t _kern_stop_watching(dev_t device, ino_t node, port_id port, // time functions extern status_t _kern_set_real_time_clock(uint32 time); -extern status_t _kern_set_timezone(int32 timezoneOffset, - bool daylightSavingTime); -extern status_t _kern_get_timezone(int32 *_timezoneOffset, - bool *_daylightSavingTime); +extern status_t _kern_set_timezone(int32 timezoneOffset); +extern status_t _kern_get_timezone(int32 *_timezoneOffset); extern status_t _kern_set_real_time_clock_is_gmt(bool isGMT); extern status_t _kern_get_real_time_clock_is_gmt(bool *_isGMT); diff --git a/src/add-ons/kernel/file_systems/fat/util.c b/src/add-ons/kernel/file_systems/fat/util.c index 7e015ad327..f7981fab67 100644 --- a/src/add-ons/kernel/file_systems/fat/util.c +++ b/src/add-ons/kernel/file_systems/fat/util.c @@ -69,16 +69,22 @@ dump_directory(uint8 *buffer) static void get_tzoffset() { - rtc_info info; - if (tzoffset != -1) return; - if (get_rtc_info(&info) < 0) { - dprintf("error getting rtc info\n"); - } else { - tzoffset = info.tz_minuteswest; - } + // tzoffset used to be set to a bogus value (timezone offset in seconds), + // we could try to use something like the following ... + // + // int32 tzOffsetInSeconds; + // if (_kern_get_timezone(&tzOffsetInSeconds) < 0) { + // dprintf("error getting timezone offset\n"); + // } else { + // tzoffset = tzOffsetInSeconds / 60; + // } + // + // but I'd rather like to spare us the specific kernel call, + // so we hardcode the timezone (let's see if it makes any difference) + tzoffset = 0; } diff --git a/src/bin/clockconfig.cpp b/src/bin/clockconfig.cpp index 5466cef80f..9bd7743c5e 100644 --- a/src/bin/clockconfig.cpp +++ b/src/bin/clockconfig.cpp @@ -68,7 +68,7 @@ setTimeZoneOffset(BPath path) return; } - _kern_set_timezone(timeZoneOffset, false); + _kern_set_timezone(timeZoneOffset); printf("timezone offset is %ld seconds from GMT.\n", timeZoneOffset); } diff --git a/src/preferences/time/ZoneView.cpp b/src/preferences/time/ZoneView.cpp index e629d73657..a2a87cf12a 100644 --- a/src/preferences/time/ZoneView.cpp +++ b/src/preferences/time/ZoneView.cpp @@ -357,7 +357,7 @@ TimeZoneView::_SetSystemTimeZone() mutable_locale_roster->SetDefaultTimeZone(timeZone); - _kern_set_timezone(timeZone.OffsetFromGMT(), false); + _kern_set_timezone(timeZone.OffsetFromGMT()); fSetZone->SetEnabled(false); fLastUpdateMinute = -1; diff --git a/src/system/kernel/real_time_clock.cpp b/src/system/kernel/real_time_clock.cpp index 0e5570689b..4578a30531 100644 --- a/src/system/kernel/real_time_clock.cpp +++ b/src/system/kernel/real_time_clock.cpp @@ -32,7 +32,6 @@ static struct real_time_data *sRealTimeData; static bool sIsGMT = false; static bigtime_t sTimezoneOffset = 0; -static bool sDaylightSavingTime = false; /*! Write the system time to CMOS. */ @@ -129,21 +128,6 @@ real_time_clock_usecs(void) } -status_t -get_rtc_info(rtc_info *info) -{ - if (info == NULL) - return B_BAD_VALUE; - - info->time = real_time_clock(); - info->is_gmt = sIsGMT; - info->tz_minuteswest = sTimezoneOffset / 1000000LL; - info->tz_dsttime = sDaylightSavingTime; - - return B_OK; -} - - // #pragma mark - @@ -202,22 +186,6 @@ rtc_secs_to_tm(uint32 seconds, struct tm *t) } -// #pragma mark - - - -/*! This is called from the gettimeofday() implementation that's part of the - kernel. -*/ -status_t -_kern_get_timezone(time_t *_timezoneOffset, bool *_daylightSavingTime) -{ - *_timezoneOffset = (time_t)(sTimezoneOffset / 1000000LL); - *_daylightSavingTime = sDaylightSavingTime; - - return B_OK; -} - - // #pragma mark - syscalls @@ -242,7 +210,7 @@ _user_set_real_time_clock(uint32 time) status_t -_user_set_timezone(time_t timezoneOffset, bool daylightSavingTime) +_user_set_timezone(time_t timezoneOffset) { bigtime_t offset = (bigtime_t)timezoneOffset * 1000000LL; @@ -263,7 +231,6 @@ _user_set_timezone(time_t timezoneOffset, bool daylightSavingTime) } sTimezoneOffset = offset; - sDaylightSavingTime = daylightSavingTime; TRACE(("new system_time_offset %Ld\n", arch_rtc_get_system_time_offset(sRealTimeData))); @@ -273,15 +240,12 @@ _user_set_timezone(time_t timezoneOffset, bool daylightSavingTime) status_t -_user_get_timezone(time_t *_timezoneOffset, bool *_daylightSavingTime) +_user_get_timezone(time_t *_timezoneOffset) { time_t offset = (time_t)(sTimezoneOffset / 1000000LL); if (!IS_USER_ADDRESS(_timezoneOffset) - || !IS_USER_ADDRESS(_daylightSavingTime) - || user_memcpy(_timezoneOffset, &offset, sizeof(time_t)) < B_OK - || user_memcpy(_daylightSavingTime, &sDaylightSavingTime, - sizeof(bool)) < B_OK) + || user_memcpy(_timezoneOffset, &offset, sizeof(time_t)) < B_OK) return B_BAD_ADDRESS; return B_OK; diff --git a/src/system/libroot/posix/sys/gettimeofday.c b/src/system/libroot/posix/sys/gettimeofday.c index f234d10984..3660e99515 100644 --- a/src/system/libroot/posix/sys/gettimeofday.c +++ b/src/system/libroot/posix/sys/gettimeofday.c @@ -9,7 +9,7 @@ int -gettimeofday(struct timeval *tv, struct timezone *tz) +gettimeofday(struct timeval *tv, void *tz) { if (tv != NULL) { bigtime_t usecs = real_time_clock_usecs(); @@ -18,14 +18,8 @@ gettimeofday(struct timeval *tv, struct timezone *tz) tv->tv_usec = usecs % 1000000; } - if (tz != NULL) { - time_t timezoneOffset; - bool daylightSavingTime; - _kern_get_timezone(&timezoneOffset, &daylightSavingTime); - - tz->tz_minuteswest = timezoneOffset; - tz->tz_dsttime = daylightSavingTime; - } + // struct timezone (tz) has been deprecated since long and its exact + // semantics are a bit unclear, so we need not bother to deal with it return 0; }