diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-09-28 09:25:06 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-10-23 11:18:07 -0700 |
commit | 0d186cbbc8088e505f3d77e18fe8b17b22cfcfb5 (patch) | |
tree | 645892a7ec5dedb6cb69821f9fd7b8df72475357 | |
parent | 8c093003c4defcc02e21f19ce812b065afecc277 (diff) | |
download | consfigurator-0d186cbbc8088e505f3d77e18fe8b17b22cfcfb5.tar.gz |
RUN/MRUN: support unsetting environment variables too
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r-- | src/connection.lisp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/connection.lisp b/src/connection.lisp index b01f298..b7a5cb6 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -391,10 +391,13 @@ 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" - (string-upcase (symbol-name (pop env))) - (escape-sh-token (pop env))) - into accum + for k = (string-upcase (symbol-name (pop env))) + for v = (pop env) + if v + collect (format nil "export ~A=~A" k (escape-sh-token v)) + into accum + else + collect (format nil "unset -v ~A" k) into accum finally (when accum ;; We take this approach of exporting individual variables @@ -405,7 +408,7 @@ the working directory of the Lisp process using UIOP:WITH-CURRENT-DIRECTORY." ;; 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 "~{~A;~^ ~} ~A" accum cmd)))) ;; Set HOME (in a way which ENV can override) because with certain ;; connection types the value sh(1) sets or inherits is wrong. E.g. with ;; :CHROOT.SHELL we get the value from /etc/passwd outside the chroot. @@ -446,7 +449,8 @@ Keyword arguments accepted: - :ENV ENVIRONMENT -- where ENVIRONMENT is a plist specifying environment variable names and values, use env(1) to set these variables when running - the command. + the command. An environment variable value of nil means that the variable + should be unset. Returns command's stdout, stderr and exit code, unless :FOR-EXIT, in which case return only the exit code." |