Made some progress with consolidation of timezone-related code:
* renamed syscalls _kern_[gs]et_tzfilename to _kern_[gs]et_real_time_clock_is_gmt, as the filename part is no longer relevant (and the two corresponding parameters were removed) * C++-ified and reworked clockconfig to use the info from 'Time settings' to setup the timezone info during boot * removed invocation of _kern_get_tzfilename() from tzset(), as the syscall no longer exists and tzset() is currently broken anyway * adjusted the Time preflet to use the renamed syscall when getting/setting the RTC info git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37881 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
0aa23047c6
commit
96ac47e312
@ -42,8 +42,8 @@ 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_tzfilename(const char* filename, size_t length, bool isGMT);
|
||||
status_t _user_get_tzfilename(char *filename, size_t length, bool *_isGMT);
|
||||
status_t _user_set_real_time_clock_is_gmt(bool isGMT);
|
||||
status_t _user_get_real_time_clock_is_gmt(bool *_isGMT);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -367,10 +367,8 @@ 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_tzfilename(const char *filename, size_t length,
|
||||
bool isGMT);
|
||||
extern status_t _kern_get_tzfilename(char *filename, size_t length,
|
||||
bool *_isGMT);
|
||||
extern status_t _kern_set_real_time_clock_is_gmt(bool isGMT);
|
||||
extern status_t _kern_get_real_time_clock_is_gmt(bool *_isGMT);
|
||||
|
||||
extern bigtime_t _kern_system_time();
|
||||
extern status_t _kern_snooze_etc(bigtime_t time, int timebase, int32 flags);
|
||||
|
@ -29,7 +29,6 @@ StdBinCommands
|
||||
cal.c
|
||||
chop.c
|
||||
clear.c
|
||||
clockconfig.c
|
||||
# csplit.c
|
||||
driveinfo.c
|
||||
# echo.c
|
||||
@ -83,6 +82,7 @@ StdBinCommands
|
||||
catattr.cpp
|
||||
checkfs.cpp
|
||||
clipboard.cpp
|
||||
clockconfig.cpp
|
||||
df.cpp
|
||||
diskimage.cpp
|
||||
dpms.cpp
|
||||
@ -203,7 +203,7 @@ StdBinCommands
|
||||
StdBinCommands
|
||||
checkitout.cpp
|
||||
: be tracker $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ;
|
||||
|
||||
|
||||
#standard commands that need libbe.so, libtracker.so, liblocale.so
|
||||
StdBinCommands
|
||||
filepanel.cpp
|
||||
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004, Jérôme Duval, jerome.duval@free.fr.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
#ifdef COMPILE_FOR_R5
|
||||
void _kset_tzfilename_(const char *name, size_t length, bool isGMT);
|
||||
void _kset_tzspecs_(uint32 timezone_offset, bool dst_observed);
|
||||
|
||||
# define _kern_set_tzfilename _kset_tzfilename_
|
||||
# define _kern_set_timezone _kset_tzspecs_
|
||||
#else
|
||||
# include <syscalls.h>
|
||||
#endif
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char path[B_PATH_NAME_LENGTH];
|
||||
char link[B_PATH_NAME_LENGTH];
|
||||
FILE *file;
|
||||
bool isGMT = false;
|
||||
struct tm* tm = NULL;
|
||||
time_t t;
|
||||
|
||||
printf("Looking for RTC settings file\n");
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, true, path, B_PATH_NAME_LENGTH) != B_OK) {
|
||||
fprintf(stderr, "%s: can't find settings directory\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
strcat(path, "/RTC_time_settings");
|
||||
file = fopen(path, "r");
|
||||
if (file != NULL) {
|
||||
char string[10];
|
||||
fscanf(file, "%s", string);
|
||||
isGMT = (strncmp(string, "local", 5) != 0);
|
||||
fclose(file);
|
||||
} else {
|
||||
fprintf(stderr, "%s: can't read RTC settings\n", argv[0]);
|
||||
printf("%s: No knowledge about contents of RTC\n", argv[0]);
|
||||
|
||||
// we don't care if not RTC settings is found, default is local
|
||||
}
|
||||
|
||||
printf("%s: RTC stores %s time.\n", argv[0], isGMT ? "GMT" : "local" );
|
||||
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, true, path, B_PATH_NAME_LENGTH) != B_OK) {
|
||||
fprintf(stderr, "can't find settings directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
strcat(path, "/timezone");
|
||||
|
||||
printf("Looking for %s file\n", path);
|
||||
if (readlink(path, link, B_PATH_NAME_LENGTH) > 0) {
|
||||
printf("%s: Setting timezone to '%s'\n", argv[0], link);
|
||||
|
||||
_kern_set_tzfilename(link, strlen(link), isGMT);
|
||||
|
||||
tzset();
|
||||
|
||||
time(&t);
|
||||
tm = localtime(&t);
|
||||
_kern_set_timezone(tm->tm_gmtoff, tm->tm_isdst);
|
||||
} else {
|
||||
fprintf(stderr, "%s: can't read link for timezone\n", argv[0]);
|
||||
printf("%s: No timezone setting.\n", argv[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
92
src/bin/clockconfig.cpp
Normal file
92
src/bin/clockconfig.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2004, Jérôme Duval, jerome.duval@free.fr.
|
||||
* Copyright 2010, Oliver Tappe <zooey@hirschkaefer.de>
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Message.h>
|
||||
#include <OS.h>
|
||||
#include <Path.h>
|
||||
|
||||
#include <syscalls.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static char* program;
|
||||
|
||||
|
||||
void
|
||||
setRealTimeClockIsGMT(BPath path)
|
||||
{
|
||||
path.Append("RTC_time_settings");
|
||||
BFile file;
|
||||
status_t status = file.SetTo(path.Path(), B_READ_ONLY);
|
||||
if (status != B_OK) {
|
||||
fprintf(stderr, "%s: can't open RTC settings file\n", program);
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[10];
|
||||
ssize_t bytesRead = file.Read(buffer, sizeof(buffer));
|
||||
if (bytesRead < 0) {
|
||||
fprintf(stderr, "%s: unable to read RTC settings file\n", program);
|
||||
return;
|
||||
}
|
||||
bool isGMT = strncmp(buffer, "local", 5) != 0;
|
||||
|
||||
_kern_set_real_time_clock_is_gmt(isGMT);
|
||||
printf("RTC stores %s time.\n", isGMT ? "GMT" : "local" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
setTimeZoneOffset(BPath path)
|
||||
{
|
||||
path.Append("Time settings");
|
||||
BFile file;
|
||||
status_t status = file.SetTo(path.Path(), B_READ_ONLY);
|
||||
if (status != B_OK) {
|
||||
fprintf(stderr, "%s: can't open Time settings file\n", program);
|
||||
return;
|
||||
}
|
||||
|
||||
BMessage settings;
|
||||
status = settings.Unflatten(&file);
|
||||
if (status != B_OK) {
|
||||
fprintf(stderr, "%s: unable to parse Time settings file\n", program);
|
||||
return;
|
||||
}
|
||||
int32 timeZoneOffset;
|
||||
if (settings.FindInt32("offset", &timeZoneOffset) != B_OK) {
|
||||
fprintf(stderr, "%s: no timezone offset found\n", program);
|
||||
return;
|
||||
}
|
||||
|
||||
_kern_set_timezone(timeZoneOffset, false);
|
||||
printf("timezone offset is %ld seconds from GMT.\n", timeZoneOffset);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
program = argv[0];
|
||||
|
||||
BPath path;
|
||||
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||
if (status != B_OK) {
|
||||
fprintf(stderr, "%s: can't find settings directory\n", program);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
setRealTimeClockIsGMT(path);
|
||||
setTimeZoneOffset(path);
|
||||
|
||||
return 0;
|
||||
}
|
@ -319,7 +319,7 @@ DateTimeView::_UpdateGmtSettings()
|
||||
{
|
||||
_WriteRTCSettings();
|
||||
|
||||
_kern_set_tzfilename(NULL, 0, fUseGmtTime);
|
||||
_kern_set_real_time_clock_is_gmt(fUseGmtTime);
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
static struct real_time_data *sRealTimeData;
|
||||
static bool sIsGMT = false;
|
||||
static char sTimezoneFilename[B_PATH_NAME_LENGTH] = "";
|
||||
static bigtime_t sTimezoneOffset = 0;
|
||||
static bool sDaylightSavingTime = false;
|
||||
|
||||
@ -290,19 +289,13 @@ _user_get_timezone(time_t *_timezoneOffset, bool *_daylightSavingTime)
|
||||
|
||||
|
||||
status_t
|
||||
_user_set_tzfilename(const char *filename, size_t length, bool isGMT)
|
||||
_user_set_real_time_clock_is_gmt(bool isGMT)
|
||||
{
|
||||
// store previous value
|
||||
bool wasGMT = sIsGMT;
|
||||
if (geteuid() != 0)
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
if (filename != NULL && length > 0) {
|
||||
if (!IS_USER_ADDRESS(filename)
|
||||
|| user_strlcpy(sTimezoneFilename, filename, B_PATH_NAME_LENGTH) < 0)
|
||||
return B_BAD_ADDRESS;
|
||||
}
|
||||
|
||||
sIsGMT = isGMT;
|
||||
|
||||
if (wasGMT != sIsGMT) {
|
||||
@ -316,16 +309,11 @@ _user_set_tzfilename(const char *filename, size_t length, bool isGMT)
|
||||
|
||||
|
||||
status_t
|
||||
_user_get_tzfilename(char *userFilename, size_t length, bool *_userIsGMT)
|
||||
_user_get_real_time_clock_is_gmt(bool *_userIsGMT)
|
||||
{
|
||||
if ((userFilename == NULL || length == 0) && _userIsGMT == NULL)
|
||||
if (_userIsGMT == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if (userFilename != NULL
|
||||
&& (!IS_USER_ADDRESS(userFilename)
|
||||
|| user_strlcpy(userFilename, sTimezoneFilename, length) < 0))
|
||||
return B_BAD_ADDRESS;
|
||||
|
||||
if (_userIsGMT != NULL
|
||||
&& (!IS_USER_ADDRESS(_userIsGMT)
|
||||
|| user_memcpy(_userIsGMT, &sIsGMT, sizeof(bool)) != B_OK))
|
||||
|
@ -1173,7 +1173,7 @@ tzset P((void))
|
||||
|
||||
name = getenv("TZ");
|
||||
if (name == NULL) {
|
||||
_kern_get_tzfilename(tzfilename, sizeof(tzfilename), &is_gmt);
|
||||
// _kern_get_tzfilename(tzfilename, sizeof(tzfilename), &is_gmt);
|
||||
if (tzfilename[0] == '\0') {
|
||||
tzsetwall();
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user