summaryrefslogtreecommitdiff
path: root/src/shared/install-printf.c
diff options
context:
space:
mode:
authorDaniel Mack <github@zonque.org>2015-11-12 18:18:45 +0100
committerDaniel Mack <github@zonque.org>2015-11-12 18:18:45 +0100
commitf1637bd3a81fe0468b53d7aa91b44cc0c34410d7 (patch)
tree60306026034427f5016a1da67cdb9d4689e2a5e9 /src/shared/install-printf.c
parent05c450966a08ff85fa8348e2fe41b722612fa3dc (diff)
parent79413b673b45adc98dfeaec882bbdda2343cb2f9 (diff)
Merge pull request #1515 from poettering/install-symlink
install: follow unit file symlinks in /usr, but not /etc when looking for [Install] data and more
Diffstat (limited to 'src/shared/install-printf.c')
-rw-r--r--src/shared/install-printf.c52
1 files changed, 19 insertions, 33 deletions
diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c
index e1cb5d27ff..74b909d34d 100644
--- a/src/shared/install-printf.c
+++ b/src/shared/install-printf.c
@@ -67,42 +67,28 @@ static int specifier_instance(char specifier, void *data, void *userdata, char *
}
static int specifier_user_name(char specifier, void *data, void *userdata, char **ret) {
- UnitFileInstallInfo *i = userdata;
- const char *username;
- _cleanup_free_ char *tmp = NULL;
- char *printed = NULL;
-
- assert(i);
+ char *t;
- if (i->user)
- username = i->user;
- else
- /* get USER env from env or our own uid */
- username = tmp = getusername_malloc();
-
- switch (specifier) {
- case 'u':
- printed = strdup(username);
- break;
- case 'U': {
- /* fish username from passwd */
- uid_t uid;
- int r;
-
- r = get_user_creds(&username, &uid, NULL, NULL, NULL);
- if (r < 0)
- return r;
-
- if (asprintf(&printed, UID_FMT, uid) < 0)
- return -ENOMEM;
- break;
- }}
+ /* If we are UID 0 (root), this will not result in NSS,
+ * otherwise it might. This is good, as we want to be able to
+ * run this in PID 1, where our user ID is 0, but where NSS
+ * lookups are not allowed. */
+ t = getusername_malloc();
+ if (!t)
+ return -ENOMEM;
- *ret = printed;
+ *ret = t;
return 0;
}
+static int specifier_user_id(char specifier, void *data, void *userdata, char **ret) {
+
+ if (asprintf(ret, UID_FMT, getuid()) < 0)
+ return -ENOMEM;
+
+ return 0;
+}
int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret) {
@@ -114,8 +100,8 @@ int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret)
* %p: the prefix (foo)
* %i: the instance (bar)
- * %U the UID of the configured user or running user
- * %u the username of the configured user or running user
+ * %U the UID of the running user
+ * %u the username of running user
* %m the machine ID of the running system
* %H the host name of the running system
* %b the boot ID of the running system
@@ -128,7 +114,7 @@ int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret)
{ 'p', specifier_prefix, NULL },
{ 'i', specifier_instance, NULL },
- { 'U', specifier_user_name, NULL },
+ { 'U', specifier_user_id, NULL },
{ 'u', specifier_user_name, NULL },
{ 'm', specifier_machine_id, NULL },