aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/net/tramp-cache.el2
-rw-r--r--lisp/net/tramp-container.el8
-rw-r--r--lisp/net/tramp-sh.el65
-rw-r--r--lisp/net/tramp-smb.el60
-rw-r--r--lisp/net/tramp-sshfs.el2
-rw-r--r--lisp/net/tramp.el13
-rw-r--r--test/lisp/net/tramp-tests.el96
7 files changed, 158 insertions, 88 deletions
diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el
index cbdaa48fc0e..721b7be123f 100644
--- a/lisp/net/tramp-cache.el
+++ b/lisp/net/tramp-cache.el
@@ -713,5 +713,7 @@ for all methods. Resulting data are derived from connection history."
713;;; TODO: 713;;; TODO:
714;; 714;;
715;; * Use multisession.el, starting with Emacs 29.1. 715;; * Use multisession.el, starting with Emacs 29.1.
716;;
717;; Use `with-memoization', starting with Emacs 29.1.
716 718
717;;; tramp-cache.el ends here 719;;; tramp-cache.el ends here
diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el
index 8429208b44b..6e82bc67be1 100644
--- a/lisp/net/tramp-container.el
+++ b/lisp/net/tramp-container.el
@@ -551,6 +551,7 @@ see its function help for a description of the format."
551 (tramp-login-args (("exec") 551 (tramp-login-args (("exec")
552 ("-it") 552 ("-it")
553 ("-u" "%u") 553 ("-u" "%u")
554 ("-e" ,(format "TERM=%s" tramp-terminal-type))
554 ("%h") 555 ("%h")
555 ("%l"))) 556 ("%l")))
556 (tramp-direct-async (,tramp-default-remote-shell "-c")) 557 (tramp-direct-async (,tramp-default-remote-shell "-c"))
@@ -565,6 +566,7 @@ see its function help for a description of the format."
565 (tramp-login-args (("exec") 566 (tramp-login-args (("exec")
566 ("-it") 567 ("-it")
567 ("-u" "%u") 568 ("-u" "%u")
569 ("-e" ,(format "TERM=%s" tramp-terminal-type))
568 ("%h") 570 ("%h")
569 ("%l"))) 571 ("%l")))
570 (tramp-direct-async (,tramp-default-remote-shell "-c")) 572 (tramp-direct-async (,tramp-default-remote-shell "-c"))
@@ -583,6 +585,7 @@ see its function help for a description of the format."
583 (tramp-login-args (("exec") 585 (tramp-login-args (("exec")
584 ("-it") 586 ("-it")
585 ("-u" "%u") 587 ("-u" "%u")
588 ("-e" ,(format "TERM=%s" tramp-terminal-type))
586 ("%h") 589 ("%h")
587 ("%l"))) 590 ("%l")))
588 (tramp-direct-async (,tramp-default-remote-shell "-c")) 591 (tramp-direct-async (,tramp-default-remote-shell "-c"))
@@ -597,6 +600,7 @@ see its function help for a description of the format."
597 (tramp-login-args (("exec") 600 (tramp-login-args (("exec")
598 ("-it") 601 ("-it")
599 ("-u" "%u") 602 ("-u" "%u")
603 ("-e" ,(format "TERM=%s" tramp-terminal-type))
600 ("%h") 604 ("%h")
601 ("%l"))) 605 ("%l")))
602 (tramp-direct-async (,tramp-default-remote-shell "-c")) 606 (tramp-direct-async (,tramp-default-remote-shell "-c"))
@@ -754,6 +758,8 @@ see its function help for a description of the format."
754 `(,tramp-apptainer-method 758 `(,tramp-apptainer-method
755 (tramp-login-program ,tramp-apptainer-program) 759 (tramp-login-program ,tramp-apptainer-program)
756 (tramp-login-args (("shell") 760 (tramp-login-args (("shell")
761 ("--env"
762 ,(format "TERM=%s" tramp-terminal-type))
757 ("instance://%h") 763 ("instance://%h")
758 ("%h"))) ; Needed for multi-hop check. 764 ("%h"))) ; Needed for multi-hop check.
759 (tramp-remote-shell ,tramp-default-remote-shell) 765 (tramp-remote-shell ,tramp-default-remote-shell)
@@ -777,6 +783,8 @@ see its function help for a description of the format."
777 (tramp-login-args (("shell") 783 (tramp-login-args (("shell")
778 ("-q") 784 ("-q")
779 ("--uid" "%u") 785 ("--uid" "%u")
786 ("-E"
787 ,(format "TERM=%s" tramp-terminal-type))
780 ("%h"))) 788 ("%h")))
781 (tramp-remote-shell ,tramp-default-remote-shell) 789 (tramp-remote-shell ,tramp-default-remote-shell)
782 (tramp-remote-shell-login ("-l")) 790 (tramp-remote-shell-login ("-l"))
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index eb446f4e2cd..679d76d0f57 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -190,7 +190,10 @@ The string is used in `tramp-methods'.")
190 `("scp" 190 `("scp"
191 (tramp-login-program "ssh") 191 (tramp-login-program "ssh")
192 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") 192 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
193 ("-e" "none") ("%h"))) 193 ("-e" "none")
194 ("-o" ,(format "SetEnv=\"TERM=%s\""
195 tramp-terminal-type))
196 ("%h")))
194 (tramp-async-args (("-q"))) 197 (tramp-async-args (("-q")))
195 (tramp-direct-async ("-t" "-t")) 198 (tramp-direct-async ("-t" "-t"))
196 (tramp-remote-shell ,tramp-default-remote-shell) 199 (tramp-remote-shell ,tramp-default-remote-shell)
@@ -208,6 +211,8 @@ The string is used in `tramp-methods'.")
208 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") 211 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
209 ("-e" "none") ("-t" "-t") 212 ("-e" "none") ("-t" "-t")
210 ("-o" "RemoteCommand=\"%l\"") 213 ("-o" "RemoteCommand=\"%l\"")
214 ("-o" ,(format "SetEnv=\"TERM=%s\""
215 tramp-terminal-type))
211 ("%h"))) 216 ("%h")))
212 (tramp-async-args (("-q"))) 217 (tramp-async-args (("-q")))
213 (tramp-remote-shell ,tramp-default-remote-shell) 218 (tramp-remote-shell ,tramp-default-remote-shell)
@@ -223,7 +228,10 @@ The string is used in `tramp-methods'.")
223 `("rsync" 228 `("rsync"
224 (tramp-login-program "ssh") 229 (tramp-login-program "ssh")
225 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") 230 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
226 ("-e" "none") ("%h"))) 231 ("-e" "none")
232 ("-o" ,(format "SetEnv=\"TERM=%s\""
233 tramp-terminal-type))
234 ("%h")))
227 (tramp-async-args (("-q"))) 235 (tramp-async-args (("-q")))
228 (tramp-direct-async t) 236 (tramp-direct-async t)
229 (tramp-remote-shell ,tramp-default-remote-shell) 237 (tramp-remote-shell ,tramp-default-remote-shell)
@@ -254,7 +262,10 @@ The string is used in `tramp-methods'.")
254 `("ssh" 262 `("ssh"
255 (tramp-login-program "ssh") 263 (tramp-login-program "ssh")
256 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") 264 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
257 ("-e" "none") ("%h"))) 265 ("-e" "none")
266 ("-o" ,(format "SetEnv=\"TERM=%s\""
267 tramp-terminal-type))
268 ("%h")))
258 (tramp-async-args (("-q"))) 269 (tramp-async-args (("-q")))
259 (tramp-direct-async ("-t" "-t")) 270 (tramp-direct-async ("-t" "-t"))
260 (tramp-remote-shell ,tramp-default-remote-shell) 271 (tramp-remote-shell ,tramp-default-remote-shell)
@@ -265,6 +276,8 @@ The string is used in `tramp-methods'.")
265 (tramp-login-program "ssh") 276 (tramp-login-program "ssh")
266 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c") 277 (tramp-login-args (("-l" "%u") ("-p" "%p") ("%c")
267 ("-e" "none") ("-t" "-t") 278 ("-e" "none") ("-t" "-t")
279 ("-o" ,(format "SetEnv=\"TERM=%s\""
280 tramp-terminal-type))
268 ("-o" "RemoteCommand=\"%l\"") 281 ("-o" "RemoteCommand=\"%l\"")
269 ("%h"))) 282 ("%h")))
270 (tramp-async-args (("-q"))) 283 (tramp-async-args (("-q")))
@@ -301,6 +314,7 @@ The string is used in `tramp-methods'.")
301 ;; remote host echoes the command. 314 ;; remote host echoes the command.
302 ;; The "-p" argument doesn't work reliably, see Bug#50594. 315 ;; The "-p" argument doesn't work reliably, see Bug#50594.
303 (tramp-login-args (("SUDO_PROMPT=P\"\"a\"\"s\"\"s\"\"w\"\"o\"\"r\"\"d\"\":") 316 (tramp-login-args (("SUDO_PROMPT=P\"\"a\"\"s\"\"s\"\"w\"\"o\"\"r\"\"d\"\":")
317 (,(format "TERM=%s" tramp-terminal-type))
304 ("sudo") ("-u" "%u") ("-s") ("-H") 318 ("sudo") ("-u" "%u") ("-s") ("-H")
305 ("%l"))) 319 ("%l")))
306 (tramp-remote-shell ,tramp-default-remote-shell) 320 (tramp-remote-shell ,tramp-default-remote-shell)
@@ -4123,12 +4137,33 @@ This function expects to be in the right *tramp* buffer."
4123 (unless (char-equal ?~ (aref d 0)) 4137 (unless (char-equal ?~ (aref d 0))
4124 (setq newdl (cons d newdl)))) 4138 (setq newdl (cons d newdl))))
4125 (setq dirlist (nreverse newdl)))) 4139 (setq dirlist (nreverse newdl))))
4126 (when (tramp-send-command-and-check 4140 (let ((command
4127 vec (format "(unalias %s; %s command -v %s)" 4141 (concat
4128 progname 4142 (when dirlist (format "PATH=%s " (string-join dirlist ":")))
4129 (if dirlist (concat "PATH=" (string-join dirlist ":")) "") 4143 "command -v " progname))
4130 progname)) 4144 (pipe-buf (tramp-get-remote-pipe-buf vec))
4131 (string-trim (tramp-get-buffer-string (tramp-get-connection-buffer vec))))) 4145 tmpfile chunk chunksize)
4146 (when (if (length< command pipe-buf)
4147 (tramp-send-command-and-check vec command)
4148 ;; Use a temporary file. We cannot use `write-region'
4149 ;; because setting the remote path happens in the early
4150 ;; connection handshake, and not all external tools are
4151 ;; determined yet.
4152 (setq command (concat command "\n")
4153 tmpfile (tramp-make-tramp-temp-file vec))
4154 (while (not (string-empty-p command))
4155 (setq chunksize (min (length command) (/ pipe-buf 2))
4156 chunk (substring command 0 chunksize)
4157 command (substring command chunksize))
4158 (tramp-send-command
4159 vec (format "printf \"%%b\" \"$*\" %s >>%s"
4160 (tramp-shell-quote-argument chunk)
4161 (tramp-shell-quote-argument tmpfile))))
4162 (tramp-send-command-and-check
4163 vec (format ". %s && rm -f %s" tmpfile tmpfile)))
4164
4165 (string-trim
4166 (tramp-get-buffer-string (tramp-get-connection-buffer vec))))))
4132 4167
4133;; On hydra.nixos.org, the $PATH environment variable is too long to 4168;; On hydra.nixos.org, the $PATH environment variable is too long to
4134;; send it. This is likely not due to PATH_MAX, but PIPE_BUF. We 4169;; send it. This is likely not due to PATH_MAX, but PIPE_BUF. We
@@ -4162,12 +4197,11 @@ variable PATH."
4162 (setq chunksize (min (length command) (/ pipe-buf 2)) 4197 (setq chunksize (min (length command) (/ pipe-buf 2))
4163 chunk (substring command 0 chunksize) 4198 chunk (substring command 0 chunksize)
4164 command (substring command chunksize)) 4199 command (substring command chunksize))
4165 (tramp-send-command vec (format 4200 (tramp-send-command
4166 "printf \"%%b\" \"$*\" %s >>%s" 4201 vec (format "printf \"%%b\" \"$*\" %s >>%s"
4167 (tramp-shell-quote-argument chunk) 4202 (tramp-shell-quote-argument chunk)
4168 (tramp-shell-quote-argument tmpfile)))) 4203 (tramp-shell-quote-argument tmpfile))))
4169 (tramp-send-command vec (format ". %s" tmpfile)) 4204 (tramp-send-command vec (format ". %s && rm -f %s" tmpfile tmpfile))))))
4170 (tramp-send-command vec (format "rm -f %s" tmpfile))))))
4171 4205
4172;; ------------------------------------------------------------ 4206;; ------------------------------------------------------------
4173;; -- Communication with external shell -- 4207;; -- Communication with external shell --
@@ -5108,6 +5142,7 @@ Goes through the list `tramp-inline-compress-commands'."
5108 5142
5109 (t "-3"))) 5143 (t "-3")))
5110 5144
5145;;;###tramp-autoload
5111(defun tramp-timeout-session (vec) 5146(defun tramp-timeout-session (vec)
5112 "Close the connection VEC after a session timeout. 5147 "Close the connection VEC after a session timeout.
5113If there is just some editing, retry it after 5 seconds." 5148If there is just some editing, retry it after 5 seconds."
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index aeb7c01c03f..db961c97523 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -162,6 +162,7 @@ this variable \"client min protocol=NT1\"."
162 "NT_STATUS_PASSWORD_MUST_CHANGE" 162 "NT_STATUS_PASSWORD_MUST_CHANGE"
163 "NT_STATUS_RESOURCE_NAME_NOT_FOUND" 163 "NT_STATUS_RESOURCE_NAME_NOT_FOUND"
164 "NT_STATUS_REVISION_MISMATCH" 164 "NT_STATUS_REVISION_MISMATCH"
165 "NT_STATUS_RPC_SS_CONTEXT_MISMATCH"
165 "NT_STATUS_SHARING_VIOLATION" 166 "NT_STATUS_SHARING_VIOLATION"
166 "NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE" 167 "NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE"
167 "NT_STATUS_UNSUCCESSFUL" 168 "NT_STATUS_UNSUCCESSFUL"
@@ -316,7 +317,7 @@ Operations not mentioned here will be handled by the default Emacs primitives.")
316;; Options for remote processes via winexe. 317;; Options for remote processes via winexe.
317(defcustom tramp-smb-winexe-program "winexe" 318(defcustom tramp-smb-winexe-program "winexe"
318 "Name of winexe client to run. 319 "Name of winexe client to run.
319If it isn't found in the local $PATH, the absolute path of winexe 320If it isn't found in the local $PATH, the absolute path of \"winexe\"
320shall be given. This is needed for remote processes." 321shall be given. This is needed for remote processes."
321 :group 'tramp 322 :group 'tramp
322 :version "24.3" 323 :version "24.3"
@@ -488,12 +489,13 @@ arguments to pass to the OPERATION."
488 (args (list (concat "//" host "/" share) "-E")) 489 (args (list (concat "//" host "/" share) "-E"))
489 (options tramp-smb-options)) 490 (options tramp-smb-options))
490 491
491 (if (tramp-string-empty-or-nil-p user) 492 (setq args
492 (setq args (append args (list "-N"))) 493 (append args
493 (setq args (append args (list "-U" user)))) 494 (if (tramp-string-empty-or-nil-p user)
495 (list "-N")
496 (list "-U" (if domain (concat domain "/" user) user)))
497 (when port (list "-p" port))))
494 498
495 (when domain (setq args (append args (list "-W" domain))))
496 (when port (setq args (append args (list "-p" port))))
497 (when tramp-smb-conf 499 (when tramp-smb-conf
498 (setq args (append args (list "-s" tramp-smb-conf)))) 500 (setq args (append args (list "-s" tramp-smb-conf))))
499 (while options 501 (while options
@@ -779,12 +781,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
779 (args (list (concat "//" host "/" share) "-E")) 781 (args (list (concat "//" host "/" share) "-E"))
780 (options tramp-smb-options)) 782 (options tramp-smb-options))
781 783
782 (if (tramp-string-empty-or-nil-p user) 784 (setq args
783 (setq args (append args (list "-N"))) 785 (append args
784 (setq args (append args (list "-U" user)))) 786 (if (tramp-string-empty-or-nil-p user)
787 (list "-N")
788 (list "-U" (if domain (concat domain "/" user) user)))
789 (when port (list "-p" port))))
785 790
786 (when domain (setq args (append args (list "-W" domain))))
787 (when port (setq args (append args (list "-p" port))))
788 (when tramp-smb-conf 791 (when tramp-smb-conf
789 (setq args (append args (list "-s" tramp-smb-conf)))) 792 (setq args (append args (list "-s" tramp-smb-conf))))
790 (while options 793 (while options
@@ -1251,6 +1254,7 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
1251 (tramp-set-connection-property 1254 (tramp-set-connection-property
1252 v " process-buffer" 1255 v " process-buffer"
1253 (or outbuf (generate-new-buffer tramp-temp-buffer-name))) 1256 (or outbuf (generate-new-buffer tramp-temp-buffer-name)))
1257 (tramp-flush-connection-property v " process-exit-status")
1254 (with-current-buffer (tramp-get-connection-buffer v) 1258 (with-current-buffer (tramp-get-connection-buffer v)
1255 ;; Preserve buffer contents. 1259 ;; Preserve buffer contents.
1256 (narrow-to-region (point-max) (point-max)) 1260 (narrow-to-region (point-max) (point-max))
@@ -1366,12 +1370,13 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
1366 (string-replace "\n" "," acl-string))) 1370 (string-replace "\n" "," acl-string)))
1367 (options tramp-smb-options)) 1371 (options tramp-smb-options))
1368 1372
1369 (if (tramp-string-empty-or-nil-p user) 1373 (setq args
1370 (setq args (append args (list "-N"))) 1374 (append args
1371 (setq args (append args (list "-U" user)))) 1375 (if (tramp-string-empty-or-nil-p user)
1376 (list "-N")
1377 (list "-U" (if domain (concat domain "/" user) user)))
1378 (when port (list "-p" port))))
1372 1379
1373 (when domain (setq args (append args (list "-W" domain))))
1374 (when port (setq args (append args (list "-p" port))))
1375 (when tramp-smb-conf 1380 (when tramp-smb-conf
1376 (setq args (append args (list "-s" tramp-smb-conf)))) 1381 (setq args (append args (list "-s" tramp-smb-conf))))
1377 (while options 1382 (while options
@@ -1906,16 +1911,19 @@ If ARGUMENT is non-nil, use it as argument for
1906 (share (setq args (list (concat "//" host "/" share)))) 1911 (share (setq args (list (concat "//" host "/" share))))
1907 (t (setq args (list "-g" "-L" host )))) 1912 (t (setq args (list "-g" "-L" host ))))
1908 1913
1909 (if (tramp-string-empty-or-nil-p user) 1914 (setq args
1910 (setq args (append args (list "-N"))) 1915 (append args
1911 (setq args (append args (list "-U" user)))) 1916 (if (tramp-string-empty-or-nil-p user)
1917 (list "-N")
1918 (list "-U" (if domain (concat domain "/" user) user)))
1919 (when port (list "-p" port))))
1912 1920
1913 (when domain (setq args (append args (list "-W" domain))))
1914 (when port (setq args (append args (list "-p" port))))
1915 (when tramp-smb-conf 1921 (when tramp-smb-conf
1916 (setq args (append args (list "-s" tramp-smb-conf)))) 1922 (setq args (append args (list "-s" tramp-smb-conf))))
1917 (dolist (option options) 1923 (dolist (option options)
1918 (setq args (append args (list "--option" option)))) 1924 (setq args (append args (list "--option" option))))
1925 ;; For debugging.
1926 (setq args (append args (list "-d" "1")))
1919 (when argument 1927 (when argument
1920 (setq args (append args (list argument)))) 1928 (setq args (append args (list argument))))
1921 1929
@@ -2026,6 +2034,8 @@ Removes smb prompt. Returns nil if an error message has appeared."
2026 (when (tramp-file-name-port vec) 2034 (when (tramp-file-name-port vec)
2027 (tramp-error vec 'file-error "Port not supported for remote processes")) 2035 (tramp-error vec 'file-error "Port not supported for remote processes"))
2028 2036
2037 ;; In case of "NT_STATUS_RPC_SS_CONTEXT_MISMATCH", the remote server
2038 ;; is a Samba server. winexe cannot install the respective service there.
2029 (tramp-smb-maybe-open-connection 2039 (tramp-smb-maybe-open-connection
2030 vec 2040 vec
2031 (format 2041 (format
@@ -2037,12 +2047,14 @@ Removes smb prompt. Returns nil if an error message has appeared."
2037 ;; Suppress "^M". Shouldn't we specify utf8? 2047 ;; Suppress "^M". Shouldn't we specify utf8?
2038 (set-process-coding-system (tramp-get-connection-process vec) 'raw-text-dos) 2048 (set-process-coding-system (tramp-get-connection-process vec) 'raw-text-dos)
2039 2049
2040 ;; Set width to 128. This avoids mixing prompt and long error messages. 2050 ;; Set width to 128 ($bufsize.Width) or 102 ($winsize.Width),
2051 ;; respectively. $winsize.Width cannot be larger. This avoids
2052 ;; mixing prompt and long error messages.
2041 (tramp-smb-send-command vec "$rawui = (Get-Host).UI.RawUI") 2053 (tramp-smb-send-command vec "$rawui = (Get-Host).UI.RawUI")
2042 (tramp-smb-send-command vec "$bufsize = $rawui.BufferSize") 2054 (tramp-smb-send-command vec "$bufsize = $rawui.BufferSize")
2043 (tramp-smb-send-command vec "$winsize = $rawui.WindowSize") 2055 (tramp-smb-send-command vec "$winsize = $rawui.WindowSize")
2044 (tramp-smb-send-command vec "$bufsize.Width = 128") 2056 (tramp-smb-send-command vec "$bufsize.Width = 128")
2045 (tramp-smb-send-command vec "$winsize.Width = 128") 2057 (tramp-smb-send-command vec "$winsize.Width = 102")
2046 (tramp-smb-send-command vec "$rawui.BufferSize = $bufsize") 2058 (tramp-smb-send-command vec "$rawui.BufferSize = $bufsize")
2047 (tramp-smb-send-command vec "$rawui.WindowSize = $winsize")) 2059 (tramp-smb-send-command vec "$rawui.WindowSize = $winsize"))
2048 2060
@@ -2069,5 +2081,7 @@ Removes smb prompt. Returns nil if an error message has appeared."
2069;; several places, especially in `tramp-smb-handle-insert-directory'. 2081;; several places, especially in `tramp-smb-handle-insert-directory'.
2070;; 2082;;
2071;; * Keep a separate connection process per share. 2083;; * Keep a separate connection process per share.
2084;;
2085;; * Keep a permanent connection process for `process-file'.
2072 2086
2073;;; tramp-smb.el ends here 2087;;; tramp-smb.el ends here
diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el
index 3176236128a..cbc083a1fe0 100644
--- a/lisp/net/tramp-sshfs.el
+++ b/lisp/net/tramp-sshfs.el
@@ -62,6 +62,8 @@
62 (tramp-login-program "ssh") 62 (tramp-login-program "ssh")
63 (tramp-login-args (("-q") ("-l" "%u") ("-p" "%p") 63 (tramp-login-args (("-q") ("-l" "%u") ("-p" "%p")
64 ("-e" "none") ("%a" "%a") 64 ("-e" "none") ("%a" "%a")
65 ("-o" ,(format "SetEnv=\"TERM=%s\""
66 tramp-terminal-type))
65 ("%h") ("%l"))) 67 ("%h") ("%l")))
66 (tramp-direct-async t) 68 (tramp-direct-async t)
67 (tramp-remote-shell ,tramp-default-remote-shell) 69 (tramp-remote-shell ,tramp-default-remote-shell)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 67aa2cd0fdb..24298e8e09a 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -6255,15 +6255,22 @@ the remote host use line-endings as defined in the variable
6255 (process-send-string p string))))))) 6255 (process-send-string p string)))))))
6256 6256
6257(defun tramp-process-sentinel (proc event) 6257(defun tramp-process-sentinel (proc event)
6258 "Flush file caches and remove shell prompt." 6258 "Flush file caches and remove shell prompt.
6259Set exit status of PROC as connection property \" process-exit-status\"."
6259 (unless (process-live-p proc) 6260 (unless (process-live-p proc)
6260 (let ((vec (process-get proc 'tramp-vector)) 6261 (let ((vec (process-get proc 'tramp-vector))
6261 (buf (process-buffer proc)) 6262 (buf (process-buffer proc))
6262 (prompt (tramp-get-connection-property proc "prompt"))) 6263 (prompt (tramp-get-connection-property proc "prompt")))
6263 (when vec 6264 (when vec
6264 (tramp-message vec 5 "Sentinel called: `%S' `%s'" proc event) 6265 (tramp-message
6266 vec 5 "Sentinel called: `%S' event: `%s' status: %s"
6267 proc event (process-exit-status proc))
6265 (tramp-flush-connection-properties proc) 6268 (tramp-flush-connection-properties proc)
6266 (tramp-flush-directory-properties vec "/")) 6269 (tramp-flush-directory-properties vec "/")
6270 ;; Sometimes, the process has been deleted already before we
6271 ;; can retrieve the exit status.
6272 (tramp-set-connection-property
6273 vec " process-exit-status" (process-exit-status proc)))
6267 (when (buffer-live-p buf) 6274 (when (buffer-live-p buf)
6268 (with-current-buffer buf 6275 (with-current-buffer buf
6269 (when (and prompt (tramp-search-regexp (rx (literal prompt)))) 6276 (when (and prompt (tramp-search-regexp (rx (literal prompt))))
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 349abdc44c9..b60b29fc3e6 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -278,9 +278,10 @@ being the result.")
278 (| "rclone" "sshfs") ".") 278 (| "rclone" "sshfs") ".")
279 (file-name-nondirectory file))) 279 (file-name-nondirectory file)))
280 (tramp--test-message "Delete %s" file) 280 (tramp--test-message "Delete %s" file)
281 (if (file-directory-p file) 281 (ignore-errors ;; Wrong permissions?
282 (delete-directory file 'recursive) 282 (if (file-directory-p file)
283 (delete-file file)))))) 283 (delete-directory file 'recursive)
284 (delete-file file)))))))
284 ;; Cleanup connection. 285 ;; Cleanup connection.
285 (tramp-cleanup-connection tramp-test-vec nil 'keep-password)) 286 (tramp-cleanup-connection tramp-test-vec nil 'keep-password))
286 287
@@ -3761,11 +3762,7 @@ This tests also `access-file', `file-readable-p',
3761 (tmp-name2 (tramp--test-make-temp-name nil quoted)) 3762 (tmp-name2 (tramp--test-make-temp-name nil quoted))
3762 ;; File name with "//". 3763 ;; File name with "//".
3763 (tmp-name3 3764 (tmp-name3
3764 (format 3765 (replace-regexp-in-string "/" "//" (file-local-name tmp-name1)))
3765 "%s%s"
3766 (file-remote-p tmp-name1)
3767 (replace-regexp-in-string
3768 "/" "//" (file-remote-p tmp-name1 'localname))))
3769 ;; `file-ownership-preserved-p' is implemented only in tramp-sh.el. 3766 ;; `file-ownership-preserved-p' is implemented only in tramp-sh.el.
3770 (test-file-ownership-preserved-p (tramp--test-sh-p)) 3767 (test-file-ownership-preserved-p (tramp--test-sh-p))
3771 attr) 3768 attr)
@@ -3887,28 +3884,13 @@ This tests also `access-file', `file-readable-p',
3887 ;; symlinked files to a non-existing or cyclic target. 3884 ;; symlinked files to a non-existing or cyclic target.
3888 (when test-file-ownership-preserved-p 3885 (when test-file-ownership-preserved-p
3889 (should (file-ownership-preserved-p tmp-name2 'group))) 3886 (should (file-ownership-preserved-p tmp-name2 'group)))
3890 (delete-file tmp-name2))) 3887 (delete-file tmp-name2))
3891 3888
3892 ;; Check, that "//" in symlinks are handled properly. 3889 ;; Check, that "//" in symlinks are handled properly.
3893 (with-temp-buffer 3890 (make-symbolic-link tmp-name3 tmp-name2)
3894 (let ((default-directory ert-remote-temporary-file-directory)) 3891 (should (file-symlink-p tmp-name2))
3895 (shell-command
3896 (format
3897 "ln -s %s %s"
3898 (tramp-file-name-localname
3899 (tramp-dissect-file-name tmp-name3))
3900 (tramp-file-name-localname
3901 (tramp-dissect-file-name tmp-name2)))
3902 t)))
3903 (when (file-symlink-p tmp-name2)
3904 (setq attr (file-attributes tmp-name2)) 3892 (setq attr (file-attributes tmp-name2))
3905 (should 3893 (should (string-equal (file-attribute-type attr) tmp-name3))
3906 (string-equal
3907 (file-attribute-type attr)
3908 (funcall
3909 (if (tramp--test-sshfs-p) #'file-name-nondirectory #'identity)
3910 (tramp-file-name-localname
3911 (tramp-dissect-file-name tmp-name3)))))
3912 (delete-file tmp-name2)) 3894 (delete-file tmp-name2))
3913 3895
3914 (when test-file-ownership-preserved-p 3896 (when test-file-ownership-preserved-p
@@ -5164,7 +5146,8 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
5164 ;; (tramp--test-message "%s" (tramp-get-buffer-string trace-buffer)) 5146 ;; (tramp--test-message "%s" (tramp-get-buffer-string trace-buffer))
5165 ;; (untrace-function #'tramp-completion-file-name-handler) 5147 ;; (untrace-function #'tramp-completion-file-name-handler)
5166 ;; (untrace-function #'completion-file-name-table) 5148 ;; (untrace-function #'completion-file-name-table)
5167 (tramp-change-syntax orig-syntax)))) 5149 (tramp-change-syntax orig-syntax)
5150 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password))))
5168 5151
5169(defun tramp--test-split-on-boundary (s) 5152(defun tramp--test-split-on-boundary (s)
5170 "Return completion boundaries for string S." 5153 "Return completion boundaries for string S."
@@ -5177,15 +5160,12 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
5177 ;; boundaries are always incorrect before that. 5160 ;; boundaries are always incorrect before that.
5178 (skip-unless (tramp--test-emacs31-p)) 5161 (skip-unless (tramp--test-emacs31-p))
5179 5162
5180 (should (equal (tramp--test-split-on-boundary "/ssh:user@host:foo") 5163 (let ((remote (file-remote-p ert-remote-temporary-file-directory)))
5181 '("/ssh:user@host:" . "foo"))) 5164 (dolist
5182 (should (equal (tramp--test-split-on-boundary "/ssh:user@host:/~/foo") 5165 (file `(,remote ,(concat remote "/~/")
5183 '("/ssh:user@host:/~/" . "foo"))) 5166 ,(concat remote "/usr//usr/") ,(concat remote remote "//usr/")))
5184 (should (equal (tramp--test-split-on-boundary "/ssh:user@host:/usr//usr/foo") 5167 (should (equal (tramp--test-split-on-boundary (concat file "foo"))
5185 '("/ssh:user@host:/usr//usr/" . "foo"))) 5168 `(,file . "foo"))))))
5186 (should (equal (tramp--test-split-on-boundary
5187 "/ssh:user@host:/ssh:user@host://usr/foo")
5188 '("/ssh:user@host:/ssh:user@host://usr/" . "foo"))))
5189 5169
5190(ert-deftest tramp-test27-load () 5170(ert-deftest tramp-test27-load ()
5191 "Check `load'." 5171 "Check `load'."
@@ -6511,6 +6491,7 @@ INPUT, if non-nil, is a string sent to the process."
6511 (file-remote-p default-directory 'localname))) 6491 (file-remote-p default-directory 'localname)))
6512 ;; The shell "sh" shall always exist. 6492 ;; The shell "sh" shall always exist.
6513 (should (executable-find "sh" 'remote)) 6493 (should (executable-find "sh" 'remote))
6494
6514 ;; Since the last element in `exec-path' is the current 6495 ;; Since the last element in `exec-path' is the current
6515 ;; directory, an executable file in that directory will be 6496 ;; directory, an executable file in that directory will be
6516 ;; found. 6497 ;; found.
@@ -6539,19 +6520,19 @@ INPUT, if non-nil, is a string sent to the process."
6539 (skip-unless (tramp--test-sh-p)) 6520 (skip-unless (tramp--test-sh-p))
6540 (skip-unless (not (tramp--test-crypt-p))) 6521 (skip-unless (not (tramp--test-crypt-p)))
6541 6522
6542 (let* ((tmp-name (tramp--test-make-temp-name)) 6523 (let* ((tmp-name1 (tramp--test-make-temp-name))
6543 (default-directory ert-remote-temporary-file-directory) 6524 (default-directory ert-remote-temporary-file-directory)
6544 (orig-exec-path (exec-path)) 6525 (orig-exec-path (exec-path))
6545 (tramp-remote-path tramp-remote-path) 6526 (tramp-remote-path tramp-remote-path)
6546 (orig-tramp-remote-path tramp-remote-path) 6527 (orig-tramp-remote-path tramp-remote-path)
6547 path) 6528 tmp-name2 path)
6548 ;; The "flatpak" method modifies `tramp-remote-path'. 6529 ;; The "flatpak" method modifies `tramp-remote-path'.
6549 (skip-unless (not (tramp-compat-connection-local-p tramp-remote-path))) 6530 (skip-unless (not (tramp-compat-connection-local-p tramp-remote-path)))
6550 (unwind-protect 6531 (unwind-protect
6551 (progn 6532 (progn
6552 ;; Non existing directories are removed. 6533 ;; Non existing directories are removed.
6553 (setq tramp-remote-path 6534 (setq tramp-remote-path
6554 (cons (file-remote-p tmp-name 'localname) tramp-remote-path)) 6535 (cons (file-remote-p tmp-name1 'localname) tramp-remote-path))
6555 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) 6536 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
6556 (should (equal (exec-path) orig-exec-path)) 6537 (should (equal (exec-path) orig-exec-path))
6557 (setq tramp-remote-path orig-tramp-remote-path) 6538 (setq tramp-remote-path orig-tramp-remote-path)
@@ -6564,11 +6545,11 @@ INPUT, if non-nil, is a string sent to the process."
6564 6545
6565 ;; We make a super long `tramp-remote-path'. 6546 ;; We make a super long `tramp-remote-path'.
6566 (unless (tramp--test-container-oob-p) 6547 (unless (tramp--test-container-oob-p)
6567 (make-directory tmp-name) 6548 (make-directory tmp-name1)
6568 (should (file-directory-p tmp-name)) 6549 (should (file-directory-p tmp-name1))
6569 (while (length< (string-join orig-exec-path ":") 5000) 6550 (while (length< (string-join orig-exec-path ":") 5000)
6570 (let ((dir (make-temp-file 6551 (let ((dir (make-temp-file
6571 (file-name-as-directory tmp-name) 'dir))) 6552 (file-name-as-directory tmp-name1) 'dir)))
6572 (should (file-directory-p dir)) 6553 (should (file-directory-p dir))
6573 (setq tramp-remote-path 6554 (setq tramp-remote-path
6574 (append 6555 (append
@@ -6591,12 +6572,33 @@ INPUT, if non-nil, is a string sent to the process."
6591 (should 6572 (should
6592 (string-equal path (string-join (butlast orig-exec-path) ":")))) 6573 (string-equal path (string-join (butlast orig-exec-path) ":"))))
6593 ;; The shell "sh" shall always exist. 6574 ;; The shell "sh" shall always exist.
6594 (should (executable-find "sh" 'remote)))) 6575 (should (executable-find "sh" 'remote))
6576
6577 ;; Since the last element in `exec-path' is the current
6578 ;; directory, an executable file in that directory will be
6579 ;; found.
6580 (setq tmp-name2
6581 (expand-file-name
6582 "foo"
6583 (concat (file-remote-p default-directory)
6584 (car (last orig-exec-path 2)))))
6585 (write-region "foo" nil tmp-name2)
6586 (should (file-exists-p tmp-name2))
6587
6588 (set-file-modes tmp-name2 #o777)
6589 (should (file-executable-p tmp-name2))
6590 (should
6591 (string-equal
6592 (executable-find (file-name-nondirectory tmp-name2) 'remote)
6593 (file-remote-p tmp-name2 'localname)))
6594 (should-not
6595 (executable-find
6596 (concat (file-name-nondirectory tmp-name2) "foo") 'remote))))
6595 6597
6596 ;; Cleanup. 6598 ;; Cleanup.
6599 (ignore-errors (delete-directory tmp-name1 'recursive))
6597 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password) 6600 (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password)
6598 (setq tramp-remote-path orig-tramp-remote-path) 6601 (setq tramp-remote-path orig-tramp-remote-path))))
6599 (ignore-errors (delete-directory tmp-name 'recursive)))))
6600 6602
6601(tramp--test-deftest-direct-async-process tramp-test35-remote-path) 6603(tramp--test-deftest-direct-async-process tramp-test35-remote-path)
6602 6604