From 8b89628a10af3863bfc97872912e9da4076a5929 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 3 Feb 2017 09:41:53 -0500 Subject: core/execute: set HOME, USER also for root users This changes the environment for services running as root from: LANG=C.utf8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin INVOCATION_ID=ffbdec203c69499a9b83199333e31555 JOURNAL_STREAM=8:1614518 to LANG=C.utf8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin HOME=/root LOGNAME=root USER=root SHELL=/bin/sh INVOCATION_ID=15a077963d7b4ca0b82c91dc6519f87c JOURNAL_STREAM=8:1616718 Making the environment special for the root user complicates things unnecessarily. This change simplifies both our logic (by making the setting of the variables unconditional), and should also simplify the logic in services (particularly scripts). Fixes #5124. --- man/systemd.exec.xml | 4 +--- src/core/execute.c | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml index 699f6e263f..8079b4b210 100644 --- a/man/systemd.exec.xml +++ b/man/systemd.exec.xml @@ -1694,9 +1694,7 @@ $SHELL User name (twice), home directory, and the - login shell. The variables are set for the units that have - User= set, which includes user - systemd instances. See + login shell. See passwd5. diff --git a/src/core/execute.c b/src/core/execute.c index 47cc4311c1..67b54a3bec 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -815,13 +815,10 @@ static int get_fixed_user(const ExecContext *c, const char **user, assert(c); - if (!c->user) - return 0; - /* Note that we don't set $HOME or $SHELL if they are not particularly enlightening anyway * (i.e. are "/" or "/bin/nologin"). */ - name = c->user; + name = c->user ?: "root"; r = get_user_creds_clean(&name, uid, gid, home, shell); if (r < 0) return r; -- cgit v1.2.3-54-g00ecf From 6a93917df9c8c852387d71004ccb43b33da962cd Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 3 Feb 2017 11:32:42 -0500 Subject: core/execute: pass the username to utmp/wtmp database Before previous commit, username would be NULL for root, and set only for other users. So the argument passed to utmp_put_init_process() would be "root" for other users and NULL for root. Seems strange. Instead, always pass the username if available. --- src/core/execute.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index 67b54a3bec..aa0ddb564e 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2436,11 +2436,12 @@ static int exec_child( } if (context->utmp_id) - utmp_put_init_process(context->utmp_id, getpid(), getsid(0), context->tty_path, + utmp_put_init_process(context->utmp_id, getpid(), getsid(0), + context->tty_path, context->utmp_mode == EXEC_UTMP_INIT ? INIT_PROCESS : context->utmp_mode == EXEC_UTMP_LOGIN ? LOGIN_PROCESS : USER_PROCESS, - username ? "root" : context->user); + username); if (context->user) { r = chown_terminal(STDIN_FILENO, uid); -- cgit v1.2.3-54-g00ecf