In Tramp. check ssh Control* options only when needed

Fixes: debbugs:20015

* net/tramp-adb.el:
* net/tramp-gvfs.el:
* net/tramp-sh.el:
* net/tramp-smb.el: Set tramp-autoload cookie for all defcustoms.

* net/tramp-sh.el (tramp-use-ssh-controlmaster-options):
New defcustom, moved from tramp.el.
(tramp-ssh-controlmaster-options): New defvar, moved from tramp.el
but with a nil initial value.
(tramp-ssh-controlmaster-options): New defun.
(tramp-do-copy-or-rename-file-out-of-band)
(tramp-maybe-open-connection): Use it.

* net/tramp.el (tramp-ssh-controlmaster-options)
(tramp-use-ssh-controlmaster-options): Move them to tramp-sh.el.
(tramp-default-method): Do not check for
`tramp-ssh-controlmaster-options'.
This commit is contained in:
Michael Albinus 2015-03-15 16:07:03 +01:00
parent 51e7e463e9
commit 28caedba0f
6 changed files with 101 additions and 46 deletions

View file

@ -1,3 +1,23 @@
2015-03-15 Michael Albinus <michael.albinus@gmx.de>
* net/tramp-adb.el:
* net/tramp-gvfs.el:
* net/tramp-sh.el:
* net/tramp-smb.el: Set tramp-autoload cookie for all defcustoms.
* net/tramp.el (tramp-ssh-controlmaster-options)
(tramp-use-ssh-controlmaster-options): Move them to tramp-sh.el.
(tramp-default-method): Do not check for
`tramp-ssh-controlmaster-options'.
* net/tramp-sh.el (tramp-use-ssh-controlmaster-options):
New defcustom, moved from tramp.el.
(tramp-ssh-controlmaster-options): New defvar, moved from tramp.el
but with a nil initial value.
(tramp-ssh-controlmaster-options): New defun.
(tramp-do-copy-or-rename-file-out-of-band)
(tramp-maybe-open-connection): Use it. (Bug#20015)
2015-03-15 Tassilo Horn <tsdh@gnu.org>
* emacs-lisp/lisp-mode.el (lisp--el-macro-regexp): New defconst.

View file

@ -38,12 +38,14 @@
;; Pacify byte-compiler.
(defvar directory-sep-char)
;;;###tramp-autoload
(defcustom tramp-adb-program "adb"
"Name of the Android Debug Bridge program."
:group 'tramp
:version "24.4"
:type 'string)
;;;###tramp-autoload
(defcustom tramp-adb-connect-if-not-connected nil
"Try to run `adb connect' if provided device is not connected currently.
It is used for TCP/IP devices."
@ -55,6 +57,7 @@ It is used for TCP/IP devices."
(defconst tramp-adb-method "adb"
"*When this method name is used, forward all calls to Android Debug Bridge.")
;;;###tramp-autoload
(defcustom tramp-adb-prompt
"^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
"Regexp used as prompt in almquist shell."

View file

@ -127,6 +127,7 @@
;;;###tramp-autoload
(add-to-list 'tramp-default-user-alist '("\\`synce\\'" nil nil))
;;;###tramp-autoload
(defcustom tramp-gvfs-zeroconf-domain "local"
"Zeroconf domain to be used for discovering services, like host names."
:group 'tramp
@ -374,6 +375,7 @@ It has been changed in GVFS 1.14.")
;; </signal>
;; </interface>
;;;###tramp-autoload
(defcustom tramp-bluez-discover-devices-timeout 60
"Defines seconds since last bluetooth device discovery before rescanning.
A value of 0 would require an immediate discovery during hostname

View file

@ -40,6 +40,7 @@
(defvar vc-git-program)
(defvar vc-hg-program)
;;;###tramp-autoload
(defcustom tramp-inline-compress-start-size 4096
"The minimum size of compressing where inline transfer.
When inline transfer, compress transferred data of file
@ -48,6 +49,7 @@ If it is nil, no compression at all will be applied."
:group 'tramp
:type '(choice (const nil) integer))
;;;###tramp-autoload
(defcustom tramp-copy-size-limit 10240
"The maximum file size where inline copying is preferred over an \
out-of-the-band copy.
@ -105,6 +107,27 @@ detected as prompt when being sent on echoing hosts, therefore.")
(defconst tramp-end-of-heredoc (md5 tramp-end-of-output)
"String used to recognize end of heredoc strings.")
;;;###tramp-autoload
(defcustom tramp-use-ssh-controlmaster-options t
"Whether to use `tramp-ssh-controlmaster-options'."
:group 'tramp
:version "24.4"
:type 'boolean)
(defvar tramp-ssh-controlmaster-options nil
"Which ssh Control* arguments to use.
If it is a string, it should have the form
\"-o ControlMaster=auto -o ControlPath='tramp.%%r@%%h:%%p'
-o ControlPersist=no\". Percent characters in the ControlPath
spec must be doubled, because the string is used as format string.
Otherwise, it will be auto-detected by Tramp, if
`tramp-use-ssh-controlmaster-options' is non-nil. The value
depends on the installed local ssh version.
The string is used in `tramp-methods'.")
;; Initialize `tramp-methods' with the supported methods.
;;;###tramp-autoload
(add-to-list 'tramp-methods
@ -489,6 +512,7 @@ not be set here. Instead, it should be set via `tramp-remote-path'."
:version "24.4"
:type '(repeat string))
;;;###tramp-autoload
(defcustom tramp-sh-extra-args '(("/bash\\'" . "-norc -noprofile"))
"Alist specifying extra arguments to pass to the remote shell.
Entries are (REGEXP . ARGS) where REGEXP is a regular expression
@ -2354,10 +2378,7 @@ The method used must be an out-of-band method."
spec (format-spec-make
?t (tramp-get-connection-property
(tramp-get-connection-process v) "temp-file" ""))
options (format-spec
(if tramp-use-ssh-controlmaster-options
tramp-ssh-controlmaster-options "")
spec)
options (format-spec (tramp-ssh-controlmaster-options v) spec)
spec (format-spec-make
?h host ?u user ?p port ?r listener ?c options
?k (if keep-date " " ""))
@ -4566,6 +4587,49 @@ Gateway hops are already opened."
;; Result.
target-alist))
(defun tramp-ssh-controlmaster-options (vec)
"Return the Control* arguments of the local ssh."
(cond
;; No options to be computed.
((or (null tramp-use-ssh-controlmaster-options)
(null (assoc "%c" (tramp-get-method-parameter
(tramp-file-name-method vec) 'tramp-login-args))))
"")
;; There is already a value to be used.
((stringp tramp-ssh-controlmaster-options) tramp-ssh-controlmaster-options)
;; Determine the options.
(t (setq tramp-ssh-controlmaster-options "")
(let ((case-fold-search t))
(ignore-errors
(when (executable-find "ssh")
(with-temp-buffer
(tramp-call-process vec "ssh" nil t nil "-o" "ControlMaster")
(goto-char (point-min))
(when (search-forward-regexp "missing.+argument" nil t)
(setq tramp-ssh-controlmaster-options "-o ControlMaster=auto")))
(unless (zerop (length tramp-ssh-controlmaster-options))
(with-temp-buffer
(tramp-call-process
vec "ssh" nil t nil
"-o" "ControlPath=%C" "host.does.not.exist")
(goto-char (point-min))
(setq tramp-ssh-controlmaster-options
(if (search-forward-regexp "unknown.+key" nil t)
(concat tramp-ssh-controlmaster-options
" -o ControlPath='tramp.%%r@%%h:%%p'")
(concat tramp-ssh-controlmaster-options
" -o ControlPath='tramp.%%C'"))))
(with-temp-buffer
(tramp-call-process vec "ssh" nil t nil "-o" "ControlPersist")
(goto-char (point-min))
(when (search-forward-regexp "missing.+argument" nil t)
(setq tramp-ssh-controlmaster-options
(concat tramp-ssh-controlmaster-options
" -o ControlPersist=no"))))))))
tramp-ssh-controlmaster-options)))
(defun tramp-maybe-open-connection (vec)
"Maybe open a connection VEC.
Does not do anything if a connection is already open, but re-opens the
@ -4647,8 +4711,7 @@ connection if a previous connection has died for some reason."
(let* ((target-alist (tramp-compute-multi-hops vec))
;; We will apply `tramp-ssh-controlmaster-options'
;; only for the first hop.
(options (if tramp-use-ssh-controlmaster-options
tramp-ssh-controlmaster-options ""))
(options (tramp-ssh-controlmaster-options vec))
(process-connection-type tramp-process-connection-type)
(process-adaptive-read-buffering nil)
(coding-system-for-read nil)

View file

@ -70,17 +70,20 @@
tramp-smb-method
'((tramp-parse-netrc "~/.netrc"))))
;;;###tramp-autoload
(defcustom tramp-smb-program "smbclient"
"Name of SMB client to run."
:group 'tramp
:type 'string)
;;;###tramp-autoload
(defcustom tramp-smb-acl-program "smbcacls"
"Name of SMB acls to run."
:group 'tramp
:type 'string
:version "24.4")
;;;###tramp-autoload
(defcustom tramp-smb-conf "/dev/null"
"Path of the smb.conf file.
If it is nil, no smb.conf will be added to the `tramp-smb-program'
@ -280,6 +283,7 @@ See `tramp-actions-before-shell' for more info.")
Operations not mentioned here will be handled by the default Emacs primitives.")
;; Options for remote processes via winexe.
;;;###tramp-autoload
(defcustom tramp-smb-winexe-program "winexe"
"Name of winexe client to run.
If it isn't found in the local $PATH, the absolute path of winexe
@ -288,6 +292,7 @@ shall be given. This is needed for remote processes."
:type 'string
:version "24.3")
;;;###tramp-autoload
(defcustom tramp-smb-winexe-shell-command "powershell.exe"
"Shell to be used for processes on remote machines.
This must be Powershell V2 compatible."
@ -295,6 +300,7 @@ This must be Powershell V2 compatible."
:type 'string
:version "24.3")
;;;###tramp-autoload
(defcustom tramp-smb-winexe-shell-command-switch "-file -"
"Command switch used together with `tramp-smb-winexe-shell-command'.
This can be used to disable echo etc."

View file

@ -307,43 +307,6 @@ started on the local host. You should specify a remote host
`localhost' or the name of the local host. Another host name is
useful only in combination with `tramp-default-proxies-alist'.")
;;;###tramp-autoload
(defconst tramp-ssh-controlmaster-options
(let ((result "")
(case-fold-search t))
(ignore-errors
(when (executable-find "ssh")
(with-temp-buffer
(call-process "ssh" nil t nil "-o" "ControlMaster")
(goto-char (point-min))
(when (search-forward-regexp "missing.+argument" nil t)
(setq result "-o ControlMaster=auto")))
(unless (zerop (length result))
(with-temp-buffer
(call-process
"ssh" nil t nil "-o" "ControlPath=%C" "host.does.not.exist")
(goto-char (point-min))
(if (search-forward-regexp "unknown.+key" nil t)
(setq result
(concat result " -o ControlPath='tramp.%%r@%%h:%%p'"))
(setq result (concat result " -o ControlPath='tramp.%%C'"))))
(with-temp-buffer
(call-process "ssh" nil t nil "-o" "ControlPersist")
(goto-char (point-min))
(when (search-forward-regexp "missing.+argument" nil t)
(setq result (concat result " -o ControlPersist=no")))))))
result)
"Call ssh to detect whether it supports the Control* arguments.
Return a string to be used in `tramp-methods'.")
;;;###tramp-autoload
(defcustom tramp-use-ssh-controlmaster-options
(not (zerop (length tramp-ssh-controlmaster-options)))
"Whether to use `tramp-ssh-controlmaster-options'."
:group 'tramp
:version "24.4"
:type 'boolean)
(defcustom tramp-default-method
;; An external copy method seems to be preferred, because it performs
;; much better for large files, and it hasn't too serious delays
@ -374,9 +337,7 @@ Return a string to be used in `tramp-methods'.")
(fboundp 'auth-source-search)
;; ssh-agent is running.
(getenv "SSH_AUTH_SOCK")
(getenv "SSH_AGENT_PID")
;; We could reuse the connection.
(> (length tramp-ssh-controlmaster-options) 0))
(getenv "SSH_AGENT_PID"))
"scp"
"ssh"))
;; Fallback.