diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 668eae3198b..079f82f556a 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -4693,13 +4693,14 @@ process to set up. VEC specifies the connection." ;; `connection-local-profile-name-for-criteria' exists since Emacs 29.1. ;; We simulate it with `make-symbol'. (when (boundp 'command-line-max-length) - (let* ((criteria (tramp-get-connection-local-criteria vec)) + (let* ((arg-max (tramp-get-remote-arg-max vec)) + (criteria (tramp-get-connection-local-criteria vec)) (profile (if (fboundp 'connection-local-profile-name-for-criteria) (connection-local-profile-name-for-criteria criteria) (make-symbol "generated-profile-name")))) (connection-local-set-profile-variables profile - `((command-line-max-length . ,(tramp-get-remote-pipe-buf vec)))) + `((command-line-max-length . ,(if arg-max (floor arg-max 4) 4094)))) (connection-local-set-profiles criteria profile))))) ;; Old text from documentation of tramp-methods: @@ -5809,6 +5810,17 @@ Nonexistent directories are removed from spec." (lambda (x) (not (tramp-get-file-property vec x "file-directory-p"))) remote-path)))))) +(defun tramp-get-remote-arg-max (vec) + "Return ARG_MAX config from the remote side." + (with-tramp-connection-property vec "arg-max" + (when-let* ((result + (tramp-send-command-and-read + vec (format "getconf ARG_MAX 2>%s" + (tramp-get-remote-null-device vec)) + 'noerror)) + ((natnump result))) + result))) + ;; The PIPE_BUF in POSIX [1] can be as low as 512 [2]. Here are the values ;; on various platforms: ;; - 512 on macOS, FreeBSD, NetBSD, OpenBSD, MirBSD, native Windows. diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 0685de12494..553b76bd044 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -5227,11 +5227,17 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.") (delete-file local-copy))))) t))) +(defvar tramp-multi-hop-p-hook nil + "Abnormal hook for `tramp-multi-hop-p'. +This can be used by external Tramp backends to inform, that they are +multi-hop capable.") + (defun tramp-multi-hop-p (vec) "Whether the method of VEC is capable of multi-hops." (let ((tramp-verbose 0)) - (and (tramp-sh-file-name-handler-p vec) - (tramp-get-method-parameter vec 'tramp-login-args)))) + (or (and (tramp-sh-file-name-handler-p vec) + (tramp-get-method-parameter vec 'tramp-login-args)) + (run-hook-with-args-until-success 'tramp-multi-hop-p-hook vec)))) (defun tramp-add-hops (vec) "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'." @@ -5499,6 +5505,10 @@ processes." (setenv-internal env "HISTFILESIZE" "0" 'keep)) (t env)) env)) + ;; Add TERM. + (env (if sh-file-name-handler-p + (setenv-internal env "TERM" tramp-terminal-type 'keep) + env)) ;; Add INSIDE_EMACS. (env (setenv-internal env "INSIDE_EMACS" (tramp-inside-emacs) 'keep)) (env (mapcar #'tramp-shell-quote-argument (delq nil env)))