X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Funit-printf.c;h=cbae45d9f75c2f2db756982acac52f7154ef4772;hb=6aa220e019f9dffd96590b06b68f937985204109;hp=35da29abdf1779776bfff0c477c5adfb02915909;hpb=3ef63c317481c2b3f1fe39e1b0f130aac3544522;p=elogind.git diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 35da29abd..cbae45d9f 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -107,7 +107,7 @@ static char *specifier_runtime(char specifier, void *data, void *userdata) { Unit *u = userdata; assert(u); - if (u->manager->running_as == MANAGER_USER) { + if (u->manager->running_as == SYSTEMD_USER) { const char *e; e = getenv("XDG_RUNTIME_DIR"); @@ -124,6 +124,8 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) { int r; const char *username; + assert(u); + c = unit_get_exec_context(u); if (!c) return NULL; @@ -147,6 +149,8 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) { int r; const char *username, *home; + assert(u); + c = unit_get_exec_context(u); if (!c) return NULL; @@ -176,6 +180,8 @@ static char *specifier_user_shell(char specifier, void *data, void *userdata) { int r; const char *username, *shell; + assert(u); + c = unit_get_exec_context(u); if (!c) return NULL; @@ -199,6 +205,42 @@ static char *specifier_user_shell(char specifier, void *data, void *userdata) { return strdup(shell); } +static 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); +} + +static 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); +} + +static char *specifier_host_name(char specifier, void *data, void *userdata) { + return gethostname_malloc(); +} + char *unit_name_printf(Unit *u, const char* format) { /* @@ -238,6 +280,9 @@ char *unit_full_printf(Unit *u, const char *format) { * %u the username of the configured user or running user * %h the homedir of the configured user or running user * %s the shell of the configured user or running user + * %m the machine ID of the running system + * %b the boot ID of the running system + * %H the host name of the running system */ const Specifier table[] = { @@ -256,6 +301,10 @@ char *unit_full_printf(Unit *u, const char *format) { { 'u', specifier_user_name, NULL }, { 'h', specifier_user_home, NULL }, { 's', specifier_user_shell, NULL }, + + { 'm', specifier_machine_id, NULL }, + { 'H', specifier_host_name, NULL }, + { 'b', specifier_boot_id, NULL }, { 0, NULL, NULL } };