X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fhwclock.c;h=488c30e93f6c8ce04dfb2da451b4c60022b0c9c4;hb=d611dadcc74db10ba533ee6859308f5fc505aee1;hp=9f8ab08e2bdd0589b9fd5a0d7446c713afbbe5dc;hpb=b7def684941808600c344f0be7a2b9fcdda97e0f;p=elogind.git diff --git a/src/shared/hwclock.c b/src/shared/hwclock.c index 9f8ab08e2..488c30e93 100644 --- a/src/shared/hwclock.c +++ b/src/shared/hwclock.c @@ -41,6 +41,7 @@ #include "log.h" #include "strv.h" #include "hwclock.h" +#include "fileio.h" static int rtc_open(int flags) { int fd; @@ -61,10 +62,11 @@ static int rtc_open(int flags) { for (;;) { char *p, *v; - struct dirent buf, *de; + struct dirent *de; + union dirent_storage buf; int r; - r = readdir_r(d, &buf, &de); + r = readdir_r(d, &buf.de, &de); if (r != 0) goto fallback; @@ -93,6 +95,11 @@ static int rtc_open(int flags) { continue; p = strappend("/dev/", de->d_name); + if (!p) { + closedir(d); + return -ENOMEM; + } + fd = open(p, flags); free(p); @@ -154,6 +161,7 @@ int hwclock_set_time(const struct tm *tm) { return err; } + int hwclock_is_localtime(void) { FILE *f; bool local = false; @@ -188,18 +196,18 @@ int hwclock_is_localtime(void) { return local; } -int hwclock_apply_localtime_delta(int *min) { +int hwclock_set_timezone(int *min) { const struct timeval *tv_null = NULL; struct timespec ts; struct tm *tm; - int minuteswest; + int minutesdelta; struct timezone tz; assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0); assert_se(tm = localtime(&ts.tv_sec)); - minuteswest = tm->tm_gmtoff / 60; + minutesdelta = tm->tm_gmtoff / 60; - tz.tz_minuteswest = -minuteswest; + tz.tz_minuteswest = -minutesdelta; tz.tz_dsttime = 0; /* DST_NONE*/ /* @@ -210,17 +218,22 @@ int hwclock_apply_localtime_delta(int *min) { if (settimeofday(tv_null, &tz) < 0) return -errno; if (min) - *min = minuteswest; + *min = minutesdelta; return 0; } -int hwclock_reset_localtime_delta(void) { +int hwclock_reset_timezone(void) { const struct timeval *tv_null = NULL; struct timezone tz; tz.tz_minuteswest = 0; tz.tz_dsttime = 0; /* DST_NONE*/ + /* + * The very first time we set the kernel's timezone, it will warp + * the clock. Do a dummy call here, so the time warping is sealed + * and we set only the time zone with next call. + */ if (settimeofday(tv_null, &tz) < 0) return -errno;