Add env variable for machine ID path
authorMartin Pitt <mpitt@debian.org>
Wed, 18 Jan 2017 10:21:35 +0000 (11:21 +0100)
committerMichael Biebl <biebl@debian.org>
Mon, 21 Sep 2020 18:28:36 +0000 (19:28 +0100)
During package build, in minimal chroots, or other systems which do not already
have an /etc/machine-id we get six test failures. Introduce a
$SYSTEMD_MACHINE_ID_PATH environment variable which can specify a location
other than /etc/machine-id, so that the unit tests are independent from the
environment.

Also adjust test-fs-util to not assume that /etc/machine-id exists. Use
/etc/passwd instead which is created by base-files.

Closes: #851445
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=62344

Gbp-Pq: Topic debian
Gbp-Pq: Name Add-env-variable-for-machine-ID-path.patch

src/libsystemd/sd-id128/sd-id128.c
src/test/test-fs-util.c

index 9b38ef0c563206f79b00dc397e9c1c55926d8adb..29b8abe6a5ad98d9668bf4bdf878c66d4c8be615 100644 (file)
@@ -88,7 +88,7 @@ _public_ int sd_id128_get_machine(sd_id128_t *ret) {
         assert_return(ret, -EINVAL);
 
         if (sd_id128_is_null(saved_machine_id)) {
-                r = id128_read("/etc/machine-id", ID128_PLAIN, &saved_machine_id);
+                r = id128_read(getenv("SYSTEMD_MACHINE_ID_PATH") ?: "/etc/machine-id", ID128_PLAIN, &saved_machine_id);
                 if (r < 0)
                         return r;
 
index f2df2e35e623d23f51d2384a3f869180d8853602..7e411cdcdc1e2731761ee1a011dd6f70e2edf16e 100644 (file)
@@ -211,7 +211,7 @@ static void test_chase_symlinks(void) {
         assert_se(streq(result, "/test-chase.fsldajfl"));
         result = mfree(result);
 
-        r = chase_symlinks("/etc/machine-id/foo", NULL, 0, &result, NULL);
+        r = chase_symlinks("/etc/passwd/foo", NULL, 0, &result, NULL);
         assert_se(r == -ENOTDIR);
         result = mfree(result);
 
@@ -284,23 +284,26 @@ static void test_chase_symlinks(void) {
                 assert_se(chase_symlinks(q, NULL, CHASE_SAFE, NULL, NULL) >= 0);
         }
 
-        p = strjoina(temp, "/machine-id-test");
-        assert_se(symlink("/usr/../etc/./machine-id", p) >= 0);
+        p = strjoina(temp, "/passwd-test");
+        assert_se(symlink("/usr/../etc/./passwd", p) >= 0);
 
         r = chase_symlinks(p, NULL, 0, NULL, &pfd);
         if (r != -ENOENT) {
                 _cleanup_close_ int fd = -1;
+/*
                 sd_id128_t a, b;
+*/
 
                 assert_se(pfd >= 0);
 
                 fd = fd_reopen(pfd, O_RDONLY|O_CLOEXEC);
                 assert_se(fd >= 0);
                 safe_close(pfd);
-
+/*
                 assert_se(id128_read_fd(fd, ID128_PLAIN, &a) >= 0);
                 assert_se(sd_id128_get_machine(&b) >= 0);
                 assert_se(sd_id128_equal(a, b));
+*/
         }
 
         /* Test CHASE_NOFOLLOW */