Merge ~robert-ancell/ubuntu/+source/systemd:etc-writable-timezone into ~ubuntu-core-dev/ubuntu/+source/systemd:ubuntu-kinetic

Proposed by Robert Ancell
Status: Rejected
Rejected by: Robert Ancell
Proposed branch: ~robert-ancell/ubuntu/+source/systemd:etc-writable-timezone
Merge into: ~ubuntu-core-dev/ubuntu/+source/systemd:ubuntu-kinetic
Diff against target: 147 lines (+116/-0)
4 files modified
debian/changelog (+9/-0)
debian/patches/debian/UBUNTU-firstboot-timezone.patch (+55/-0)
debian/patches/debian/UBUNTU-inotify-timezone.patch (+50/-0)
debian/patches/series (+2/-0)
Reviewer Review Type Date Requested Status
Nick Rosbrook Needs Information
Review via email: mp+426518@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nick Rosbrook (enr0n) wrote :

I have a few questions, because LP: #1981042 does not provide any detail beyond the existing background of why systemd is patched to workaround Ubuntu Core's /etc/writable:

1. What version of systemd is this being observed in? The patches reference the 249.11 source from jammy, but you have proposed it into kinetc.

2. If the intended target really is kinetic, do we really need to bring this into the devel release? Has there been any progress on fixing Ubuntu Core [1] so that we can stop carrying these patches in systemd?

3. If the intended target is jammy, it would need an SRU and a strong justification.

[1] https://bugs.launchpad.net/snappy/+bug/1953172

review: Needs Information
Revision history for this message
Robert Ancell (robert-ancell) wrote :

1. Observed in all versions of systemd, as systemd assumes that /etc/locatime is a writable location.

2. Proposing to bring it into kinetic so it can be SRUd to jammy, which is the version we are using to build core based desktop images with. I wasn't aware of any progress on a better solution, but I'll contact Valentin about the bug you linked against. Note the linked git branch only seems to consolidate these patches, it doesn't have any new solution AFAICT.

3. See above.

Revision history for this message
Nick Rosbrook (enr0n) wrote :

Understood. I will add rls tags to the bug so that we can discuss in the next Foundations meeting.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

Unmerged commits

c9bd437... by Robert Ancell

