diff options
Diffstat (limited to 'lisp/net')
-rw-r--r-- | lisp/net/tramp-sh.el | 48 | ||||
-rw-r--r-- | lisp/net/tramp.el | 2 |
2 files changed, 35 insertions, 15 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index f79394ac9b7..80e8375b944 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2877,18 +2877,23 @@ the result will be a local, non-Tramp, file name." tramp-initial-end-of-output)) ;; We use as environment the difference to toplevel ;; `process-environment'. - env - (env - (dolist - (elt - (cons prompt (nreverse (copy-sequence process-environment))) - env) - (or (member elt (default-toplevel-value 'process-environment)) - (setq env (cons elt env))))) + env uenv + (env (dolist (elt (cons prompt process-environment) env) + (or (member elt (default-toplevel-value 'process-environment)) + (if (string-match "=" elt) + (setq env (append env `(,elt))) + (if (tramp-get-env-with-u-option v) + (setq env (append `("-u" ,elt) env)) + (setq uenv (cons elt uenv))))))) (command (when (stringp program) - (format "cd %s && exec %s env %s %s" + (format "cd %s && %s exec %s env %s %s" (tramp-shell-quote-argument localname) + (if uenv + (format + "unset %s &&" + (mapconcat 'tramp-shell-quote-argument uenv " ")) + "") (if heredoc (format "<<'%s'" tramp-end-of-heredoc) "") (mapconcat 'tramp-shell-quote-argument env " ") (if heredoc @@ -2974,20 +2979,28 @@ the result will be a local, non-Tramp, file name." (error "Implementation does not handle immediate return")) (with-parsed-tramp-file-name default-directory nil - (let (command env input tmpinput stderr tmpstderr outbuf ret) + (let (command env uenv input tmpinput stderr tmpstderr outbuf ret) ;; Compute command. (setq command (mapconcat 'tramp-shell-quote-argument (cons program args) " ")) ;; We use as environment the difference to toplevel `process-environment'. - (setq env - (dolist (elt (nreverse (copy-sequence process-environment)) env) - (or (member elt (default-toplevel-value 'process-environment)) - (setq env (cons elt env))))) + (dolist (elt process-environment) + (or (member elt (default-toplevel-value 'process-environment)) + (if (string-match "=" elt) + (setq env (append env `(,elt))) + (if (tramp-get-env-with-u-option v) + (setq env (append `("-u" ,elt) env)) + (setq uenv (cons elt uenv)))))) (when env (setq command (format "env %s %s" (mapconcat 'tramp-shell-quote-argument env " ") command))) + (when uenv + (setq command + (format + "unset %s && %s" + (mapconcat 'tramp-shell-quote-argument uenv " ") command))) ;; Determine input. (if (null infile) (setq input "/dev/null") @@ -5528,6 +5541,13 @@ Return ATTR." tramp-unknown-id-string) (t res))))) +(defun tramp-get-env-with-u-option (vec) + (with-tramp-connection-property vec "env-u-option" + (tramp-message vec 5 "Checking, whether `env -u' works") + ;; Option "-u" is a GNU extension. + (tramp-send-command-and-check + vec "env FOO=foo env -u FOO 2>/dev/null | grep -qv FOO" t))) + ;; Some predefined connection properties. (defun tramp-get-inline-compress (vec prop size) "Return the compress command related to PROP. diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index d80006abbca..34e3054721d 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3524,7 +3524,7 @@ connection buffer." (with-current-buffer (tramp-get-connection-buffer vec) (let (buffer-read-only) (delete-region pos (point)))))))) -:;; Utility functions: +;;; Utility functions: (defun tramp-accept-process-output (&optional proc timeout timeout-msecs) "Like `accept-process-output' for Tramp processes. |