]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run0: make sure we submit $SHELL to remote
authorMike Yuan <me@yhndnzj.com>
Tue, 8 Apr 2025 20:35:14 +0000 (22:35 +0200)
committerMike Yuan <me@yhndnzj.com>
Wed, 9 Apr 2025 17:30:17 +0000 (19:30 +0200)
Normally, the service manager sets $SHELL to the target user's
login shell, but run0 always overrides that with either
originating user's shell or value from --setenv=SHELL=. In both cases
$SHELL needs to be sent.

Fixes #35007

src/run/run.c

index e4ae5373b92e4c9be89c38774d224c070f6e7197..cc00f9304198cbc5b6ba0d8568c14550ead34bb5 100644 (file)
@@ -1029,18 +1029,25 @@ static int parse_argv_sudo_mode(int argc, char *argv[]) {
                 const char *e;
 
                 e = strv_env_get(arg_environment, "SHELL");
-                if (e)
+                if (e) {
                         arg_exec_path = strdup(e);
-                else {
+                        if (!arg_exec_path)
+                                return log_oom();
+                } else {
                         if (arg_transport == BUS_TRANSPORT_LOCAL) {
                                 r = get_shell(&arg_exec_path);
                                 if (r < 0)
                                         return log_error_errno(r, "Failed to determine shell: %m");
-                        } else
+                        } else {
                                 arg_exec_path = strdup("/bin/sh");
+                                if (!arg_exec_path)
+                                        return log_oom();
+                        }
+
+                        r = strv_env_assign(&arg_environment, "SHELL", arg_exec_path);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to set $SHELL environment variable: %m");
                 }
-                if (!arg_exec_path)
-                        return log_oom();
 
                 l = make_login_shell_cmdline(arg_exec_path);
         }