Fix timezone not working on read-only /etc (e.g. Ubuntu Core and system-image-based systems)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/changelog b/debian/changelog
index fce5cca..dd15247 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
1systemd (251.2-2ubuntu2) kinetic; urgency=medium
2
3 * debian/patches/debian/UBUNTU-firstboot-timezone.patch:
4 * debian/patches/debian/UBUNTU-inotify-timezone.patch:
5 - Fix timezone not working on read-only /etc (e.g. Ubuntu Core and
6 system-image-based systems) (LP: #1981042)
7
8 -- Robert Ancell <robert.ancell@canonical.com> Fri, 08 Jul 2022 12:35:44 +1200
9
1systemd (251.2-2ubuntu1) kinetic; urgency=medium10systemd (251.2-2ubuntu1) kinetic; urgency=medium
211
3 [ Nick Rosbrook ]12 [ Nick Rosbrook ]
diff --git a/debian/patches/debian/UBUNTU-firstboot-timezone.patch b/debian/patches/debian/UBUNTU-firstboot-timezone.patch
4new file mode 10064413new file mode 100644
index 0000000..cec5cf9
--- /dev/null
+++ b/debian/patches/debian/UBUNTU-firstboot-timezone.patch
@@ -0,0 +1,55 @@
1Description: On Ubuntu Core /etc/localtime is a symlink, so it needs to be
2 resolved first before finding the file it is linked to.
3Index: systemd-249.11/src/firstboot/firstboot.c
4===================================================================
5--- systemd-249.11.orig/src/firstboot/firstboot.c
6+++ systemd-249.11/src/firstboot/firstboot.c
7@@ -459,18 +459,37 @@ static int prompt_timezone(void) {
8 return 0;
9 }
10
11+/* Hack for Ubuntu Phone/Core: check if path is an existing symlink to
12+ * /etc/writable; if it is, update that instead */
13+static const char* writable_filename(const char *path) {
14+ ssize_t r;
15+ static char realfile_buf[PATH_MAX];
16+ _cleanup_free_ char *realfile = NULL;
17+ const char *result = path;
18+ int orig_errno = errno;
19+
20+ r = readlink_and_make_absolute(path, &realfile);
21+ if (r >= 0 && startswith(realfile, "/etc/writable")) {
22+ snprintf(realfile_buf, sizeof(realfile_buf), "%s", realfile);
23+ result = realfile_buf;
24+ }
25+
26+ errno = orig_errno;
27+ return result;
28+}
29+
30 static int process_timezone(void) {
31 const char *etc_localtime, *e;
32 int r;
33
34- etc_localtime = prefix_roota(arg_root, "/etc/localtime");
35+ etc_localtime = prefix_roota(arg_root, writable_filename("/etc/localtime"));
36 if (laccess(etc_localtime, F_OK) >= 0 && !arg_force)
37 return 0;
38
39 if (arg_copy_timezone && arg_root) {
40 _cleanup_free_ char *p = NULL;
41
42- r = readlink_malloc("/etc/localtime", &p);
43+ r = readlink_malloc(writable_filename("/etc/localtime"), &p);
44 if (r != -ENOENT) {
45 if (r < 0)
46 return log_error_errno(r, "Failed to read host timezone: %m");
47@@ -491,7 +510,7 @@ static int process_timezone(void) {
48 if (isempty(arg_timezone))
49 return 0;
50
51- e = strjoina("../usr/share/zoneinfo/", arg_timezone);
52+ e = strjoina("/usr/share/zoneinfo/", arg_timezone);
53
54 (void) mkdir_parents(etc_localtime, 0755);
55 if (symlink(e, etc_localtime) < 0)
diff --git a/debian/patches/debian/UBUNTU-inotify-timezone.patch b/debian/patches/debian/UBUNTU-inotify-timezone.patch
0new file mode 10064456new file mode 100644
index 0000000..dccfb2f
--- /dev/null
+++ b/debian/patches/debian/UBUNTU-inotify-timezone.patch
@@ -0,0 +1,50 @@
1Description: On Ubuntu Core /etc/localtime is a symlink, so it needs to be
2 resolved to perform the inotify correctly.
3Index: systemd-249.11/src/core/manager.c
4===================================================================
5--- systemd-249.11.orig/src/core/manager.c
6+++ systemd-249.11/src/core/manager.c
7@@ -400,6 +400,25 @@ static int manager_setup_time_change(Man
8 return 0;
9 }
10
11+/* Hack for Ubuntu Phone/Core: check if path is an existing symlink to
12+ * /etc/writable; if it is, update that instead */
13+static const char* writable_filename(const char *path) {
14+ ssize_t r;
15+ static char realfile_buf[PATH_MAX];
16+ _cleanup_free_ char *realfile = NULL;
17+ const char *result = path;
18+ int orig_errno = errno;
19+
20+ r = readlink_and_make_absolute(path, &realfile);
21+ if (r >= 0 && startswith(realfile, "/etc/writable")) {
22+ snprintf(realfile_buf, sizeof(realfile_buf), "%s", realfile);
23+ result = realfile_buf;
24+ }
25+
26+ errno = orig_errno;
27+ return result;
28+}
29+
30 static int manager_read_timezone_stat(Manager *m) {
31 struct stat st;
32 bool changed;
33@@ -407,7 +426,7 @@ static int manager_read_timezone_stat(Ma
34 assert(m);
35
36 /* Read the current stat() data of /etc/localtime so that we detect changes */
37- if (lstat("/etc/localtime", &st) < 0) {
38+ if (lstat(writable_filename("/etc/localtime"), &st) < 0) {
39 log_debug_errno(errno, "Failed to stat /etc/localtime, ignoring: %m");
40 changed = m->etc_localtime_accessible;
41 m->etc_localtime_accessible = false;
42@@ -444,7 +463,7 @@ static int manager_setup_timezone_change
43 * Note that we create the new event source first here, before releasing the old one. This should optimize
44 * behaviour as this way sd-event can reuse the old watch in case the inode didn't change. */
45
46- r = sd_event_add_inotify(m->event, &new_event, "/etc/localtime",
47+ r = sd_event_add_inotify(m->event, &new_event, writable_filename("/etc/localtime"),
48 IN_ATTRIB|IN_MOVE_SELF|IN_CLOSE_WRITE|IN_DONT_FOLLOW, manager_dispatch_timezone_change, m);
49 if (r == -ENOENT) {
50 /* If the file doesn't exist yet, subscribe to /etc instead, and wait until it is created either by
diff --git a/debian/patches/series b/debian/patches/series
index 503bef3..0faee82 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -29,6 +29,8 @@ debian/UBUNTU-test-sleep-skip-test_fiemap-upon-inapproriate-ioctl-.patch
29debian/UBUNTU-Support-system-image-read-only-etc.patch29debian/UBUNTU-Support-system-image-read-only-etc.patch
30debian/timedatectl-lp1650688.patch30debian/timedatectl-lp1650688.patch
31debian/UBUNTU-Fix-timezone-setting-on-read-only-etc.patch31debian/UBUNTU-Fix-timezone-setting-on-read-only-etc.patch
32debian/UBUNTU-inotify-timezone.patch
33debian/UBUNTU-firstboot-timezone.patch
32debian/UBUNTU-Revert-namespace-be-more-careful-when-handling-namespacin.patch34debian/UBUNTU-Revert-namespace-be-more-careful-when-handling-namespacin.patch
33debian/UBUNTU-Revert-cgroup-Continue-unit-reset-if-cgroup-is-busy.patch35debian/UBUNTU-Revert-cgroup-Continue-unit-reset-if-cgroup-is-busy.patch
34debian/UBUNTU-resolved-default-no-negative-caching.patch36debian/UBUNTU-resolved-default-no-negative-caching.patch

Subscribers

People subscribed via source and target branches