summaryrefslogtreecommitdiff
path: root/src/core/unit-printf.c
diff options
context:
space:
mode:
authorDaniel Wallace <danielwallace@gtmanfred.com>2012-12-07 00:01:15 -0500
committerLennart Poettering <lennart@poettering.net>2012-12-19 17:36:24 +0100
commit067d851d30386c553e3a84f59d81d003ff638b91 (patch)
treee15bc44448236b8dd15cf0c448be6af063a261ce /src/core/unit-printf.c
parent490b7e47093d491a2bdb1084fe92b796f4e07eef (diff)
unit: add %U for uids in units
Diffstat (limited to 'src/core/unit-printf.c')
-rw-r--r--src/core/unit-printf.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
index a8eb60a3d4..a58c96c238 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -123,6 +123,8 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
ExecContext *c;
int r;
const char *username;
+ uid_t uid;
+ char *printed = NULL;
assert(u);
@@ -134,11 +136,21 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
/* fish username from passwd */
username = c->user;
- r = get_user_creds(&username, NULL, NULL, NULL, NULL);
+ r = get_user_creds(&username, &uid, NULL, NULL, NULL);
if (r < 0)
return NULL;
- return strdup(username);
+ switch (specifier) {
+ case 'U':
+ if (asprintf(&printed, "%d", uid) < 0)
+ return NULL;
+ break;
+ case 'u':
+ printed = strdup(username);
+ break;
+ }
+
+ return printed;
}
static char *specifier_user_home(char specifier, void *data, void *userdata) {
@@ -292,6 +304,7 @@ char *unit_full_printf(Unit *u, const char *format) {
{ 'r', specifier_cgroup_root, NULL },
{ 'R', specifier_cgroup_root, NULL },
{ 't', specifier_runtime, NULL },
+ { 'U', specifier_user_name, NULL },
{ 'u', specifier_user_name, NULL },
{ 'h', specifier_user_home, NULL },
{ 's', specifier_user_shell, NULL },