From 24efb112451413c1013d5f7fe27d7e2cd407647a Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Thu, 22 May 2014 21:21:38 +0900 Subject: shared: rename hwclock.[ch] to clock-util.[ch] --- src/core/dbus-manager.c | 4 +- src/core/main.c | 10 +-- src/hostname/hostnamectl.c | 2 +- src/shared/clock-util.c | 154 +++++++++++++++++++++++++++++++++++++++++++++ src/shared/clock-util.h | 28 +++++++++ src/shared/hwclock.c | 154 --------------------------------------------- src/shared/hwclock.h | 28 --------- src/timedate/timedated.c | 18 +++--- 8 files changed, 199 insertions(+), 199 deletions(-) create mode 100644 src/shared/clock-util.c create mode 100644 src/shared/clock-util.h delete mode 100644 src/shared/hwclock.c delete mode 100644 src/shared/hwclock.h (limited to 'src') diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index d5fab0a22c..333c1d46e7 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -28,7 +28,7 @@ #include "install.h" #include "selinux-access.h" #include "watchdog.h" -#include "hwclock.h" +#include "clock-util.h" #include "path-util.h" #include "virt.h" #include "architecture.h" @@ -130,7 +130,7 @@ static int property_get_tainted( if (access("/proc/cgroups", F_OK) < 0) e = stpcpy(e, "cgroups-missing:"); - if (hwclock_is_localtime() > 0) + if (clock_is_localtime() > 0) e = stpcpy(e, "local-hwclock:"); /* remove the last ':' */ diff --git a/src/core/main.c b/src/core/main.c index 74c50f51be..77cc2fbbdd 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -61,7 +61,7 @@ #include "capability.h" #include "killall.h" #include "env-util.h" -#include "hwclock.h" +#include "clock-util.h" #include "fileio.h" #include "dbus-manager.h" #include "bus-error.h" @@ -1352,11 +1352,11 @@ int main(int argc, char *argv[]) { goto finish; if (!skip_setup) { - if (hwclock_is_localtime() > 0) { + if (clock_is_localtime() > 0) { int min; /* The first-time call to settimeofday() does a time warp in the kernel */ - r = hwclock_set_timezone(&min); + r = clock_set_timezone(&min); if (r < 0) log_error("Failed to apply local time delta, ignoring: %s", strerror(-r)); else @@ -1370,10 +1370,10 @@ int main(int argc, char *argv[]) { * that way. In such case, we need to delay the time-warp or the sealing * until we reach the real system. */ - hwclock_reset_timezone(); + clock_reset_timezone(); /* Tell the kernel our timezone */ - r = hwclock_set_timezone(NULL); + r = clock_set_timezone(NULL); if (r < 0) log_error("Failed to set the kernel's timezone, ignoring: %s", strerror(-r)); } diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 70049d31f6..267cd74011 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -35,7 +35,7 @@ #include "util.h" #include "spawn-polkit-agent.h" #include "build.h" -#include "hwclock.h" +#include "clock-util.h" #include "strv.h" #include "sd-id128.h" #include "virt.h" diff --git a/src/shared/clock-util.c b/src/shared/clock-util.c new file mode 100644 index 0000000000..15535732f7 --- /dev/null +++ b/src/shared/clock-util.c @@ -0,0 +1,154 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2010-2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "macro.h" +#include "util.h" +#include "log.h" +#include "strv.h" +#include "clock-util.h" +#include "fileio.h" + +int clock_get_time(struct tm *tm) { + _cleanup_close_ int fd = -1; + + assert(tm); + + fd = open("/dev/rtc", O_RDONLY|O_CLOEXEC); + if (fd < 0) + return -errno; + + /* This leaves the timezone fields of struct tm + * uninitialized! */ + if (ioctl(fd, RTC_RD_TIME, tm) < 0) + return -errno; + + /* We don't know daylight saving, so we reset this in order not + * to confuse mktime(). */ + tm->tm_isdst = -1; + + return 0; +} + +int clock_set_time(const struct tm *tm) { + _cleanup_close_ int fd = -1; + + assert(tm); + + fd = open("/dev/rtc", O_RDONLY|O_CLOEXEC); + if (fd < 0) + return -errno; + + if (ioctl(fd, RTC_SET_TIME, tm) < 0) + return -errno; + + return 0; +} + +int clock_is_localtime(void) { + _cleanup_fclose_ FILE *f; + + /* + * The third line of adjtime is "UTC" or "LOCAL" or nothing. + * # /etc/adjtime + * 0.0 0 0 + * 0 + * UTC + */ + f = fopen("/etc/adjtime", "re"); + if (f) { + char line[LINE_MAX]; + bool b; + + b = fgets(line, sizeof(line), f) && + fgets(line, sizeof(line), f) && + fgets(line, sizeof(line), f); + if (!b) + return -EIO; + + truncate_nl(line); + return streq(line, "LOCAL"); + + } else if (errno != ENOENT) + return -errno; + + return 0; +} + +int clock_set_timezone(int *min) { + const struct timeval *tv_null = NULL; + struct timespec ts; + struct tm *tm; + int minutesdelta; + struct timezone tz; + + assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0); + assert_se(tm = localtime(&ts.tv_sec)); + minutesdelta = tm->tm_gmtoff / 60; + + tz.tz_minuteswest = -minutesdelta; + tz.tz_dsttime = 0; /* DST_NONE*/ + + /* + * If the hardware clock does not run in UTC, but in local time: + * The very first time we set the kernel's timezone, it will warp + * the clock so that it runs in UTC instead of local time. + */ + if (settimeofday(tv_null, &tz) < 0) + return -errno; + if (min) + *min = minutesdelta; + return 0; +} + +int clock_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 timezone with next call. + */ + if (settimeofday(tv_null, &tz) < 0) + return -errno; + + return 0; +} diff --git a/src/shared/clock-util.h b/src/shared/clock-util.h new file mode 100644 index 0000000000..63d96fca6d --- /dev/null +++ b/src/shared/clock-util.h @@ -0,0 +1,28 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2010-2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +int clock_is_localtime(void); +int clock_set_timezone(int *min); +int clock_reset_timezone(void); +int clock_get_time(struct tm *tm); +int clock_set_time(const struct tm *tm); diff --git a/src/shared/hwclock.c b/src/shared/hwclock.c deleted file mode 100644 index 7059d9c75b..0000000000 --- a/src/shared/hwclock.c +++ /dev/null @@ -1,154 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2010-2012 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see . -***/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "macro.h" -#include "util.h" -#include "log.h" -#include "strv.h" -#include "hwclock.h" -#include "fileio.h" - -int hwclock_get_time(struct tm *tm) { - _cleanup_close_ int fd = -1; - - assert(tm); - - fd = open("/dev/rtc", O_RDONLY|O_CLOEXEC); - if (fd < 0) - return -errno; - - /* This leaves the timezone fields of struct tm - * uninitialized! */ - if (ioctl(fd, RTC_RD_TIME, tm) < 0) - return -errno; - - /* We don't know daylight saving, so we reset this in order not - * to confuse mktime(). */ - tm->tm_isdst = -1; - - return 0; -} - -int hwclock_set_time(const struct tm *tm) { - _cleanup_close_ int fd = -1; - - assert(tm); - - fd = open("/dev/rtc", O_RDONLY|O_CLOEXEC); - if (fd < 0) - return -errno; - - if (ioctl(fd, RTC_SET_TIME, tm) < 0) - return -errno; - - return 0; -} - -int hwclock_is_localtime(void) { - _cleanup_fclose_ FILE *f; - - /* - * The third line of adjtime is "UTC" or "LOCAL" or nothing. - * # /etc/adjtime - * 0.0 0 0 - * 0 - * UTC - */ - f = fopen("/etc/adjtime", "re"); - if (f) { - char line[LINE_MAX]; - bool b; - - b = fgets(line, sizeof(line), f) && - fgets(line, sizeof(line), f) && - fgets(line, sizeof(line), f); - if (!b) - return -EIO; - - truncate_nl(line); - return streq(line, "LOCAL"); - - } else if (errno != ENOENT) - return -errno; - - return 0; -} - -int hwclock_set_timezone(int *min) { - const struct timeval *tv_null = NULL; - struct timespec ts; - struct tm *tm; - int minutesdelta; - struct timezone tz; - - assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0); - assert_se(tm = localtime(&ts.tv_sec)); - minutesdelta = tm->tm_gmtoff / 60; - - tz.tz_minuteswest = -minutesdelta; - tz.tz_dsttime = 0; /* DST_NONE*/ - - /* - * If the hardware clock does not run in UTC, but in local time: - * The very first time we set the kernel's timezone, it will warp - * the clock so that it runs in UTC instead of local time. - */ - if (settimeofday(tv_null, &tz) < 0) - return -errno; - if (min) - *min = minutesdelta; - return 0; -} - -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 timezone with next call. - */ - if (settimeofday(tv_null, &tz) < 0) - return -errno; - - return 0; -} diff --git a/src/shared/hwclock.h b/src/shared/hwclock.h deleted file mode 100644 index 4330b8ea87..0000000000 --- a/src/shared/hwclock.h +++ /dev/null @@ -1,28 +0,0 @@ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -#pragma once - -/*** - This file is part of systemd. - - Copyright 2010-2012 Lennart Poettering - - systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - systemd is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with systemd; If not, see . -***/ - -int hwclock_is_localtime(void); -int hwclock_set_timezone(int *min); -int hwclock_reset_timezone(void); -int hwclock_get_time(struct tm *tm); -int hwclock_set_time(const struct tm *tm); diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 3e0f70cfdc..95255def29 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -31,7 +31,7 @@ #include "util.h" #include "strv.h" #include "def.h" -#include "hwclock.h" +#include "clock-util.h" #include "conf-files.h" #include "path-util.h" #include "fileio-label.h" @@ -153,7 +153,7 @@ have_timezone: c->zone = NULL; } - c->local_rtc = hwclock_is_localtime() > 0; + c->local_rtc = clock_is_localtime() > 0; return 0; } @@ -465,7 +465,7 @@ static int property_get_rtc_time( int r; zero(tm); - r = hwclock_get_time(&tm); + r = clock_get_time(&tm); if (r == -EBUSY) { log_warning("/dev/rtc is busy. Is somebody keeping it open continuously? That's not a good idea... Returning a bogus RTC timestamp."); t = 0; @@ -546,7 +546,7 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata, s } /* 2. Tell the kernel our timezone */ - hwclock_set_timezone(NULL); + clock_set_timezone(NULL); if (c->local_rtc) { struct timespec ts; @@ -555,7 +555,7 @@ static int method_set_timezone(sd_bus *bus, sd_bus_message *m, void *userdata, s /* 3. Sync RTC from system clock, with the new delta */ assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0); assert_se(tm = localtime(&ts.tv_sec)); - hwclock_set_time(tm); + clock_set_time(tm); } log_struct(LOG_INFO, @@ -602,7 +602,7 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata, } /* 2. Tell the kernel our timezone */ - hwclock_set_timezone(NULL); + clock_set_timezone(NULL); /* 3. Synchronize clocks */ assert_se(clock_gettime(CLOCK_REALTIME, &ts) == 0); @@ -621,7 +621,7 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata, /* Override the main fields of * struct tm, but not the timezone * fields */ - if (hwclock_get_time(&tm) >= 0) { + if (clock_get_time(&tm) >= 0) { /* And set the system clock * with this */ @@ -642,7 +642,7 @@ static int method_set_local_rtc(sd_bus *bus, sd_bus_message *m, void *userdata, else tm = gmtime(&ts.tv_sec); - hwclock_set_time(tm); + clock_set_time(tm); } log_info("RTC configured to %s time.", c->local_rtc ? "local" : "UTC"); @@ -706,7 +706,7 @@ static int method_set_time(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu else tm = gmtime(&ts.tv_sec); - hwclock_set_time(tm); + clock_set_time(tm); log_struct(LOG_INFO, MESSAGE_ID(SD_MESSAGE_TIME_CHANGE), -- cgit v1.2.3-54-g00ecf