core/execute: always set $USER and introduce SetLoginEnvironment=

Before this commit, $USER, $HOME, $LOGNAME and $SHELL are only
set when User= is set for the unit. For system service, this
results in different behaviors depending on whether User=root is set.

$USER always makes sense on its own, so let's set it unconditionally.
Ideally $HOME should be set too, but it causes trouble when e.g. getty
passes '-p' to login(1), which then doesn't override $HOME. $LOGNAME and
$SHELL are more like "login environments", and are generally not
suitable for system services. Therefore, a new option SetLoginEnvironment=
is also added to control the latter three variables.

Fixes #23438

Replaces #8227
This commit is contained in:
Mike Yuan
2023-10-10 00:00:26 +08:00
parent 1c9433559a
commit 854eca4a95
7 changed files with 88 additions and 24 deletions
+2
View File
@@ -254,6 +254,8 @@ struct ExecContext {
char *group;
char **supplementary_groups;
int set_login_environment;
char *pam_name;
char *utmp_id;