specifier: always convert missing machine-id file to EUNATCH

Then, use id128_get_machine().
This commit is contained in:
Yu Watanabe
2023-04-01 22:48:14 +09:00
parent 319477f1b6
commit edd595f760
2 changed files with 4 additions and 14 deletions

View File

@@ -187,19 +187,9 @@ int specifier_machine_id(char specifier, const void *data, const char *root, con
assert(ret);
if (root) {
_cleanup_close_ int fd = -EBADF;
fd = chase_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NOCTTY, NULL);
if (fd < 0)
/* Translate error for missing os-release file to EUNATCH. */
return fd == -ENOENT ? -EUNATCH : fd;
r = id128_read_fd(fd, ID128_FORMAT_PLAIN, &id);
} else
r = sd_id128_get_machine(&id);
if (r < 0)
return r;
r = id128_get_machine(root, &id);
if (r < 0) /* Translate error for missing /etc/machine-id file to EUNATCH. */
return r == -ENOENT ? -EUNATCH : r;
return specifier_id128(specifier, &id, root, userdata, ret);
}

View File

@@ -136,7 +136,7 @@ TEST(specifiers) {
xsprintf(spec, "%%%c", s->specifier);
r = specifier_printf(spec, SIZE_MAX, specifier_table, NULL, NULL, &resolved);
if (s->specifier == 'm' && IN_SET(r, -ENOENT, -ENOMEDIUM)) /* machine-id might be missing in build chroots */
if (s->specifier == 'm' && IN_SET(r, -EUNATCH, -ENOMEDIUM)) /* machine-id might be missing in build chroots */
continue;
assert_se(r >= 0);