Commit 5a02623d authored by Marek Belisko's avatar Marek Belisko
Browse files

systemd: Fix timezone update


Signed-off-by: default avatarMarek Belisko <marek.belisko@open-nandra.com>
parent 4a65a9ff
From fa33bb1c844bf80899a192ae2183ca5ba4cecc9b 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
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(-)
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index 105584e..85ec381 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1397,7 +1397,7 @@ int get_timezone(char **ret) {
char *z;
int r;
- r = readlink_malloc("/etc/localtime", &t);
+ r = readlink_malloc("/data/etc/localtime", &t);
if (r == -ENOENT) {
/* 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
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -386,8 +386,8 @@ 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");
changed = m->etc_localtime_accessible;
m->etc_localtime_accessible = false;
} else {
@@ -423,13 +423,13 @@ 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. */
- r = sd_event_add_inotify(m->event, &new_event, "/etc/localtime",
+ r = sd_event_add_inotify(m->event, &new_event, "/data/etc/localtime",
IN_ATTRIB|IN_MOVE_SELF|IN_CLOSE_WRITE|IN_DONT_FOLLOW, manager_dispatch_timezone_change, m);
if (r == -ENOENT) {
/* 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",
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)
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 528e645..845d817 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -415,14 +415,14 @@ static int process_timezone(void) {
const char *etc_localtime, *e;
int r;
- etc_localtime = prefix_roota(arg_root, "/etc/localtime");
+ etc_localtime = prefix_roota(arg_root, "/data/etc/localtime");
if (laccess(etc_localtime, F_OK) >= 0)
return 0;
if (arg_copy_timezone && arg_root) {
_cleanup_free_ char *p = NULL;
- r = readlink_malloc("/etc/localtime", &p);
+ r = readlink_malloc("/data/etc/localtime", &p);
if (r != -ENOENT) {
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
--- 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) {
assert(dest);
if (IN_SET(arg_timezone, TIMEZONE_AUTO, TIMEZONE_SYMLINK)) {
- r = readlink_malloc("/etc/localtime", &p);
+ r = readlink_malloc("/data/etc/localtime", &p);
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);
- r = mount_verbose(LOG_WARNING, "/etc/localtime", resolved, NULL, MS_BIND, NULL);
+ r = mount_verbose(LOG_WARNING, "/data/etc/localtime", resolved, NULL, MS_BIND, NULL);
if (r >= 0)
return mount_verbose(LOG_ERR, NULL, resolved, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY|MS_NOSUID|MS_NODEV, NULL);
@@ -1759,7 +1759,7 @@ static int setup_timezone(const char *dest) {
case TIMEZONE_COPY:
/* If mounting failed, try to copy */
- r = copy_file_atomic("/etc/localtime", where, 0644, 0, 0, COPY_REFLINK|COPY_REPLACE);
+ r = copy_file_atomic("/data/etc/localtime", where, 0644, 0, 0, COPY_REFLINK|COPY_REPLACE);
if (r < 0) {
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
--- 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) {
if (access("/usr/share/zoneinfo/UTC", F_OK) < 0) {
- if (unlink("/etc/localtime") < 0 && errno != ENOENT)
+ if (unlink("/data/etc/localtime") < 0 && errno != ENOENT)
return -errno;
return 0;
}
- source = "../usr/share/zoneinfo/UTC";
+ source = "/usr/share/zoneinfo/UTC";
} else {
- p = path_join("../usr/share/zoneinfo", c->zone);
+ p = path_join("/usr/share/zoneinfo", c->zone);
if (!p)
return -ENOMEM;
source = p;
}
- return symlink_atomic(source, "/etc/localtime");
+ return symlink_atomic(source, "/data/etc/localtime");
}
static int context_write_data_local_rtc(Context *c) {
--
2.7.4
......@@ -2,6 +2,7 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI_append = " \
file://init.sh \
file://0001-Move-localtime-to-data-partition.patch \
"
do_install_append() {
......@@ -10,6 +11,12 @@ do_install_append() {
# we use custom script before running of systemd
ln -sf /usr/sbin/init.sh ${D}/sbin/init
# 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}/*"
FILES_${PN} += "${sbindir}/* /data/*"
Supports Markdown
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