From 489388fbc0be89e2b978258d277b5ff2da573174 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 17 Jun 2014 03:25:02 +0200 Subject: [PATCH] machine-id-setup: allow passing NULL as function argument, for simplicity --- src/core/machine-id-setup.c | 17 +++++++++++------ src/core/main.c | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c index 3efcd5fac..e2e6d0226 100644 --- a/src/core/machine-id-setup.c +++ b/src/core/machine-id-setup.c @@ -157,18 +157,23 @@ static int generate(char id[34], const char *root) { } int machine_id_setup(const char *root) { + const char *etc_machine_id, *run_machine_id; _cleanup_close_ int fd = -1; - int r; bool writable = false; struct stat st; char id[34]; /* 32 + \n + \0 */ - char *etc_machine_id, *run_machine_id; + int r; - etc_machine_id = strappenda(root, "/etc/machine-id"); - path_kill_slashes(etc_machine_id); + if (isempty(root)) { + etc_machine_id = "/etc/machine-id"; + run_machine_id = "/run/machine-id"; + } else { + etc_machine_id = strappenda(root, "/etc/machine-id"); + path_kill_slashes((char*) etc_machine_id); - run_machine_id = strappenda(root, "/run/machine-id"); - path_kill_slashes(run_machine_id); + run_machine_id = strappenda(root, "/run/machine-id"); + path_kill_slashes((char*) run_machine_id); + } RUN_WITH_UMASK(0000) { /* We create this 0444, to indicate that this isn't really diff --git a/src/core/main.c b/src/core/main.c index 899233bf5..82852d640 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1592,7 +1592,7 @@ int main(int argc, char *argv[]) { kmod_setup(); #endif hostname_setup(); - machine_id_setup(""); + machine_id_setup(NULL); loopback_setup(); test_mtab(); -- 2.30.2