machine-id-setup: --print --commit
respects the --root option
This commit is contained in:
parent
fcb2427055
commit
a6f72863ad
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue