mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 16:37:19 +09:00
machine-id-setup: inform supervisor about chosen machine ID
Similar as the previous commit, it's useful for a supervisor to know what machine ID we settlted on, in particular as various other things are deterministically derived from it, for example MAC addresses and such.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-id128.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
@@ -12,6 +13,7 @@
|
||||
#include "creds-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "id128-util.h"
|
||||
#include "initrd-util.h"
|
||||
#include "io-util.h"
|
||||
#include "log.h"
|
||||
#include "machine-id-setup.h"
|
||||
@@ -141,8 +143,8 @@ int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_
|
||||
if (sd_id128_is_null(machine_id)) {
|
||||
|
||||
/* Try to read any existing machine ID */
|
||||
if (id128_read_fd(fd, ID128_FORMAT_PLAIN, ret) >= 0)
|
||||
return 0;
|
||||
if (id128_read_fd(fd, ID128_FORMAT_PLAIN, &machine_id) >= 0)
|
||||
goto finish;
|
||||
|
||||
/* Hmm, so, the id currently stored is not useful, then let's generate one */
|
||||
r = generate_machine_id(root, &machine_id);
|
||||
@@ -207,6 +209,9 @@ int machine_id_setup(const char *root, bool force_transient, sd_id128_t machine_
|
||||
return r;
|
||||
|
||||
finish:
|
||||
if (!in_initrd())
|
||||
(void) sd_notifyf(/* unset_environment= */ false, "X_SYSTEMD_MACHINE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(machine_id));
|
||||
|
||||
if (ret)
|
||||
*ret = machine_id;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user