diff options
author | David Teigland <teigland@redhat.com> | 2020-05-20 10:59:38 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2021-10-07 12:06:49 -0500 |
commit | 3e1316bb09b087ec79c9661ead14d8556c36fa8d (patch) | |
tree | dc04e98f896348aa5595332fdb0f377904e7ecf0 /lib/commands | |
parent | 6c22392a3f903d6c086f7cc94978bdf8b072da6e (diff) | |
download | lvm2-3e1316bb09b087ec79c9661ead14d8556c36fa8d.tar.gz |
system_id: new appmachineid option
The new system_id_source="appmachineid" will cause
lvm to use an lvm-specific derivation of the machine-id,
instead of the machine-id directly. This is now
recommended in place of using machineid.
Diffstat (limited to 'lib/commands')
-rw-r--r-- | lib/commands/toolcontext.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index ecd50dbf7..8991aebcf 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -41,6 +41,10 @@ #include <syslog.h> #include <time.h> +#ifdef APP_MACHINEID_SUPPORT +#include <systemd/sd-id128.h> +#endif + #ifdef __linux__ # include <malloc.h> #endif @@ -129,9 +133,12 @@ static const char *_read_system_id_from_file(struct cmd_context *cmd, const char return system_id; } +/* systemd-id128 new produced: f64406832c2140e8ac5422d1089aae03 */ +#define LVM_APPLICATION_ID SD_ID128_MAKE(f6,44,06,83,2c,21,40,e8,ac,54,22,d1,08,9a,ae,03) + static const char *_system_id_from_source(struct cmd_context *cmd, const char *source) { - char filebuf[PATH_MAX]; + char buf[PATH_MAX]; const char *file; const char *etc_str; const char *str; @@ -150,10 +157,23 @@ static const char *_system_id_from_source(struct cmd_context *cmd, const char *s goto out; } +#ifdef APP_MACHINEID_SUPPORT + if (!strcasecmp(source, "appmachineid")) { + sd_id128_t id; + + sd_id128_get_machine_app_specific(LVM_APPLICATION_ID, &id); + + if (dm_snprintf(buf, PATH_MAX, SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(id)) < 0) + stack; + system_id = system_id_from_string(cmd, buf); + goto out; + } +#endif + if (!strcasecmp(source, "machineid") || !strcasecmp(source, "machine-id")) { etc_str = find_config_tree_str(cmd, global_etc_CFG, NULL); - if (dm_snprintf(filebuf, sizeof(filebuf), "%s/machine-id", etc_str) != -1) - system_id = _read_system_id_from_file(cmd, filebuf); + if (dm_snprintf(buf, sizeof(buf), "%s/machine-id", etc_str) != -1) + system_id = _read_system_id_from_file(cmd, buf); goto out; } |