]> 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)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 17 May 2025 11:43:20 +0000 (12:43 +0100)
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

(cherry picked from commit ba7fb8cf5f8f6ad26ff5509722ab4795e566bf09)
(cherry picked from commit fbfeda9ff5eefad33dbb40c02c1d51e877a7baa5)

src/run/run.c

index d8118763f073dc6f9545f07cbdabd7218706ead1..b40e188455f38f4766fc3972a9e25d298188ddcc 100644 (file)
@@ -912,18 +912,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);
         }