summaryrefslogtreecommitdiffstats
path: root/src/shared/discover-image.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-04-01 15:49:22 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-04 17:52:56 +0200
commitf7b5f39934c145a2afdf9de27f61b6e15fcccea7 (patch)
treefc86d357198d776c0b8d42d184c606d2e54ec41e /src/shared/discover-image.c
parentspecifier: always convert missing machine-id file to EUNATCH (diff)
downloadsystemd-f7b5f39934c145a2afdf9de27f61b6e15fcccea7.tar.xz
systemd-f7b5f39934c145a2afdf9de27f61b6e15fcccea7.zip
discover-image: use id128_get_machine() at one more place
Diffstat (limited to 'src/shared/discover-image.c')
-rw-r--r--src/shared/discover-image.c20
1 files changed, 3 insertions, 17 deletions
diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c
index 6aff9fbb30..eed0a5629e 100644
--- a/src/shared/discover-image.c
+++ b/src/shared/discover-image.c
@@ -1173,23 +1173,9 @@ int image_read_metadata(Image *i) {
path = mfree(path);
- r = chase("/etc/machine-id", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
- if (r < 0 && r != -ENOENT)
- log_debug_errno(r, "Failed to chase /etc/machine-id in image %s: %m", i->name);
- else if (r >= 0) {
- _cleanup_close_ int fd = -EBADF;
-
- fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
- if (fd < 0)
- log_debug_errno(errno, "Failed to open %s: %m", path);
- else {
- r = id128_read_fd(fd, ID128_FORMAT_PLAIN, &machine_id);
- if (r < 0)
- log_debug_errno(r, "Image %s contains invalid machine ID.", i->name);
- }
- }
-
- path = mfree(path);
+ r = id128_get_machine(i->path, &machine_id);
+ if (r < 0)
+ log_debug_errno(r, "Failed to read machine ID in image %s, ignoring: %m", i->name);
r = chase("/etc/machine-info", i->path, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &path, NULL);
if (r < 0 && r != -ENOENT)