X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fspecifier.c;h=7577c91052cd7f57e0a9c6503dc2932843510b86;hb=9f26c90cb50c45d4549c4dd569917b4ac143b94d;hp=ae00ae10bbf303fbb67ccbb5349ce65208b02095;hpb=f33d3ec1d7521c91da8b30ad5cb345d6416bb07d;p=elogind.git diff --git a/src/shared/specifier.c b/src/shared/specifier.c index ae00ae10b..7577c9105 100644 --- a/src/shared/specifier.c +++ b/src/shared/specifier.c @@ -41,7 +41,8 @@ char *specifier_printf(const char *text, const Specifier table[], void *userdata assert(table); l = strlen(text); - if (!(r = new(char, l+1))) + r = new(char, l+1); + if (!r) return NULL; t = r; @@ -62,7 +63,8 @@ char *specifier_printf(const char *text, const Specifier table[], void *userdata char *n, *w; size_t k, j; - if (!(w = i->lookup(i->specifier, i->data, userdata))) { + w = i->lookup(i->specifier, i->data, userdata); + if (!w) { free(r); return NULL; } @@ -70,7 +72,8 @@ char *specifier_printf(const char *text, const Specifier table[], void *userdata j = t - r; k = strlen(w); - if (!(n = new(char, j + k + l + 1))) { + n = new(char, j + k + l + 1); + if (!n) { free(r); free(w); return NULL; @@ -106,3 +109,39 @@ char *specifier_printf(const char *text, const Specifier table[], void *userdata char* specifier_string(char specifier, void *data, void *userdata) { return strdup(strempty(data)); } + +char *specifier_machine_id(char specifier, void *data, void *userdata) { + sd_id128_t id; + char *buf; + int r; + + r = sd_id128_get_machine(&id); + if (r < 0) + return NULL; + + buf = new(char, 33); + if (!buf) + return NULL; + + return sd_id128_to_string(id, buf); +} + +char *specifier_boot_id(char specifier, void *data, void *userdata) { + sd_id128_t id; + char *buf; + int r; + + r = sd_id128_get_boot(&id); + if (r < 0) + return NULL; + + buf = new(char, 33); + if (!buf) + return NULL; + + return sd_id128_to_string(id, buf); +} + +char *specifier_host_name(char specifier, void *data, void *userdata) { + return gethostname_malloc(); +}