summaryrefslogtreecommitdiff
path: root/src/machine-id-setup
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-05-10 15:16:09 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-05-15 10:16:27 +0900
commit62281c78bb0ef77dafb2cad14c1216c313417a23 (patch)
treed548217a77b1a2157a02af341df814122fd60a39 /src/machine-id-setup
parent048eb301ec7c86568a7c72c4dbaed3ece015f384 (diff)
downloadsystemd-62281c78bb0ef77dafb2cad14c1216c313417a23.tar.gz
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.
Diffstat (limited to 'src/machine-id-setup')
-rw-r--r--src/machine-id-setup/machine-id-setup-main.c18
1 files changed, 14 insertions, 4 deletions
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;
}