Add env variable for machine ID path
authorMartin Pitt <mpitt@debian.org>
Wed, 18 Jan 2017 10:21:35 +0000 (11:21 +0100)
committerLuca Boccassi <bluca@debian.org>
Sat, 27 Aug 2022 21:39:04 +0000 (22:39 +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 09c3401ca10e0958e5ce6780097e7b517175a372..2d4b11721d8aab2fa99ccc3570febb480c9445e3 100644 (file)
@@ -108,7 +108,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 5d9d99e272a5eabd6376909ec935e5ead0672992..9466db6ecc6bb66cc3e945836ea544f1517a3e54 100644 (file)
@@ -215,7 +215,7 @@ TEST(chase_symlinks) {
         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);
 
@@ -288,23 +288,26 @@ TEST(chase_symlinks) {
                 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 */