summaryrefslogtreecommitdiff
path: root/src/partition
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-31 16:00:37 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-05 00:52:56 +0900
commit5ee37b703e686782be565b2d0638c5488770141e (patch)
treed514805400bb9b6352bfa84cd6842c3ba0470d4e /src/partition
parent1adbc2a4283ded14b89bec69bd97b9d189425278 (diff)
downloadsystemd-5ee37b703e686782be565b2d0638c5488770141e.tar.gz
repart: use id128_get_machine()
This also makes that the seed is actually randomized when the read machine ID is NULL.
Diffstat (limited to 'src/partition')
-rw-r--r--src/partition/repart.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c
index 3d21caa306..e4ae8a2c89 100644
--- a/src/partition/repart.c
+++ b/src/partition/repart.c
@@ -4909,24 +4909,14 @@ static int context_read_seed(Context *context, const char *root) {
return 0;
if (!arg_randomize) {
- _cleanup_close_ int fd = -EBADF;
-
- fd = chase_and_open("/etc/machine-id", root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC, NULL);
- if (fd == -ENOENT)
- log_info("No machine ID set, using randomized partition UUIDs.");
- else if (fd < 0)
- return log_error_errno(fd, "Failed to determine machine ID of image: %m");
- else {
- r = id128_read_fd(fd, ID128_FORMAT_PLAIN, &context->seed);
- if (r < 0) {
- if (!ERRNO_IS_MACHINE_ID_UNSET(r))
- return log_error_errno(r, "Failed to parse machine ID of image: %m");
+ r = id128_get_machine(root, &context->seed);
+ if (r >= 0)
+ return 0;
- log_info("No machine ID set, using randomized partition UUIDs.");
- }
+ if (!ERRNO_IS_MACHINE_ID_UNSET(r))
+ return log_error_errno(r, "Failed to parse machine ID of image: %m");
- return 0;
- }
+ log_info("No machine ID set, using randomized partition UUIDs.");
}
r = sd_id128_randomize(&context->seed);