From 62281c78bb0ef77dafb2cad14c1216c313417a23 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 10 May 2023 15:16:09 +0200 Subject: machine-id-setup: Do not overwrite if /etc/machine-id contains uninitialized When we're building OS images, we never want /etc/machine-id to contain anything other than "uninitialized" until we actually boot the image. So let's allow image builders to write "uninitialized" to /etc/machine-id and if systemd-machine-id-setup is called after, make sure we don't overwrite it. --- src/machine-id-setup/machine-id-setup-main.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/machine-id-setup') diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index 17012e20ac..38d66def06 100644 --- a/src/machine-id-setup/machine-id-setup-main.c +++ b/src/machine-id-setup/machine-id-setup-main.c @@ -137,7 +137,6 @@ static int parse_argv(int argc, char *argv[]) { static int run(int argc, char *argv[]) { _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL; _cleanup_(umount_and_rmdir_and_freep) char *unlink_dir = NULL; - sd_id128_t id; int r; log_parse_environment(); @@ -170,6 +169,8 @@ static int run(int argc, char *argv[]) { } if (arg_commit) { + sd_id128_t id; + r = machine_id_commit(arg_root); if (r < 0) return r; @@ -177,14 +178,23 @@ static int run(int argc, char *argv[]) { r = id128_get_machine(arg_root, &id); if (r < 0) return log_error_errno(r, "Failed to read machine ID back: %m"); + + if (arg_print) + puts(SD_ID128_TO_STRING(id)); + + } else if (id128_get_machine(arg_root, NULL) == -ENOPKG) { + if (arg_print) + puts("uninitialized"); } else { + sd_id128_t id; + r = machine_id_setup(arg_root, false, SD_ID128_NULL, &id); if (r < 0) return r; - } - if (arg_print) - puts(SD_ID128_TO_STRING(id)); + if (arg_print) + puts(SD_ID128_TO_STRING(id)); + } return 0; } -- cgit v1.2.1