diff options
author | Evgeny Vereshchagin <evvers@ya.ru> | 2016-12-13 11:34:09 +0000 |
---|---|---|
committer | Evgeny Vereshchagin <evvers@ya.ru> | 2016-12-13 13:03:13 +0000 |
commit | a6f72863adda77b3b6c7b08b0c85f41c6ba2a6d1 (patch) | |
tree | 1d15a7eebe561c2e44d732d3c13acfc8b7e39359 | |
parent | fcb2427055bc2e1d8f009ebf3b4d8b1b2bb14faa (diff) |
machine-id-setup: `--print --commit` respects the --root option
-rw-r--r-- | src/basic/path-util.h | 1 | ||||
-rw-r--r-- | src/machine-id-setup/machine-id-setup-main.c | 6 | ||||
-rwxr-xr-x | test/TEST-14-MACHINE-ID/test.sh | 11 |
3 files changed, 17 insertions, 1 deletions
diff --git a/src/basic/path-util.h b/src/basic/path-util.h index d2bc0d3b8e..d548f0c345 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -24,6 +24,7 @@ #include <stddef.h> #include "macro.h" +#include "string-util.h" #include "time-util.h" #define DEFAULT_PATH_NORMAL "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index cc9b1b38fe..2244b1cc76 100644 --- a/src/machine-id-setup/machine-id-setup-main.c +++ b/src/machine-id-setup/machine-id-setup-main.c @@ -22,6 +22,7 @@ #include <stdio.h> #include <stdlib.h> +#include "id128-util.h" #include "log.h" #include "machine-id-setup.h" #include "path-util.h" @@ -118,11 +119,14 @@ int main(int argc, char *argv[]) { goto finish; if (arg_commit) { + const char *etc_machine_id; + r = machine_id_commit(arg_root); if (r < 0) goto finish; - r = sd_id128_get_machine(&id); + etc_machine_id = prefix_roota(arg_root, "/etc/machine-id"); + r = id128_read(etc_machine_id, ID128_PLAIN, &id); if (r < 0) { log_error_errno(r, "Failed to read machine ID back: %m"); goto finish; diff --git a/test/TEST-14-MACHINE-ID/test.sh b/test/TEST-14-MACHINE-ID/test.sh index 1423bd891f..201d5281da 100755 --- a/test/TEST-14-MACHINE-ID/test.sh +++ b/test/TEST-14-MACHINE-ID/test.sh @@ -80,6 +80,17 @@ echo abc >>"$r/etc/machine-id" id=$(systemd-machine-id-setup --print --root "$r") echo $id >expected check expected "$r/etc/machine-id" + +r="$(pwd)/transient-machine-id" +setup_root "$r" +touch "$r/etc/machine-id" +mount -o remount,ro "$r" +mount -t tmpfs tmpfs "$r/run" +transient_id=$(systemd-machine-id-setup --print --root "$r") +mount -o remount,rw "$r" +commited_id=$(systemd-machine-id-setup --print --commit --root "$r") +[[ "$transient_id" = "$commited_id" ]] +check "$r/etc/machine-id" "$r/run/machine-id" EOF chmod +x $initdir/test-machine-id-setup.sh |