]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/execute: set HOME, USER also for root users
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 3 Feb 2017 14:41:53 +0000 (09:41 -0500)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 3 Feb 2017 16:49:22 +0000 (11:49 -0500)
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
src/core/execute.c

index 699f6e263f088548d5049cd1fb012d24268b1860..8079b4b2106678a82d1909473b9ba35b45214c20 100644 (file)
         <term><varname>$SHELL</varname></term>
 
         <listitem><para>User name (twice), home directory, and the
-        login shell. The variables are set for the units that have
-        <varname>User=</varname> set, which includes user
-        <command>systemd</command> instances. See
+        login shell. See
         <citerefentry project='die-net'><refentrytitle>passwd</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
         </para></listitem>
       </varlistentry>
index 47cc4311c1c275b042f8979a162d50e67132d65c..67b54a3bece4f86be1f80cabc940d6a5e80eba84 100644 (file)
@@ -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;