aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2020-04-06 14:26:49 +0200
committerMichael Albinus2020-04-06 14:26:49 +0200
commit3dc2f50e5bf9f58aee23fd6c61c02fadc240a377 (patch)
tree9ea23578729ca2827acc3fcca6421bfde7cbe2a2
parentfd4ee361395060c8afa95393245ac8d51655ae54 (diff)
downloademacs-3dc2f50e5bf9f58aee23fd6c61c02fadc240a377.tar.gz
emacs-3dc2f50e5bf9f58aee23fd6c61c02fadc240a377.zip
Fix case that $PATH is longer than 4096 chars in Tramp
* lisp/net/tramp-sh.el (tramp-set-remote-path): Use `tramp-send-command' directly. * test/lisp/net/tramp-tests.el (tramp-test-vec): New defconst. (tramp--test-enabled, tramp--test-message) (tramp--test-backtrace, tramp-test03-file-name-host-rules) (tramp-test18-file-attributes, tramp-test20-file-modes) (tramp-test26-file-name-completion) (tramp-test33-environment-variables, tramp-test35-remote-path) (tramp-test36-vc-registered, ) (tramp-test43-asynchronous-requests): Use it. (tramp-test29-start-file-process, tramp-test30-make-process) (tramp-test33-environment-variables): Remove Hydra specific result. (tramp-test35-remote-path): Rewrite partially.
-rw-r--r--lisp/net/tramp-sh.el14
-rw-r--r--test/lisp/net/tramp-tests.el89
2 files changed, 47 insertions, 56 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index c770e3ce400..95425cbebc5 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -481,6 +481,7 @@ The string is used in `tramp-methods'.")
481;; Darwin: /usr/bin:/bin:/usr/sbin:/sbin 481;; Darwin: /usr/bin:/bin:/usr/sbin:/sbin
482;; IRIX64: /usr/bin 482;; IRIX64: /usr/bin
483;; QNAP QTS: --- 483;; QNAP QTS: ---
484;; Hydra: /run/current-system/sw/bin:/bin:/usr/bin
484;;;###tramp-autoload 485;;;###tramp-autoload
485(defcustom tramp-remote-path 486(defcustom tramp-remote-path
486 '(tramp-default-remote-path "/bin" "/usr/bin" "/sbin" "/usr/sbin" 487 '(tramp-default-remote-path "/bin" "/usr/bin" "/sbin" "/usr/sbin"
@@ -4045,11 +4046,14 @@ variable PATH."
4045 (if (< (length command) pipe-buf) 4046 (if (< (length command) pipe-buf)
4046 (tramp-send-command vec command) 4047 (tramp-send-command vec command)
4047 ;; Use a temporary file. 4048 ;; Use a temporary file.
4048 (setq tmpfile 4049 (setq tmpfile (tramp-make-tramp-temp-file vec))
4049 (tramp-make-tramp-file-name vec (tramp-make-tramp-temp-file vec))) 4050 (tramp-send-command vec (format
4050 (write-region command nil tmpfile) 4051 "cat >%s <<'%s'\n%s\n%s"
4051 (tramp-send-command vec (format ". %s" (tramp-file-local-name tmpfile))) 4052 (tramp-shell-quote-argument tmpfile)
4052 (delete-file tmpfile)))) 4053 tramp-end-of-heredoc
4054 command tramp-end-of-heredoc))
4055 (tramp-send-command vec (format ". %s" tmpfile))
4056 (tramp-send-command vec (format "rm -f %s" tmpfile)))))
4053 4057
4054;; ------------------------------------------------------------ 4058;; ------------------------------------------------------------
4055;; -- Communication with external shell -- 4059;; -- Communication with external shell --
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 77222197802..7db9ad42f1b 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -109,6 +109,10 @@
109 (format "/mock::%s" temporary-file-directory))) 109 (format "/mock::%s" temporary-file-directory)))
110 "Temporary directory for Tramp tests.") 110 "Temporary directory for Tramp tests.")
111 111
112(defconst tramp-test-vec
113 (tramp-dissect-file-name tramp-test-temporary-file-directory)
114 "The used `tramp-file-name' structure.")
115
112(setq auth-source-save-behavior nil 116(setq auth-source-save-behavior nil
113 password-cache-expiry nil 117 password-cache-expiry nil
114 remote-file-name-inhibit-cache nil 118 remote-file-name-inhibit-cache nil
@@ -141,9 +145,7 @@ being the result.")
141 (when (cdr tramp--test-enabled-checked) 145 (when (cdr tramp--test-enabled-checked)
142 ;; Cleanup connection. 146 ;; Cleanup connection.
143 (ignore-errors 147 (ignore-errors
144 (tramp-cleanup-connection 148 (tramp-cleanup-connection tramp-test-vec nil 'keep-password)))
145 (tramp-dissect-file-name tramp-test-temporary-file-directory)
146 nil 'keep-password)))
147 149
148 ;; Return result. 150 ;; Return result.
149 (cdr tramp--test-enabled-checked)) 151 (cdr tramp--test-enabled-checked))
@@ -195,16 +197,12 @@ properly. BODY shall not contain a timeout."
195(defsubst tramp--test-message (fmt-string &rest arguments) 197(defsubst tramp--test-message (fmt-string &rest arguments)
196 "Emit a message into ERT *Messages*." 198 "Emit a message into ERT *Messages*."
197 (tramp--test-instrument-test-case 0 199 (tramp--test-instrument-test-case 0
198 (apply 200 (apply #'tramp-message tramp-test-vec 0 fmt-string arguments)))
199 #'tramp-message
200 (tramp-dissect-file-name tramp-test-temporary-file-directory) 0
201 fmt-string arguments)))
202 201
203(defsubst tramp--test-backtrace () 202(defsubst tramp--test-backtrace ()
204 "Dump a backtrace into ERT *Messages*." 203 "Dump a backtrace into ERT *Messages*."
205 (tramp--test-instrument-test-case 10 204 (tramp--test-instrument-test-case 10
206 (tramp-backtrace 205 (tramp-backtrace tramp-test-vec)))
207 (tramp-dissect-file-name tramp-test-temporary-file-directory))))
208 206
209(defmacro tramp--test-print-duration (message &rest body) 207(defmacro tramp--test-print-duration (message &rest body)
210 "Run BODY and print a message with duration, prompted by MESSAGE." 208 "Run BODY and print a message with duration, prompted by MESSAGE."
@@ -1966,9 +1964,9 @@ properly. BODY shall not contain a timeout."
1966 ;; Host names must match rules in case the command template of a 1964 ;; Host names must match rules in case the command template of a
1967 ;; method doesn't use them. 1965 ;; method doesn't use them.
1968 (dolist (m '("su" "sg" "sudo" "doas" "ksu")) 1966 (dolist (m '("su" "sg" "sudo" "doas" "ksu"))
1969 (let ((vec (tramp-dissect-file-name tramp-test-temporary-file-directory)) 1967 (let (tramp-connection-properties tramp-default-proxies-alist)
1970 tramp-connection-properties tramp-default-proxies-alist) 1968 (ignore-errors
1971 (ignore-errors (tramp-cleanup-connection vec nil 'keep-password)) 1969 (tramp-cleanup-connection tramp-test-vec nil 'keep-password))
1972 ;; Single hop. The host name must match `tramp-local-host-regexp'. 1970 ;; Single hop. The host name must match `tramp-local-host-regexp'.
1973 (should-error 1971 (should-error
1974 (find-file (format "/%s:foo:" m)) 1972 (find-file (format "/%s:foo:" m))
@@ -3136,8 +3134,7 @@ This tests also `access-file', `file-readable-p',
3136 (setq test-file-ownership-preserved-p 3134 (setq test-file-ownership-preserved-p
3137 (= (tramp-compat-file-attribute-group-id 3135 (= (tramp-compat-file-attribute-group-id
3138 (file-attributes tmp-name1)) 3136 (file-attributes tmp-name1))
3139 (tramp-get-remote-gid 3137 (tramp-get-remote-gid tramp-test-vec 'integer)))
3140 (tramp-dissect-file-name tmp-name1) 'integer)))
3141 (delete-file tmp-name1)) 3138 (delete-file tmp-name1))
3142 3139
3143 (should-error 3140 (should-error
@@ -3406,7 +3403,7 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
3406 ;; in tramp-sh.el, we must ensure that the remote chmod command 3403 ;; in tramp-sh.el, we must ensure that the remote chmod command
3407 ;; supports the "-h" argument. 3404 ;; supports the "-h" argument.
3408 (when (and (tramp--test-emacs28-p) (tramp--test-sh-p) 3405 (when (and (tramp--test-emacs28-p) (tramp--test-sh-p)
3409 (tramp-get-remote-chmod-h (tramp-dissect-file-name tmp-name1))) 3406 (tramp-get-remote-chmod-h tramp-test-vec))
3410 (unwind-protect 3407 (unwind-protect
3411 (with-no-warnings 3408 (with-no-warnings
3412 (write-region "foo" nil tmp-name1) 3409 (write-region "foo" nil tmp-name1)
@@ -4038,7 +4035,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4038 (when (not (memq system-type '(cygwin windows-nt))) 4035 (when (not (memq system-type '(cygwin windows-nt)))
4039 (let ((method (file-remote-p tramp-test-temporary-file-directory 'method)) 4036 (let ((method (file-remote-p tramp-test-temporary-file-directory 'method))
4040 (host (file-remote-p tramp-test-temporary-file-directory 'host)) 4037 (host (file-remote-p tramp-test-temporary-file-directory 'host))
4041 (vec (tramp-dissect-file-name tramp-test-temporary-file-directory))
4042 (orig-syntax tramp-syntax)) 4038 (orig-syntax tramp-syntax))
4043 (when (and (stringp host) (string-match tramp-host-with-port-regexp host)) 4039 (when (and (stringp host) (string-match tramp-host-with-port-regexp host))
4044 (setq host (match-string 1 host))) 4040 (setq host (match-string 1 host)))
@@ -4051,7 +4047,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4051 (tramp-change-syntax syntax) 4047 (tramp-change-syntax syntax)
4052 ;; This has cleaned up all connection data, which are used 4048 ;; This has cleaned up all connection data, which are used
4053 ;; for completion. We must refill the cache. 4049 ;; for completion. We must refill the cache.
4054 (tramp-set-connection-property vec "property" nil) 4050 (tramp-set-connection-property tramp-test-vec "property" nil)
4055 4051
4056 (let ;; This is needed for the `simplified' syntax. 4052 (let ;; This is needed for the `simplified' syntax.
4057 ((method-marker 4053 ((method-marker
@@ -4252,7 +4248,6 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4252 4248
4253(ert-deftest tramp-test29-start-file-process () 4249(ert-deftest tramp-test29-start-file-process ()
4254 "Check `start-file-process'." 4250 "Check `start-file-process'."
4255 :expected-result (if (getenv "EMACS_HYDRA_CI") :failed :passed)
4256 :tags '(:expensive-test) 4251 :tags '(:expensive-test)
4257 (skip-unless (tramp--test-enabled)) 4252 (skip-unless (tramp--test-enabled))
4258 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p))) 4253 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
@@ -4326,14 +4321,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4326 4321
4327(ert-deftest tramp-test30-make-process () 4322(ert-deftest tramp-test30-make-process ()
4328 "Check `make-process'." 4323 "Check `make-process'."
4329 :expected-result (if (getenv "EMACS_HYDRA_CI") :failed :passed)
4330 :tags '(:expensive-test) 4324 :tags '(:expensive-test)
4331 (skip-unless (tramp--test-enabled)) 4325 (skip-unless (tramp--test-enabled))
4332 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p))) 4326 (skip-unless (or (tramp--test-adb-p) (tramp--test-sh-p)))
4333 ;; `make-process' supports file name handlers since Emacs 27. 4327 ;; `make-process' supports file name handlers since Emacs 27.
4334 (skip-unless (tramp--test-emacs27-p)) 4328 (skip-unless (tramp--test-emacs27-p))
4335 4329
4336 (tramp--test-instrument-test-case 10
4337 (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil))) 4330 (dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
4338 (let ((default-directory tramp-test-temporary-file-directory) 4331 (let ((default-directory tramp-test-temporary-file-directory)
4339 (tmp-name1 (tramp--test-make-temp-name nil quoted)) 4332 (tmp-name1 (tramp--test-make-temp-name nil quoted))
@@ -4494,7 +4487,7 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
4494 4487
4495 ;; Cleanup. 4488 ;; Cleanup.
4496 (ignore-errors (delete-process proc)) 4489 (ignore-errors (delete-process proc))
4497 (ignore-errors (delete-file tmpfile)))))))) 4490 (ignore-errors (delete-file tmpfile)))))))
4498 4491
4499(ert-deftest tramp-test31-interrupt-process () 4492(ert-deftest tramp-test31-interrupt-process ()
4500 "Check `interrupt-process'." 4493 "Check `interrupt-process'."
@@ -4744,7 +4737,6 @@ INPUT, if non-nil, is a string sent to the process."
4744;; This test is inspired by Bug#23952. 4737;; This test is inspired by Bug#23952.
4745(ert-deftest tramp-test33-environment-variables () 4738(ert-deftest tramp-test33-environment-variables ()
4746 "Check that remote processes set / unset environment variables properly." 4739 "Check that remote processes set / unset environment variables properly."
4747 :expected-result (if (getenv "EMACS_HYDRA_CI") :failed :passed)
4748 :tags '(:expensive-test) 4740 :tags '(:expensive-test)
4749 (skip-unless (tramp--test-enabled)) 4741 (skip-unless (tramp--test-enabled))
4750 (skip-unless (tramp--test-sh-p)) 4742 (skip-unless (tramp--test-sh-p))
@@ -4790,9 +4782,7 @@ INPUT, if non-nil, is a string sent to the process."
4790 (funcall this-shell-command-to-string "set"))))) 4782 (funcall this-shell-command-to-string "set")))))
4791 4783
4792 ;; We force a reconnect, in order to have a clean environment. 4784 ;; We force a reconnect, in order to have a clean environment.
4793 (tramp-cleanup-connection 4785 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
4794 (tramp-dissect-file-name tramp-test-temporary-file-directory)
4795 'keep-debug 'keep-password)
4796 (unwind-protect 4786 (unwind-protect
4797 ;; Unset the variable. 4787 ;; Unset the variable.
4798 (let ((tramp-remote-process-environment 4788 (let ((tramp-remote-process-environment
@@ -5039,23 +5029,20 @@ INPUT, if non-nil, is a string sent to the process."
5039 (default-directory tramp-test-temporary-file-directory) 5029 (default-directory tramp-test-temporary-file-directory)
5040 (orig-exec-path (with-no-warnings (exec-path))) 5030 (orig-exec-path (with-no-warnings (exec-path)))
5041 (tramp-remote-path tramp-remote-path) 5031 (tramp-remote-path tramp-remote-path)
5042 (orig-tramp-remote-path tramp-remote-path)) 5032 (orig-tramp-remote-path tramp-remote-path)
5033 path)
5043 (unwind-protect 5034 (unwind-protect
5044 (progn 5035 (progn
5045 ;; Non existing directories are removed. 5036 ;; Non existing directories are removed.
5046 (setq tramp-remote-path 5037 (setq tramp-remote-path
5047 (cons (file-remote-p tmp-name 'localname) tramp-remote-path)) 5038 (cons (file-remote-p tmp-name 'localname) tramp-remote-path))
5048 (tramp-cleanup-connection 5039 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5049 (tramp-dissect-file-name tramp-test-temporary-file-directory)
5050 'keep-debug 'keep-password)
5051 (should (equal (with-no-warnings (exec-path)) orig-exec-path)) 5040 (should (equal (with-no-warnings (exec-path)) orig-exec-path))
5052 (setq tramp-remote-path orig-tramp-remote-path) 5041 (setq tramp-remote-path orig-tramp-remote-path)
5053 5042
5054 ;; Double entries are removed. 5043 ;; Double entries are removed.
5055 (setq tramp-remote-path (append '("/" "/") tramp-remote-path)) 5044 (setq tramp-remote-path (append '("/" "/") tramp-remote-path))
5056 (tramp-cleanup-connection 5045 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5057 (tramp-dissect-file-name tramp-test-temporary-file-directory)
5058 'keep-debug 'keep-password)
5059 (should 5046 (should
5060 (equal (with-no-warnings (exec-path)) (cons "/" orig-exec-path))) 5047 (equal (with-no-warnings (exec-path)) (cons "/" orig-exec-path)))
5061 (setq tramp-remote-path orig-tramp-remote-path) 5048 (setq tramp-remote-path orig-tramp-remote-path)
@@ -5067,26 +5054,30 @@ INPUT, if non-nil, is a string sent to the process."
5067 (let ((dir (make-temp-file (file-name-as-directory tmp-name) 'dir))) 5054 (let ((dir (make-temp-file (file-name-as-directory tmp-name) 'dir)))
5068 (should (file-directory-p dir)) 5055 (should (file-directory-p dir))
5069 (setq tramp-remote-path 5056 (setq tramp-remote-path
5070 (cons (file-remote-p dir 'localname) tramp-remote-path) 5057 (append
5058 tramp-remote-path `(,(file-remote-p dir 'localname)))
5071 orig-exec-path 5059 orig-exec-path
5072 (cons (file-remote-p dir 'localname) orig-exec-path)))) 5060 (append
5073 (tramp-cleanup-connection 5061 (butlast orig-exec-path)
5074 (tramp-dissect-file-name tramp-test-temporary-file-directory) 5062 `(,(file-remote-p dir 'localname))
5075 'keep-debug 'keep-password) 5063 (last orig-exec-path)))))
5064 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5076 (should (equal (with-no-warnings (exec-path)) orig-exec-path)) 5065 (should (equal (with-no-warnings (exec-path)) orig-exec-path))
5077 (should 5066 ;; Ignore trailing newline.
5078 (string-equal 5067 (setq path (substring (shell-command-to-string "echo $PATH") nil -1))
5079 ;; Ignore trailing newline. 5068 ;; The shell doesn't handle such long strings.
5080 (substring (shell-command-to-string "echo $PATH") nil -1) 5069 (unless (<= (length path)
5070 (tramp-get-connection-property
5071 tramp-test-vec "pipe-buf" 4096))
5081 ;; The last element of `exec-path' is `exec-directory'. 5072 ;; The last element of `exec-path' is `exec-directory'.
5082 (mapconcat #'identity (butlast orig-exec-path) ":"))) 5073 (should
5074 (string-equal
5075 path (mapconcat #'identity (butlast orig-exec-path) ":"))))
5083 ;; The shell "sh" shall always exist. 5076 ;; The shell "sh" shall always exist.
5084 (should (apply #'executable-find '("sh" remote)))) 5077 (should (apply #'executable-find '("sh" remote))))
5085 5078
5086 ;; Cleanup. 5079 ;; Cleanup.
5087 (tramp-cleanup-connection 5080 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
5088 (tramp-dissect-file-name tramp-test-temporary-file-directory)
5089 'keep-debug 'keep-password)
5090 (setq tramp-remote-path orig-tramp-remote-path) 5081 (setq tramp-remote-path orig-tramp-remote-path)
5091 (ignore-errors (delete-directory tmp-name 'recursive))))) 5082 (ignore-errors (delete-directory tmp-name 'recursive)))))
5092 5083
@@ -5123,8 +5114,7 @@ INPUT, if non-nil, is a string sent to the process."
5123 tramp-remote-process-environment)) 5114 tramp-remote-process-environment))
5124 ;; We must force a reconnect, in order to activate $BZR_HOME. 5115 ;; We must force a reconnect, in order to activate $BZR_HOME.
5125 (tramp-cleanup-connection 5116 (tramp-cleanup-connection
5126 (tramp-dissect-file-name tramp-test-temporary-file-directory) 5117 tramp-test-vec 'keep-debug 'keep-password)
5127 'keep-debug 'keep-password)
5128 '(Bzr)) 5118 '(Bzr))
5129 (t nil)))) 5119 (t nil))))
5130 ;; Suppress nasty messages. 5120 ;; Suppress nasty messages.
@@ -6072,10 +6062,7 @@ process sentinels. They shall not disturb each other."
6072 0 timer-repeat 6062 0 timer-repeat
6073 (lambda () 6063 (lambda ()
6074 (tramp--test-with-proper-process-name-and-buffer 6064 (tramp--test-with-proper-process-name-and-buffer
6075 (get-buffer-process 6065 (get-buffer-process (tramp-get-buffer tramp-test-vec))
6076 (tramp-get-buffer
6077 (tramp-dissect-file-name
6078 tramp-test-temporary-file-directory)))
6079 (when (> (- (time-to-seconds) (time-to-seconds timer-start)) 6066 (when (> (- (time-to-seconds) (time-to-seconds timer-start))
6080 tramp--test-asynchronous-requests-timeout) 6067 tramp--test-asynchronous-requests-timeout)
6081 (tramp--test-timeout-handler)) 6068 (tramp--test-timeout-handler))