aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-12-20 11:07:15 +0100
committerMichael Albinus2018-12-20 11:07:15 +0100
commit88d3713beb8310eb1ab45dde8aa767f14489affe (patch)
tree1226549f5e63d7d95b2ebf677519c64e5cc12d02
parent7ca9bb7849c47f061f1e887fe1c2de9960654648 (diff)
downloademacs-88d3713beb8310eb1ab45dde8aa767f14489affe.tar.gz
emacs-88d3713beb8310eb1ab45dde8aa767f14489affe.zip
Fix Bug#33781
* lisp/net/tramp-sh.el (tramp-set-remote-path): Use a temporary file for setting $PATH, if it exceeds PATH_MAX on the remote system. (tramp-send-command-and-read): Ignore errors if NOERROR. (Bug#33781) * test/lisp/net/tramp-tests.el (tramp-test34-remote-path): New test.
-rw-r--r--lisp/net/tramp-sh.el25
-rw-r--r--test/lisp/net/tramp-tests.el66
2 files changed, 78 insertions, 13 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 14ae2cb51b4..2959422a5da 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -3885,22 +3885,21 @@ This function expects to be in the right *tramp* buffer."
3885I.e., for each directory in `tramp-remote-path', it is tested 3885I.e., for each directory in `tramp-remote-path', it is tested
3886whether it exists and if so, it is added to the environment 3886whether it exists and if so, it is added to the environment
3887variable PATH." 3887variable PATH."
3888 (let ((path (mapconcat 'identity (tramp-get-remote-path vec) ":")) 3888 (let ((command
3889 (format "PATH=%s; export PATH"
3890 (mapconcat 'identity (tramp-get-remote-path vec) ":")))
3889 (path-max 3891 (path-max
3890 (with-tramp-connection-property vec "path-max" 3892 (with-tramp-connection-property vec "path-max"
3891 (tramp-send-command-and-read vec "getconf PATH_MAX /"))) 3893 (tramp-send-command-and-read vec "getconf PATH_MAX /")))
3892 index) 3894 tmpfile)
3893 (tramp-message vec 5 "Setting $PATH environment variable") 3895 (tramp-message vec 5 "Setting $PATH environment variable")
3894 (unless (< (length path) path-max) 3896 (if (< (length command) path-max)
3895 (setq index path-max) 3897 (tramp-send-command vec command)
3896 (while (not (string-equal (substring path (1- index) index) ":")) 3898 ;; Use a temporary file.
3897 (setq index (1- index))) 3899 (setq tmpfile (tramp-make-tramp-temp-file vec))
3898 ;; FIXME: Is this sufficient? Or shall we raise an error? 3900 (write-region command nil tmpfile)
3899 (tramp-message 3901 (tramp-send-command vec (format ". %s" tmpfile))
3900 vec 2 "$PATH environment variable is too long. Ignoring \"%s\"" 3902 (delete-file tmpfile))))
3901 (substring path index))
3902 (setq path (substring path 0 (1- index))))
3903 (tramp-send-command vec (format "PATH=%s; export PATH" path))))
3904 3903
3905;; ------------------------------------------------------------ 3904;; ------------------------------------------------------------
3906;; -- Communication with external shell -- 3905;; -- Communication with external shell --
@@ -5066,7 +5065,7 @@ If MARKER is a regexp, read the output after that string.
5066In case there is no valid Lisp expression and NOERROR is nil, it 5065In case there is no valid Lisp expression and NOERROR is nil, it
5067raises an error." 5066raises an error."
5068 (when (if noerror 5067 (when (if noerror
5069 (tramp-send-command-and-check vec command) 5068 (ignore-errors (tramp-send-command-and-check vec command))
5070 (tramp-barf-unless-okay 5069 (tramp-barf-unless-okay
5071 vec command "`%s' returns with error" command)) 5070 vec command "`%s' returns with error" command))
5072 (with-current-buffer (tramp-get-connection-buffer vec) 5071 (with-current-buffer (tramp-get-connection-buffer vec)
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index f3ad8edf839..a485b8d8a70 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -4187,6 +4187,72 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4187 ;; Cleanup. 4187 ;; Cleanup.
4188 (ignore-errors (delete-file tmp-name))))) 4188 (ignore-errors (delete-file tmp-name)))))
4189 4189
4190;; This test is inspired by Bug#33781.
4191;; `exec-path' was introduced in Emacs 27.1. `executable-find' has
4192;; changed the number of parameters, so we use `apply' for older
4193;; Emacsen.
4194(ert-deftest tramp-test34-remote-path ()
4195 "Check loooong `tramp-remote-path'."
4196 (skip-unless (tramp--test-enabled))
4197 (skip-unless (tramp--test-sh-p))
4198 ;; Since Emacs 27.1.
4199 (skip-unless (fboundp 'exec-path))
4200
4201 (let* ((tmp-name (tramp--test-make-temp-name))
4202 (default-directory tramp-test-temporary-file-directory)
4203 (orig-exec-path (exec-path))
4204 (tramp-remote-path tramp-remote-path)
4205 (orig-tramp-remote-path tramp-remote-path))
4206 (unwind-protect
4207 (progn
4208 ;; Non existing directories are removed.
4209 (setq tramp-remote-path
4210 (cons (file-remote-p tmp-name 'localname) tramp-remote-path))
4211 (tramp-cleanup-connection
4212 (tramp-dissect-file-name tramp-test-temporary-file-directory)
4213 'keep-debug 'keep-password)
4214 (should (equal (with-no-warnings (exec-path)) orig-exec-path))
4215 (setq tramp-remote-path orig-tramp-remote-path)
4216
4217 ;; Double entries are removed.
4218 (setq tramp-remote-path (append '("/" "/") tramp-remote-path))
4219 (tramp-cleanup-connection
4220 (tramp-dissect-file-name tramp-test-temporary-file-directory)
4221 'keep-debug 'keep-password)
4222 (should
4223 (equal (with-no-warnings (exec-path)) (cons "/" orig-exec-path)))
4224 (setq tramp-remote-path orig-tramp-remote-path)
4225
4226 ;; We make a super long `tramp-remote-path'.
4227 (make-directory tmp-name)
4228 (should (file-directory-p tmp-name))
4229 (while (< (length (mapconcat 'identity orig-exec-path ":")) 5000)
4230 (let ((dir (make-temp-file (file-name-as-directory tmp-name) 'dir)))
4231 (should (file-directory-p dir))
4232 (setq tramp-remote-path
4233 (cons (file-remote-p dir 'localname) tramp-remote-path)
4234 orig-exec-path
4235 (cons (file-remote-p dir 'localname) orig-exec-path))))
4236 (tramp-cleanup-connection
4237 (tramp-dissect-file-name tramp-test-temporary-file-directory)
4238 'keep-debug 'keep-password)
4239 (should (equal (with-no-warnings (exec-path)) orig-exec-path))
4240 (should
4241 (string-equal
4242 ;; Ignore trailing newline.
4243 (substring (shell-command-to-string "echo $PATH") nil -1)
4244 ;; The last element of `exec-path' is `exec-directory'.
4245 (mapconcat 'identity (butlast orig-exec-path) ":")))
4246 ;; The shell "sh" shall always exist.
4247 (should (apply 'executable-find '("sh" remote))))
4248
4249 ;; Cleanup.
4250 (tramp-cleanup-connection
4251 (tramp-dissect-file-name tramp-test-temporary-file-directory)
4252 'keep-debug 'keep-password)
4253 (setq tramp-remote-path orig-tramp-remote-path)
4254 (ignore-errors (delete-directory tmp-name 'recursive)))))
4255
4190(ert-deftest tramp-test35-vc-registered () 4256(ert-deftest tramp-test35-vc-registered ()
4191 "Check `vc-registered'." 4257 "Check `vc-registered'."
4192 :tags '(:expensive-test) 4258 :tags '(:expensive-test)