repart: use id128_get_machine()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 31 Mar 2023 07:00:37 +0000 (16:00 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 4 Apr 2023 15:52:56 +0000 (00:52 +0900)
This also makes that the seed is actually randomized when the read
machine ID is NULL.

src/partition/repart.c

index 3d21caa30677b1b9a6b3a967e4de4eca9f176f30..e4ae8a2c89fa23c0fa574d7a021e704fe58fc361 100644 (file)
@@ -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);