From d3185fda78ecf915ce7ea3ae8d60441f3c89af1b Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 8 Apr 2021 13:15:23 -0700 Subject: RUN/MRUN: export each environment variable individually Signed-off-by: Sean Whitton --- src/connection.lisp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/connection.lisp') diff --git a/src/connection.lisp b/src/connection.lisp index 3f5a4f6..605667d 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -291,13 +291,20 @@ the working directory of the Lisp process using UIOP:WITH-CURRENT-DIRECTORY." finally (nreversef cmd)) (setq cmd (if (cdr cmd) (escape-sh-command cmd) (car cmd))) (loop while env - collect (format nil "~A=~A" (symbol-name (pop env)) (pop env)) + collect (format nil "~A=~A" + (symbol-name (pop env)) (escape-sh-token (pop env))) into accum finally (when accum - (setq cmd (format nil "env ~{~A~^ ~} ~A" - (mapcar #'escape-sh-token accum) - cmd)))) + ;; We take this approach of exporting individual variables + ;; rather than just prepending `FOO=bar BAR=baz` so that if CMD + ;; contains $FOO it will get expanded. We used to use env(1) + ;; but that means CMD cannot contain shell builtins which do + ;; not have an equivalent on PATH, such as 'cd'. This approach + ;; does mean that implementations of CONNECTION-RUN will need + ;; to start a fresh 'sh -c' for each command run, but that's + ;; desirable to ensure any variables set by CMD are reset. + (setq cmd (format nil "~{export ~A;~^ ~} ~A" accum cmd)))) (setq cmd (format nil "cd ~A; ~A" (escape-sh-token (unix-namestring (pwd))) cmd)) ,@forms)) -- cgit v1.2.3