diff mbox series

[wrynose,v3,6/8] systemd-systemctl-native: add systemd-hwdb

Message ID 20261117115126.14374-7-jaipaul.cheernam@est.tech
State New
Headers show
Series Systemd 259.10 upgrade | expand

Commit Message

Jaipaul Cheernam Nov. 17, 2026, 11:51 a.m. UTC
From: Ross Burton <ross.burton@arm.com>

Also build systemd-hwdb so that we can generate hwdb.bin at rootfs time
with native code instead of using qemu-user. I've verified that the
hwdb.bin format is word-size and endian agnosic, so we don't need to use
qemu.

Add a patch so that source file names in the hwdb.bin have the rootfs
prefix stripped, so that build paths don't appear in the final image.

This does mean we have to hardcode prefix=/usr sysconfdir=/etc as the
target paths, but systemd effectively mandates these so hopefully this
is not a problem in the real world.

Partially based on work by Daniel Turull.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 2a7c2ddd739db59bc14d781aa919bdd4724b365e)

Note: applied to the wrynose systemd-systemctl-native recipe (not renamed to
systemd-tools-native). Kept our MESON_TARGET ":executable" qualifier,
-Dpam=disabled and the systemd-sysv-install do_install; DEPENDS is left as-is.
The strip-the-root patch is only needed on 259.5 and is dropped again in the
259.10 uplift, where it is already upstream.
Signed-off-by: Jaipaul Cheernam <jaipaul.cheernam@est.tech>
---
 .../systemd/systemd-systemctl-native_259.5.bb | 24 ++++++++---
 ...oot-from-filenames-when-generating-h.patch | 40 +++++++++++++++++++
 2 files changed, 58 insertions(+), 6 deletions(-)
 create mode 100644 meta/recipes-core/systemd/systemd/0001-hwdb-strip-the-root-from-filenames-when-generating-h.patch
diff mbox series

Patch

diff --git a/meta/recipes-core/systemd/systemd-systemctl-native_259.5.bb b/meta/recipes-core/systemd/systemd-systemctl-native_259.5.bb
index 3c0dcd35a3..34f64e2eb9 100644
--- a/meta/recipes-core/systemd/systemd-systemctl-native_259.5.bb
+++ b/meta/recipes-core/systemd/systemd-systemctl-native_259.5.bb
@@ -4,20 +4,28 @@  SUMMARY = "Systemctl executable from systemd"
 
 require systemd.inc
 
+SRC_URI += "file://0001-hwdb-strip-the-root-from-filenames-when-generating-h.patch"
+
 DEPENDS = "gperf-native libcap-native util-linux-native python3-jinja2-native"
 
 inherit pkgconfig meson native
 
-MESON_TARGET = "systemctl:executable"
+MESON_TARGET = "systemctl:executable systemd-hwdb:executable"
 MESON_INSTALL_TAGS = "systemctl"
-EXTRA_OEMESON += "-Dlink-systemctl-shared=false"
+
+# Link the binaries statically as we don't install libsystemd-shared.so
+EXTRA_OEMESON += "-Dlink-systemctl-shared=false -Dlink-udev-shared=false"
 EXTRA_OEMESON += "-Dsysvinit-path= -Dsysvrcnd-path="
 EXTRA_OEMESON += "-Dpam=disabled"
 
-# Systemctl is supposed to operate on target, but the target sysroot is not
-# determined at run-time, but rather set during configure
-# More details are here https://github.com/systemd/systemd/issues/35897#issuecomment-2665405887
-EXTRA_OEMESON += "--sysconfdir ${sysconfdir_native}"
+# Target-absolute paths that satisfy both tools from one meson configure:
+#  - systemd-hwdb needs prefix=/usr so the compiled-in UDEVLIBEXECDIR
+#    (/usr/lib/udev) matches the target rootfs layout, letting
+#    "update --root $D --usr" find hwdb.d sources and write hwdb.bin there.
+#  - systemctl needs sysconfdir=/etc; it operates on the target rootfs but the
+#    sysroot is fixed at configure time rather than run time.
+#    See https://github.com/systemd/systemd/issues/35897#issuecomment-2665405887
+EXTRA_OEMESON += "--prefix /usr --sysconfdir /etc"
 
 do_install:append() {
 	# Install systemd-sysv-install in /usr/bin rather than /usr/lib/systemd
@@ -26,4 +34,8 @@  do_install:append() {
 	# with version 259 of systemd and then this, and everything that was
 	# added along with it, should be reverted.
 	install -Dm 0755 ${S}/src/systemctl/systemd-sysv-install.SKELETON ${D}${bindir}/systemd-sysv-install
+
+	# Can't install this with a tag "hwdb" also tries to install the hwdb
+	# itself, and there's no separate tag for systemd-hwdb.
+	install ${B}/systemd-hwdb ${D}${bindir}/systemd-hwdb
 }
diff --git a/meta/recipes-core/systemd/systemd/0001-hwdb-strip-the-root-from-filenames-when-generating-h.patch b/meta/recipes-core/systemd/systemd/0001-hwdb-strip-the-root-from-filenames-when-generating-h.patch
new file mode 100644
index 0000000000..f11199c553
--- /dev/null
+++ b/meta/recipes-core/systemd/systemd/0001-hwdb-strip-the-root-from-filenames-when-generating-h.patch
@@ -0,0 +1,40 @@ 
+From 0031715c560e8138cc320f017a0a2c7160b1f7fe Mon Sep 17 00:00:00 2001
+From: Ross Burton <ross.burton@arm.com>
+Date: Fri, 17 Jul 2026 17:25:31 +0100
+Subject: [PATCH] hwdb: strip the root from filenames when generating hwdb.bin
+
+The modern hwdb.bin format contains the filenames of the input data that
+makes up the database.  This is useful but in offline builds where
+--root is used, the filenames are the full build paths including the
+specified root.  This introduces build paths and thus information
+leakage and non-reproducible data.
+
+Solve this by stripping the root prefix off the original path when
+passing to import_file.
+
+Upstream-Status: Backport [https://github.com/systemd/systemd/pull/43062]
+Signed-off-by: Ross Burton <ross.burton@arm.com>
+---
+ src/shared/hwdb-util.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/src/shared/hwdb-util.c b/src/shared/hwdb-util.c
+index b42681a289..5386b4e9f4 100644
+--- a/src/shared/hwdb-util.c
++++ b/src/shared/hwdb-util.c
+@@ -632,9 +632,11 @@ int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool co
+ 
+         FOREACH_ARRAY(i, files, n_files) {
+                 ConfFile *c = *i;
++                char *path_in_root;
+ 
+                 log_debug("Reading file \"%s\" -> \"%s\"", c->original_path, c->resolved_path);
+-                RET_GATHER(ret, import_file(trie, c->fd, c->original_path, file_priority++, compat));
++                path_in_root = path_startswith_full(c->original_path, empty_to_root(root), PATH_STARTSWITH_RETURN_LEADING_SLASH);
++                RET_GATHER(ret, import_file(trie, c->fd, path_in_root, file_priority++, compat));
+         }
+ 
+         strbuf_complete(trie->strings);
+-- 
+2.43.0
+