summaryrefslogtreecommitdiff
path: root/src/core/unit-printf.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-01-29 10:32:39 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-01-29 19:01:41 -0500
commit0591220f339c313761f9a208e88fb719db566993 (patch)
treeac3ae94c9fd4644ea91e411314344c6c9a43942a /src/core/unit-printf.c
parentd848b9cbfa0ba72381363accce481600169df2eb (diff)
core: fix %U when no User= used
When the username was not explicitly specified, both %U and %u would print the username. Make %U always print UID.
Diffstat (limited to 'src/core/unit-printf.c')
-rw-r--r--src/core/unit-printf.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c
index 3aa735e5b2..7430beb3da 100644
--- a/src/core/unit-printf.c
+++ b/src/core/unit-printf.c
@@ -26,6 +26,7 @@
#include "strv.h"
#include "unit-name.h"
#include "unit-printf.h"
+#include "macro.h"
static char *specifier_prefix_and_instance(char specifier, void *data, void *userdata) {
Unit *u = userdata;
@@ -123,6 +124,7 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
ExecContext *c;
int r;
const char *username;
+ char _cleanup_free_ *tmp = NULL;
uid_t uid;
char *printed = NULL;
@@ -130,12 +132,13 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
c = unit_get_exec_context(u);
- /* get USER env from our own env if set */
- if (!c || !c->user)
- return getusername_malloc();
+ if (c && c->user)
+ username = c->user;
+ else
+ /* get USER env from env or our own uid */
+ username = tmp = getusername_malloc();
/* fish username from passwd */
- username = c->user;
r = get_user_creds(&username, &uid, NULL, NULL, NULL);
if (r < 0)
return NULL;