From 6a51a4682bcbe1ad2ac52aa0b469dd44bfe741c0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 19 Apr 2018 10:33:57 +0200 Subject: [PATCH 1/5] mkosi: ensure the 'hostname' tool is available in the build environment Our test-execute test uses 'hostname' to validate specifiers, hence it should be available in our mkosi build too, so that the test can pass. --- .mkosi/mkosi.fedora | 1 + 1 file changed, 1 insertion(+) diff --git a/.mkosi/mkosi.fedora b/.mkosi/mkosi.fedora index 28008745c5..7f1b555efa 100644 --- a/.mkosi/mkosi.fedora +++ b/.mkosi/mkosi.fedora @@ -34,6 +34,7 @@ BuildPackages= gnu-efi-devel gnutls-devel gperf + hostname iptables-devel kmod-devel libacl-devel From 8f63253149356e3aaa3545271e6f3654f7a6e5e7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 19 Apr 2018 10:34:58 +0200 Subject: [PATCH 2/5] core: don't export per-unit metadata files in test mode We shouldn't clobber the host's /run directories with metadata we export for our units when we run in test mode. --- src/core/unit.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/unit.c b/src/core/unit.c index 01e7cc9683..6affc65fe9 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -5169,6 +5169,9 @@ void unit_export_state_files(Unit *u) { if (!MANAGER_IS_SYSTEM(u->manager)) return; + if (u->manager->test_run_flags != 0) + return; + /* Exports a couple of unit properties to /run/systemd/units/, so that journald can quickly query this data * from there. Ideally, journald would use IPC to query this, like everybody else, but that's hard, as long as * the IPC system itself and PID 1 also log to the journal. From 63d6135feaf685b8d2822d18a829dcee1187ba4f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 19 Apr 2018 10:35:36 +0200 Subject: [PATCH 3/5] tests: compare with correct shell We synthesize the passwd record for UID 0, hence we need to compare with our synthesized data and not with the data stored in /etc/passwd --- src/test/test-execute.c | 1 + test/test-execute/exec-specifier.service | 2 +- test/test-execute/exec-specifier@.service | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 59d996c11b..2b5706822c 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -686,6 +686,7 @@ int main(int argc, char *argv[]) { (void) unsetenv("USER"); (void) unsetenv("LOGNAME"); + (void) unsetenv("SHELL"); /* It is needed otherwise cgroup creation fails */ if (getuid() != 0) { diff --git a/test/test-execute/exec-specifier.service b/test/test-execute/exec-specifier.service index 65a64bc95e..727d77f612 100644 --- a/test/test-execute/exec-specifier.service +++ b/test/test-execute/exec-specifier.service @@ -17,7 +17,7 @@ ExecStart=test %L = /var/log ExecStart=sh -c 'test %u = $$(id -un 0)' ExecStart=test %U = 0 ExecStart=sh -c 'test %h = $$(getent passwd 0 | cut -d: -f 6)' -ExecStart=sh -c 'test %s = $$(getent passwd 0 | cut -d: -f 7)' +ExecStart=sh -c 'test %s = /bin/sh' ExecStart=sh -c 'test %m = $$(cat /etc/machine-id)' ExecStart=sh -c 'test %b = $$(cat /proc/sys/kernel/random/boot_id | sed -e 's/-//g')' ExecStart=sh -c 'test %H = $$(hostname)' diff --git a/test/test-execute/exec-specifier@.service b/test/test-execute/exec-specifier@.service index f8d7dce680..1b69e60843 100644 --- a/test/test-execute/exec-specifier@.service +++ b/test/test-execute/exec-specifier@.service @@ -17,7 +17,7 @@ ExecStart=test %L = /var/log ExecStart=sh -c 'test %u = $$(id -un 0)' ExecStart=test %U = 0 ExecStart=sh -c 'test %h = $$(getent passwd 0 | cut -d: -f 6)' -ExecStart=sh -c 'test %s = $$(getent passwd 0 | cut -d: -f 7)' +ExecStart=sh -c 'test %s = /bin/sh' ExecStart=sh -c 'test %m = $$(cat /etc/machine-id)' ExecStart=sh -c 'test %b = $$(cat /proc/sys/kernel/random/boot_id | sed -e 's/-//g')' ExecStart=sh -c 'test %H = $$(hostname)' From 5b3325fedfefff4f7077faf20abf8a831fbf9474 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 19 Apr 2018 11:16:04 +0200 Subject: [PATCH 4/5] mkosi: drop dumping all test output to console again As it appears meson's test cases nowadays (?) show useful logs for failing tests anyway, hence there's no need to show them unconditionally in full every time anymore. Let's hence simplify and drop this. --- mkosi.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkosi.build b/mkosi.build index 093a586b83..ee9f7d95ad 100755 --- a/mkosi.build +++ b/mkosi.build @@ -84,7 +84,7 @@ if [ ! -f "$BUILDDIR"/build.ninja ] ; then fi ninja -C "$BUILDDIR" all -[ "$WITH_TESTS" = 0 ] || ninja -C "$BUILDDIR" test || ( RET="$?" ; cat "$BUILDDIR"/meson-logs/testlog.txt ; exit "$RET" ) +[ "$WITH_TESTS" = 0 ] || ninja -C "$BUILDDIR" test ninja -C "$BUILDDIR" install mkdir -p "$DESTDIR"/etc From ad80c6a65546154354725092b6235f3e3556ca02 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 19 Apr 2018 11:40:48 +0200 Subject: [PATCH 5/5] user-util: trivial coding style fixes Use C's downgrade-to-bool feature when comparing pointers against NULL, as we usually do. --- src/basic/user-util.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/basic/user-util.c b/src/basic/user-util.c index 0f0f21dbcf..1adb2366d8 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -775,11 +775,11 @@ int fgetpwent_sane(FILE *stream, struct passwd **pw) { errno = 0; p = fgetpwent(stream); - if (p == NULL && errno != ENOENT) + if (!p && errno != ENOENT) return errno > 0 ? -errno : -EIO; *pw = p; - return p != NULL; + return !!p; } int fgetspent_sane(FILE *stream, struct spwd **sp) { @@ -790,11 +790,11 @@ int fgetspent_sane(FILE *stream, struct spwd **sp) { errno = 0; s = fgetspent(stream); - if (s == NULL && errno != ENOENT) + if (!s && errno != ENOENT) return errno > 0 ? -errno : -EIO; *sp = s; - return s != NULL; + return !!s; } int fgetgrent_sane(FILE *stream, struct group **gr) { @@ -805,11 +805,11 @@ int fgetgrent_sane(FILE *stream, struct group **gr) { errno = 0; g = fgetgrent(stream); - if (g == NULL && errno != ENOENT) + if (!g && errno != ENOENT) return errno > 0 ? -errno : -EIO; *gr = g; - return g != NULL; + return !!g; } #if ENABLE_GSHADOW @@ -821,10 +821,10 @@ int fgetsgent_sane(FILE *stream, struct sgrp **sg) { errno = 0; s = fgetsgent(stream); - if (s == NULL && errno != ENOENT) + if (!s && errno != ENOENT) return errno > 0 ? -errno : -EIO; *sg = s; - return s != NULL; + return !!s; } #endif