diff options
| author | Liu Hui | 2025-09-12 12:43:54 +0200 |
|---|---|---|
| committer | Michael Albinus | 2025-09-12 12:43:54 +0200 |
| commit | e41eae39ad6accdd1b02dedcb36e48c2b463d0b8 (patch) | |
| tree | b02b7e956ded463867d547880b24e215b01776ca | |
| parent | 26ad23addbf79862f310136d2f0d95568fef3a04 (diff) | |
| download | emacs-e41eae39ad6accdd1b02dedcb36e48c2b463d0b8.tar.gz emacs-e41eae39ad6accdd1b02dedcb36e48c2b463d0b8.zip | |
Tramp: Refactor environment variable filtering to a separate function
* lisp/net/tramp.el (tramp-local-environment-variable-p):
New function. (Bug#79413)
(tramp-handle-make-process):
* lisp/net/tramp-sh.el (tramp-sh-handle-make-process)
(tramp-sh-handle-process-file):
* lisp/net/tramp-androidsu.el
(tramp-androidsu-handle-make-process):
Use `tramp-local-environment-variable-p'.
| -rw-r--r-- | lisp/net/tramp-androidsu.el | 4 | ||||
| -rw-r--r-- | lisp/net/tramp-sh.el | 5 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 16 |
3 files changed, 16 insertions, 9 deletions
diff --git a/lisp/net/tramp-androidsu.el b/lisp/net/tramp-androidsu.el index a593833a836..6cc3f14381d 100644 --- a/lisp/net/tramp-androidsu.el +++ b/lisp/net/tramp-androidsu.el | |||
| @@ -311,9 +311,7 @@ FUNCTION." | |||
| 311 | (when | 311 | (when |
| 312 | (and | 312 | (and |
| 313 | (string-search "=" elt) | 313 | (string-search "=" elt) |
| 314 | (not | 314 | (not (tramp-local-environment-variable-p elt))) |
| 315 | (member | ||
| 316 | elt (default-toplevel-value 'process-environment)))) | ||
| 317 | (setq env (cons elt env))))) | 315 | (setq env (cons elt env))))) |
| 318 | ;; Add remote path if exists. | 316 | ;; Add remote path if exists. |
| 319 | (env (let ((remote-path (string-join (tramp-get-remote-path v) ":"))) | 317 | (env (let ((remote-path (string-join (tramp-get-remote-path v) ":"))) |
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 9d13cdc3a2d..0a454fed69b 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el | |||
| @@ -3052,8 +3052,7 @@ will be used." | |||
| 3052 | ;; `process-environment'. | 3052 | ;; `process-environment'. |
| 3053 | env uenv | 3053 | env uenv |
| 3054 | (env (dolist (elt (cons prompt process-environment) env) | 3054 | (env (dolist (elt (cons prompt process-environment) env) |
| 3055 | (or (member | 3055 | (or (tramp-local-environment-variable-p elt) |
| 3056 | elt (default-toplevel-value 'process-environment)) | ||
| 3057 | (if (string-search "=" elt) | 3056 | (if (string-search "=" elt) |
| 3058 | (setq env (append env `(,elt))) | 3057 | (setq env (append env `(,elt))) |
| 3059 | (setq uenv (cons elt uenv)))))) | 3058 | (setq uenv (cons elt uenv)))))) |
| @@ -3288,7 +3287,7 @@ will be used." | |||
| 3288 | (cons program args) " ")) | 3287 | (cons program args) " ")) |
| 3289 | ;; We use as environment the difference to toplevel `process-environment'. | 3288 | ;; We use as environment the difference to toplevel `process-environment'. |
| 3290 | (dolist (elt process-environment) | 3289 | (dolist (elt process-environment) |
| 3291 | (or (member elt (default-toplevel-value 'process-environment)) | 3290 | (or (tramp-local-environment-variable-p elt) |
| 3292 | (if (string-search "=" elt) | 3291 | (if (string-search "=" elt) |
| 3293 | (setq env (append env `(,elt))) | 3292 | (setq env (append env `(,elt))) |
| 3294 | (setq uenv (cons elt uenv))))) | 3293 | (setq uenv (cons elt uenv))))) |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index ad768f9e038..a27e8b8fbe8 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -5347,6 +5347,18 @@ should be set connection-local.") | |||
| 5347 | (or (not (stringp buffer)) (not (tramp-tramp-file-p buffer))) | 5347 | (or (not (stringp buffer)) (not (tramp-tramp-file-p buffer))) |
| 5348 | (or (not (stringp stderr)) (not (tramp-tramp-file-p stderr)))))) | 5348 | (or (not (stringp stderr)) (not (tramp-tramp-file-p stderr)))))) |
| 5349 | 5349 | ||
| 5350 | ;; This function is used by tramp-*-handle-make-process and | ||
| 5351 | ;; tramp-sh-handle-process-file to filter local environment variables | ||
| 5352 | ;; that should not be propagated remotely. Users can override this | ||
| 5353 | ;; function if necessary, for example, to ensure that a specific | ||
| 5354 | ;; environment variable is applied to remote processes, whether it | ||
| 5355 | ;; exists locally or not. | ||
| 5356 | (defun tramp-local-environment-variable-p (arg) | ||
| 5357 | "Return non-nil if ARG exists in default `process-environment'. | ||
| 5358 | Tramp does not propagate local environment variables in remote | ||
| 5359 | processes." | ||
| 5360 | (member arg (default-toplevel-value 'process-environment))) | ||
| 5361 | |||
| 5350 | (defun tramp-handle-make-process (&rest args) | 5362 | (defun tramp-handle-make-process (&rest args) |
| 5351 | "An alternative `make-process' implementation for Tramp files." | 5363 | "An alternative `make-process' implementation for Tramp files." |
| 5352 | (tramp-skeleton-make-process args nil nil | 5364 | (tramp-skeleton-make-process args nil nil |
| @@ -5365,9 +5377,7 @@ should be set connection-local.") | |||
| 5365 | (env (dolist (elt process-environment env) | 5377 | (env (dolist (elt process-environment env) |
| 5366 | (when (and | 5378 | (when (and |
| 5367 | (string-search "=" elt) | 5379 | (string-search "=" elt) |
| 5368 | (not | 5380 | (not (tramp-local-environment-variable-p elt))) |
| 5369 | (member | ||
| 5370 | elt (default-toplevel-value 'process-environment)))) | ||
| 5371 | (setq env (cons elt env))))) | 5381 | (setq env (cons elt env))))) |
| 5372 | ;; Add remote path if exists. | 5382 | ;; Add remote path if exists. |
| 5373 | (env (if-let* ((sh-file-name-handler-p) | 5383 | (env (if-let* ((sh-file-name-handler-p) |