[systemd-commits] Makefile.am src/core src/hostname src/shared src/timedate
Kay Sievers
kay at kemper.freedesktop.org
Fri May 23 16:04:01 PDT 2014
Makefile.am | 4 -
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 ++---
9 files changed, 201 insertions(+), 201 deletions(-)
New commits:
commit 24efb112451413c1013d5f7fe27d7e2cd407647a
Author: Kay Sievers <kay at vrfy.org>
Date: Thu May 22 21:21:38 2014 +0900
shared: rename hwclock.[ch] to clock-util.[ch]
diff --git a/Makefile.am b/Makefile.am
index cd7b6a3..f517f19 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -758,8 +758,8 @@ libsystemd_shared_la_SOURCES = \
src/shared/replace-var.h \
src/shared/spawn-polkit-agent.c \
src/shared/spawn-polkit-agent.h \
- src/shared/hwclock.c \
- src/shared/hwclock.h \
+ src/shared/clock-util.c \
+ src/shared/clock-util.h \
src/shared/time-dst.c \
src/shared/time-dst.h \
src/shared/calendarspec.c \
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index d5fab0a..333c1d4 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 74c50f5..77cc2fb 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 70049d3..267cd74 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 0000000..1553573
--- /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 <http://www.gnu.org/licenses/>.
+***/
+
+#include <assert.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <sys/prctl.h>
+#include <sys/time.h>
+#include <linux/rtc.h>
+
+#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 0000000..63d96fc
--- /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 <http://www.gnu.org/licenses/>.
+***/
+
+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 7059d9c..0000000
--- 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 <http://www.gnu.org/licenses/>.
-***/
-
-#include <assert.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <sys/prctl.h>
-#include <sys/time.h>
-#include <linux/rtc.h>
-
-#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 4330b8e..0000000
--- 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 <http://www.gnu.org/licenses/>.
-***/
-
-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 3e0f70c..95255de 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),
More information about the systemd-commits
mailing list