Handle long environment variables in Tramp oricesses

* lisp/net/tramp-sh.el (tramp-sh-handle-make-process):
Handle loooong environment variables.  (Bug#80783)

* test/lisp/net/tramp-tests.el (tramp-test33-environment-variables):
Adapt test.
This commit is contained in:
Michael Albinus 2026-05-06 16:06:50 +02:00
parent dfc7cf8e41
commit eae96d9fcb
2 changed files with 27 additions and 2 deletions

View file

@ -3093,6 +3093,15 @@ will be used."
(setq uenv (cons elt uenv))))))
(env (setenv-internal
env "INSIDE_EMACS" (tramp-inside-emacs) 'keep))
;; Environment is too large. Keep it here.
(eenv (and (> (apply #'+ (length env) (seq-map #'length env)) 2000)
env))
(env (if (not eenv) env
`(,(concat
"INSIDE_EMACS=" (getenv-internal "INSIDE_EMACS" env))
,(concat "PS1=" (getenv-internal "PS1" env)))))
(eenv (setenv-internal eenv "INSIDE_EMACS" nil nil))
(eenv (setenv-internal eenv "PS1" nil nil))
(command
(when (stringp program)
(format "cd %s && %s exec %s %s env %s %s"
@ -3207,6 +3216,11 @@ will be used."
(widen)
(delete-region mark (point-max))
(narrow-to-region (point-max) (point-max))
;; Send delayed environment.
(dolist (entry eenv)
(tramp-send-command
v (format
"export %s" (tramp-shell-quote-argument entry))))
;; Now do it.
(if command
;; Send the command.

View file

@ -6519,7 +6519,7 @@ INPUT, if non-nil, is a string sent to the process."
;; (should (= 11 (point)))))))))))))
)))))))))
;; This test is inspired by Bug#23952.
;; This test is inspired by Bug#23952 and Bug#80783.
(ert-deftest tramp-test33-environment-variables ()
"Check that remote processes set / unset environment variables properly."
:tags '(:expensive-test)
@ -6611,7 +6611,18 @@ INPUT, if non-nil, is a string sent to the process."
;; We must suppress "_=VAR...".
(funcall
this-shell-command-to-string
"printenv | grep -v PS1 | grep -v _=")))))))))
"printenv | grep -v PS1 | grep -v _="))))))
;; Handle looooong environment variables. Bug#80783.
;; FIXME: Make it also work in the synchronous case.
(unless (or (eq this-shell-command-to-string 'shell-command-to-string)
(tramp-direct-async-process-p))
(let* ((bad (concat envvar "=" (make-string 2024 ?x)))
(process-environment
(cl-list* bad bad bad bad process-environment)))
(should
(string-match-p
"foo" (funcall this-shell-command-to-string "echo foo"))))))))
(tramp--test-deftest-direct-async-process tramp-test33-environment-variables)