diff options
author | David Teigland <teigland@redhat.com> | 2020-05-20 10:59:38 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2020-05-21 13:33:19 -0500 |
commit | 0d54125830ed10f06992f88b77f1e55577a61b85 (patch) | |
tree | 7569b0577a44b4b96289eb04738b9d62ade41a9e /lib/commands/toolcontext.c | |
parent | 2a304d7a75b572282c288c60497c7c489e7c3cbd (diff) | |
download | lvm2-dev-dct-appmachineid.tar.gz |
system_id: new appmachineid optiondev-dct-appmachineid
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/toolcontext.c')
-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 63b6811e5..f949ead08 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -40,6 +40,10 @@ #include <syslog.h> #include <time.h> +#ifdef APP_MACHINEID_SUPPORT +#include <systemd/sd-id128.h> +#endif + #ifdef __linux__ # include <malloc.h> #endif @@ -128,9 +132,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; @@ -149,10 +156,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; } |