Commit 1d3d62b1 authored by Marek Belisko's avatar Marek Belisko
Browse files

systemd: Fix timezone changes


Signed-off-by: default avatarMarek Belisko <marek.belisko@open-nandra.com>
parent 1fe1b594
From fa33bb1c844bf80899a192ae2183ca5ba4cecc9b Mon Sep 17 00:00:00 2001
From 9981f002eeed91c698c2394d7c597fd7c3794695 Mon Sep 17 00:00:00 2001
From: Marek Belisko <marek.belisko@open-nandra.com>
Date: Mon, 8 Feb 2021 22:07:02 +0100
Subject: [PATCH] Move localtime to /data partition
Date: Mon, 22 Mar 2021 13:15:23 +0100
Subject: [PATCH] timedated.c: change timezone link path
On a mender/read-only enabled system, the /etc/localtime could be a
symbolic link to /data/etc/localtime, let it behave so.
Signed-off-by: Marek Belisko <marek.belisko@open-nandra.com>
---
src/basic/time-util.c | 2 +-
src/core/manager.c | 10 +++++-----
src/firstboot/firstboot.c | 4 ++--
src/nspawn/nspawn.c | 10 +++++-----
src/timedate/timedated.c | 10 +++++-----
5 files changed, 18 insertions(+), 18 deletions(-)
src/basic/time-util.c | 2 +-
src/core/manager.c | 6 +++---
src/firstboot/firstboot.c | 4 ++--
src/nspawn/nspawn.c | 6 +++---
src/timedate/timedated.c | 9 ++++-----
5 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 105584e..85ec381 100644
......@@ -26,21 +29,19 @@ index 105584e..85ec381 100644
/* If the symlink does not exist, assume "UTC", like glibc does*/
z = strdup("UTC");
diff --git a/src/core/manager.c b/src/core/manager.c
index 13a6b49..79e15d0 100644
index 13a6b49..6116452 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -386,8 +386,8 @@ static int manager_read_timezone_stat(Manager *m) {
@@ -386,7 +386,7 @@ static int manager_read_timezone_stat(Manager *m) {
assert(m);
/* Read the current stat() data of /etc/localtime so that we detect changes */
- if (lstat("/etc/localtime", &st) < 0) {
- log_debug_errno(errno, "Failed to stat /etc/localtime, ignoring: %m");
+ if (lstat("/data/etc/localtime", &st) < 0) {
+ log_debug_errno(errno, "Failed to stat /data/etc/localtime, ignoring: %m");
log_debug_errno(errno, "Failed to stat /etc/localtime, ignoring: %m");
changed = m->etc_localtime_accessible;
m->etc_localtime_accessible = false;
} else {
@@ -423,13 +423,13 @@ static int manager_setup_timezone_change(Manager *m) {
@@ -423,14 +423,14 @@ static int manager_setup_timezone_change(Manager *m) {
* Note that we create the new event source first here, before releasing the old one. This should optimize
* behaviour as this way sd-event can reuse the old watch in case the inode didn't change. */
......@@ -51,20 +52,12 @@ index 13a6b49..79e15d0 100644
/* If the file doesn't exist yet, subscribe to /etc instead, and wait until it is created either by
* O_CREATE or by rename() */
- log_debug_errno(r, "/etc/localtime doesn't exist yet, watching /etc instead.");
+ log_debug_errno(r, "/data/etc/localtime doesn't exist yet, watching /etc instead.");
r = sd_event_add_inotify(m->event, &new_event, "/etc",
log_debug_errno(r, "/etc/localtime doesn't exist yet, watching /etc instead.");
- r = sd_event_add_inotify(m->event, &new_event, "/etc",
+ r = sd_event_add_inotify(m->event, &new_event, "/data/etc",
IN_CREATE|IN_MOVED_TO|IN_ONLYDIR, manager_dispatch_timezone_change, m);
}
@@ -2804,7 +2804,7 @@ static int manager_dispatch_timezone_change(
assert(m);
- log_debug("inotify event for /etc/localtime");
+ log_debug("inotify event for /data/etc/localtime");
changed = manager_read_timezone_stat(m);
if (changed <= 0)
if (r < 0)
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 528e645..845d817 100644
--- a/src/firstboot/firstboot.c
......@@ -87,19 +80,10 @@ index 528e645..845d817 100644
if (r < 0)
return log_error_errno(r, "Failed to read host timezone: %m");
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 873a765..08394f2 100644
index 873a765..de067d8 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1422,7 +1422,7 @@ static int parse_argv(int argc, char *argv[]) {
arg_timezone = timezone_mode_from_string(optarg);
if (arg_timezone < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "Failed to parse /etc/localtime mode: %s", optarg);
+ "Failed to parse /data/etc/localtime mode: %s", optarg);
arg_settings_mask |= SETTING_TIMEZONE;
break;
@@ -1659,13 +1659,13 @@ static int setup_timezone(const char *dest) {
@@ -1659,7 +1659,7 @@ static int setup_timezone(const char *dest) {
assert(dest);
if (IN_SET(arg_timezone, TIMEZONE_AUTO, TIMEZONE_SYMLINK)) {
......@@ -108,13 +92,6 @@ index 873a765..08394f2 100644
if (r == -ENOENT && arg_timezone == TIMEZONE_AUTO)
m = etc_writable() ? TIMEZONE_DELETE : TIMEZONE_OFF;
else if (r == -EINVAL && arg_timezone == TIMEZONE_AUTO) /* regular file? */
m = etc_writable() ? TIMEZONE_COPY : TIMEZONE_BIND;
else if (r < 0) {
- log_warning_errno(r, "Failed to read host's /etc/localtime symlink, not updating container timezone: %m");
+ log_warning_errno(r, "Failed to read host's /data/etc/localtime symlink, not updating container timezone: %m");
/* To handle warning, delete /etc/localtime and replace it with a symbolic link to a time zone data
* file.
*
@@ -1750,7 +1750,7 @@ static int setup_timezone(const char *dest) {
if (found == 0) /* missing? */
(void) touch(resolved);
......@@ -134,19 +111,15 @@ index 873a765..08394f2 100644
log_full_errno(IN_SET(r, -EROFS, -EACCES, -EPERM) ? LOG_DEBUG : LOG_WARNING, r,
"Failed to copy /etc/localtime to %s, ignoring: %m", where);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 5e2fb50..e6adec4 100644
index 5e2fb50..61d03d4 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -264,7 +264,7 @@ static int context_read_data(Context *c) {
r = get_timezone(&t);
if (r == -EINVAL)
- log_warning_errno(r, "/etc/localtime should be a symbolic link to a time zone data file in /usr/share/zoneinfo/.");
+ log_warning_errno(r, "/data/etc/localtime should be a symbolic link to a time zone data file in /usr/share/zoneinfo/.");
else if (r < 0)
log_warning_errno(r, "Failed to get target of /etc/localtime: %m");
@@ -290,22 +290,22 @@ static int context_write_data_timezone(Context *c) {
@@ -285,27 +285,26 @@ static int context_write_data_timezone(Context *c) {
* it isn't installed, in which case we remove the symlink altogether. Since glibc defaults to an
* internal version of UTC in that case behaviour is mostly equivalent. We still prefer creating the
* symlink though, since things are more self explanatory then. */
-
if (isempty(c->zone) || streq(c->zone, "UTC")) {
if (access("/usr/share/zoneinfo/UTC", F_OK) < 0) {
......
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI_append = " \
file://init.sh \
file://0001-Move-localtime-to-data-partition.patch \
file://init.sh \
file://0001-Move-localtime-to-data-partition.patch \
"
do_install_append() {
......@@ -14,9 +14,6 @@ do_install_append() {
# systemd services should have read-write permission to /etc and /data/etc
sed -i -e "s#\(^ReadWritePaths=.*\)#\1 /data/etc#" ${D}${systemd_unitdir}/system/systemd-timedated.service
install -d ${D}/data/etc/
ln -sf /usr/share/zoneinfo ${D}/data/etc/localtime
}
FILES_${PN} += "${sbindir}/* /data/*"
FILES_${PN} += "${sbindir}/*"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment