Commit 28caedba authored by Michael Albinus's avatar Michael Albinus
Browse files

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'.
parent 51e7e463
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> 2015-03-15 Tassilo Horn <tsdh@gnu.org>
   
* emacs-lisp/lisp-mode.el (lisp--el-macro-regexp): New defconst. * emacs-lisp/lisp-mode.el (lisp--el-macro-regexp): New defconst.
......
...@@ -38,12 +38,14 @@ ...@@ -38,12 +38,14 @@
;; Pacify byte-compiler. ;; Pacify byte-compiler.
(defvar directory-sep-char) (defvar directory-sep-char)
;;;###tramp-autoload
(defcustom tramp-adb-program "adb" (defcustom tramp-adb-program "adb"
"Name of the Android Debug Bridge program." "Name of the Android Debug Bridge program."
:group 'tramp :group 'tramp
:version "24.4" :version "24.4"
:type 'string) :type 'string)
;;;###tramp-autoload
(defcustom tramp-adb-connect-if-not-connected nil (defcustom tramp-adb-connect-if-not-connected nil
"Try to run `adb connect' if provided device is not connected currently. "Try to run `adb connect' if provided device is not connected currently.
It is used for TCP/IP devices." It is used for TCP/IP devices."
...@@ -55,6 +57,7 @@ It is used for TCP/IP devices." ...@@ -55,6 +57,7 @@ It is used for TCP/IP devices."
(defconst tramp-adb-method "adb" (defconst tramp-adb-method "adb"
"*When this method name is used, forward all calls to Android Debug Bridge.") "*When this method name is used, forward all calls to Android Debug Bridge.")
;;;###tramp-autoload
(defcustom tramp-adb-prompt (defcustom tramp-adb-prompt
"^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]" "^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
"Regexp used as prompt in almquist shell." "Regexp used as prompt in almquist shell."
......
...@@ -127,6 +127,7 @@ ...@@ -127,6 +127,7 @@
;;;###tramp-autoload ;;;###tramp-autoload
(add-to-list 'tramp-default-user-alist '("\\`synce\\'" nil nil)) (add-to-list 'tramp-default-user-alist '("\\`synce\\'" nil nil))
;;;###tramp-autoload
(defcustom tramp-gvfs-zeroconf-domain "local" (defcustom tramp-gvfs-zeroconf-domain "local"
"Zeroconf domain to be used for discovering services, like host names." "Zeroconf domain to be used for discovering services, like host names."
:group 'tramp :group 'tramp
...@@ -374,6 +375,7 @@ It has been changed in GVFS 1.14.") ...@@ -374,6 +375,7 @@ It has been changed in GVFS 1.14.")
;; </signal> ;; </signal>
;; </interface> ;; </interface>
;;;###tramp-autoload
(defcustom tramp-bluez-discover-devices-timeout 60 (defcustom tramp-bluez-discover-devices-timeout 60
"Defines seconds since last bluetooth device discovery before rescanning. "Defines seconds since last bluetooth device discovery before rescanning.
A value of 0 would require an immediate discovery during hostname A value of 0 would require an immediate discovery during hostname
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
(defvar vc-git-program) (defvar vc-git-program)
(defvar vc-hg-program) (defvar vc-hg-program)
;;;###tramp-autoload
(defcustom tramp-inline-compress-start-size 4096 (defcustom tramp-inline-compress-start-size 4096
"The minimum size of compressing where inline transfer. "The minimum size of compressing where inline transfer.
When inline transfer, compress transferred data of file When inline transfer, compress transferred data of file
...@@ -48,6 +49,7 @@ If it is nil, no compression at all will be applied." ...@@ -48,6 +49,7 @@ If it is nil, no compression at all will be applied."
:group 'tramp :group 'tramp
:type '(choice (const nil) integer)) :type '(choice (const nil) integer))
;;;###tramp-autoload
(defcustom tramp-copy-size-limit 10240 (defcustom tramp-copy-size-limit 10240
"The maximum file size where inline copying is preferred over an \ "The maximum file size where inline copying is preferred over an \
out-of-the-band copy. out-of-the-band copy.
...@@ -105,6 +107,27 @@ detected as prompt when being sent on echoing hosts, therefore.") ...@@ -105,6 +107,27 @@ detected as prompt when being sent on echoing hosts, therefore.")
(defconst tramp-end-of-heredoc (md5 tramp-end-of-output) (defconst tramp-end-of-heredoc (md5 tramp-end-of-output)
"String used to recognize end of heredoc strings.") "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. ;; Initialize `tramp-methods' with the supported methods.
;;;###tramp-autoload ;;;###tramp-autoload
(add-to-list 'tramp-methods (add-to-list 'tramp-methods
...@@ -489,6 +512,7 @@ not be set here. Instead, it should be set via `tramp-remote-path'." ...@@ -489,6 +512,7 @@ not be set here. Instead, it should be set via `tramp-remote-path'."
:version "24.4" :version "24.4"
:type '(repeat string)) :type '(repeat string))
;;;###tramp-autoload
(defcustom tramp-sh-extra-args '(("/bash\\'" . "-norc -noprofile")) (defcustom tramp-sh-extra-args '(("/bash\\'" . "-norc -noprofile"))
"Alist specifying extra arguments to pass to the remote shell. "Alist specifying extra arguments to pass to the remote shell.
Entries are (REGEXP . ARGS) where REGEXP is a regular expression Entries are (REGEXP . ARGS) where REGEXP is a regular expression
...@@ -2354,10 +2378,7 @@ The method used must be an out-of-band method." ...@@ -2354,10 +2378,7 @@ The method used must be an out-of-band method."
spec (format-spec-make spec (format-spec-make
?t (tramp-get-connection-property ?t (tramp-get-connection-property
(tramp-get-connection-process v) "temp-file" "")) (tramp-get-connection-process v) "temp-file" ""))
options (format-spec options (format-spec (tramp-ssh-controlmaster-options v) spec)
(if tramp-use-ssh-controlmaster-options
tramp-ssh-controlmaster-options "")
spec)
spec (format-spec-make spec (format-spec-make
?h host ?u user ?p port ?r listener ?c options ?h host ?u user ?p port ?r listener ?c options
?k (if keep-date " " "")) ?k (if keep-date " " ""))
...@@ -4566,6 +4587,49 @@ Gateway hops are already opened." ...@@ -4566,6 +4587,49 @@ Gateway hops are already opened."
;; Result. ;; Result.
target-alist)) 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) (defun tramp-maybe-open-connection (vec)
"Maybe open a connection VEC. "Maybe open a connection VEC.
Does not do anything if a connection is already open, but re-opens the 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." ...@@ -4647,8 +4711,7 @@ connection if a previous connection has died for some reason."
(let* ((target-alist (tramp-compute-multi-hops vec)) (let* ((target-alist (tramp-compute-multi-hops vec))
;; We will apply `tramp-ssh-controlmaster-options' ;; We will apply `tramp-ssh-controlmaster-options'
;; only for the first hop. ;; only for the first hop.
(options (if tramp-use-ssh-controlmaster-options (options (tramp-ssh-controlmaster-options vec))
tramp-ssh-controlmaster-options ""))
(process-connection-type tramp-process-connection-type) (process-connection-type tramp-process-connection-type)
(process-adaptive-read-buffering nil) (process-adaptive-read-buffering nil)
(coding-system-for-read nil) (coding-system-for-read nil)
......
...@@ -70,17 +70,20 @@ ...@@ -70,17 +70,20 @@
tramp-smb-method tramp-smb-method
'((tramp-parse-netrc "~/.netrc")))) '((tramp-parse-netrc "~/.netrc"))))
;;;###tramp-autoload
(defcustom tramp-smb-program "smbclient" (defcustom tramp-smb-program "smbclient"
"Name of SMB client to run." "Name of SMB client to run."
:group 'tramp :group 'tramp
:type 'string) :type 'string)
;;;###tramp-autoload
(defcustom tramp-smb-acl-program "smbcacls" (defcustom tramp-smb-acl-program "smbcacls"
"Name of SMB acls to run." "Name of SMB acls to run."
:group 'tramp :group 'tramp
:type 'string :type 'string
:version "24.4") :version "24.4")
;;;###tramp-autoload
(defcustom tramp-smb-conf "/dev/null" (defcustom tramp-smb-conf "/dev/null"
"Path of the smb.conf file. "Path of the smb.conf file.
If it is nil, no smb.conf will be added to the `tramp-smb-program' 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.") ...@@ -280,6 +283,7 @@ See `tramp-actions-before-shell' for more info.")
Operations not mentioned here will be handled by the default Emacs primitives.") Operations not mentioned here will be handled by the default Emacs primitives.")
;; Options for remote processes via winexe. ;; Options for remote processes via winexe.
;;;###tramp-autoload
(defcustom tramp-smb-winexe-program "winexe" (defcustom tramp-smb-winexe-program "winexe"
"Name of winexe client to run. "Name of winexe client to run.
If it isn't found in the local $PATH, the absolute path of winexe 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." ...@@ -288,6 +292,7 @@ shall be given. This is needed for remote processes."
:type 'string :type 'string
:version "24.3") :version "24.3")
;;;###tramp-autoload
(defcustom tramp-smb-winexe-shell-command "powershell.exe" (defcustom tramp-smb-winexe-shell-command "powershell.exe"
"Shell to be used for processes on remote machines. "Shell to be used for processes on remote machines.
This must be Powershell V2 compatible." This must be Powershell V2 compatible."
...@@ -295,6 +300,7 @@ This must be Powershell V2 compatible." ...@@ -295,6 +300,7 @@ This must be Powershell V2 compatible."
:type 'string :type 'string
:version "24.3") :version "24.3")
;;;###tramp-autoload
(defcustom tramp-smb-winexe-shell-command-switch "-file -" (defcustom tramp-smb-winexe-shell-command-switch "-file -"
"Command switch used together with `tramp-smb-winexe-shell-command'. "Command switch used together with `tramp-smb-winexe-shell-command'.
This can be used to disable echo etc." This can be used to disable echo etc."
......
...@@ -307,43 +307,6 @@ started on the local host. You should specify a remote host ...@@ -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 `localhost' or the name of the local host. Another host name is
useful only in combination with `tramp-default-proxies-alist'.") 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 (defcustom tramp-default-method
;; An external copy method seems to be preferred, because it performs ;; An external copy method seems to be preferred, because it performs
;; much better for large files, and it hasn't too serious delays ;; 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'.") ...@@ -374,9 +337,7 @@ Return a string to be used in `tramp-methods'.")
(fboundp 'auth-source-search) (fboundp 'auth-source-search)
;; ssh-agent is running. ;; ssh-agent is running.
(getenv "SSH_AUTH_SOCK") (getenv "SSH_AUTH_SOCK")
(getenv "SSH_AGENT_PID") (getenv "SSH_AGENT_PID"))
;; We could reuse the connection.
(> (length tramp-ssh-controlmaster-options) 0))
"scp" "scp"
"ssh")) "ssh"))
;; Fallback. ;; Fallback.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment