diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-09-18 11:40:01 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-09-18 11:40:01 +0200 |
commit | 3ef63c317481c2b3f1fe39e1b0f130aac3544522 (patch) | |
tree | 0a6bb8b1566591bb7cf6d51fcb085493688efa4a /src/core/unit-printf.c | |
parent | 41f9172f427bdbb8221c64029f78364b8dd4e527 (diff) |
unit-printf: before resolving exec context specifiers check whether the object actually has an exec context
Diffstat (limited to 'src/core/unit-printf.c')
-rw-r--r-- | src/core/unit-printf.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index cd492061bb..35da29abdf 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -119,16 +119,21 @@ static char *specifier_runtime(char specifier, void *data, void *userdata) { } static char *specifier_user_name(char specifier, void *data, void *userdata) { - Service *s = userdata; + Unit *u = userdata; + ExecContext *c; int r; const char *username; + c = unit_get_exec_context(u); + if (!c) + return NULL; + /* get USER env from our own env if set */ - if (!s->exec_context.user) + if (!c->user) return getusername_malloc(); /* fish username from passwd */ - username = s->exec_context.user; + username = c->user; r = get_user_creds(&username, NULL, NULL, NULL, NULL); if (r < 0) return NULL; @@ -137,12 +142,17 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) { } static char *specifier_user_home(char specifier, void *data, void *userdata) { - Service *s = userdata; + Unit *u = userdata; + ExecContext *c; int r; const char *username, *home; + c = unit_get_exec_context(u); + if (!c) + return NULL; + /* return HOME if set, otherwise from passwd */ - if (!s->exec_context.user) { + if (!c->user) { char *h; r = get_home_dir(&h); @@ -152,7 +162,7 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) { return h; } - username = s->exec_context.user; + username = c->user; r = get_user_creds(&username, NULL, NULL, &home, NULL); if (r < 0) return NULL; @@ -161,12 +171,17 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) { } static char *specifier_user_shell(char specifier, void *data, void *userdata) { - Service *s = userdata; + Unit *u = userdata; + ExecContext *c; int r; const char *username, *shell; + c = unit_get_exec_context(u); + if (!c) + return NULL; + /* return HOME if set, otherwise from passwd */ - if (!s->exec_context.user) { + if (!c->user) { char *sh; r = get_shell(&sh); @@ -176,7 +191,7 @@ static char *specifier_user_shell(char specifier, void *data, void *userdata) { return sh; } - username = s->exec_context.user; + username = c->user; r = get_user_creds(&username, NULL, NULL, NULL, &shell); if (r < 0) return strdup("/bin/sh"); |