]> code.delx.au - gnu-emacs/blobdiff - lisp/net/tramp.el
Use ControlMaster where applicable. (Bug#13677)
[gnu-emacs] / lisp / net / tramp.el
index 045304cbc4f05b760577dbb20b90f36ae0f83c1a..a4250f9498818e85977bbcf387282c7f2cca0265 100644 (file)
@@ -280,15 +280,18 @@ 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'.")
 
-(defun tramp-detect-ssh-controlmaster ()
-  "Call ssh to detect whether it supports the ControlMaster argument.
-This function may return nil when the argument is supported, but
-shouldn't return t when it isn't."
-  (ignore-errors
-    (with-temp-buffer
-      (call-process "ssh" nil t nil "-o" "ControlMaster")
-      (goto-char (point-min))
-      (search-forward-regexp "Missing ControlMaster argument" nil t))))
+;;;###tramp-autoload
+(defvar tramp-ssh-controlmaster-template
+    (ignore-errors
+      (with-temp-buffer
+       (call-process "ssh" nil t nil "-o" "ControlMaster")
+       (goto-char (point-min))
+       (when (search-forward-regexp "Missing ControlMaster argument" nil t)
+         '("-o" "ControlPath=%t.%%r@%%h:%%p"
+           "-o" "ControlMaster=auto"
+           "-o" "ControlPersist=no"))))
+    "Call ssh to detect whether it supports the ControlMaster argument.
+Return a template to be used in `tramp-methods'.")
 
 (defcustom tramp-default-method
   ;; An external copy method seems to be preferred, because it performs
@@ -297,8 +300,9 @@ shouldn't return t when it isn't."
   ;; permanent password queries.  Either a password agent like
   ;; "ssh-agent" or "Pageant" shall run, or the optional
   ;; password-cache.el or auth-sources.el packages shall be active for
-  ;; password caching.  "scpc" is chosen if we detect that the user is
-  ;; running OpenSSH 4.0 or newer.
+  ;; password caching.  If we detect that the user is running OpenSSH
+  ;; 4.0 or newer, we could reuse the connection, which calls also for
+  ;; an external method.
   (cond
    ;; PuTTY is installed.  We don't take it, if it is installed on a
    ;; non-windows system, or pscp from the pssh (parallel ssh) package
@@ -314,16 +318,16 @@ shouldn't return t when it isn't."
       "plink"))
    ;; There is an ssh installation.
    ((executable-find "scp")
-    (cond
-     ((tramp-detect-ssh-controlmaster) "scpc")
-     ((or (fboundp 'password-read)
-         (fboundp 'auth-source-user-or-password)
-         (fboundp 'auth-source-search)
-         ;; ssh-agent is running.
-         (getenv "SSH_AUTH_SOCK")
-         (getenv "SSH_AGENT_PID"))
-      "scp")
-     (t "ssh")))
+    (if        (or (fboundp 'password-read)
+           (fboundp 'auth-source-user-or-password)
+           (fboundp 'auth-source-search)
+           ;; ssh-agent is running.
+           (getenv "SSH_AUTH_SOCK")
+           (getenv "SSH_AGENT_PID")
+           ;; We could reuse the connection.
+           tramp-ssh-controlmaster-template)
+       "scp"
+      "ssh"))
    ;; Fallback.
    (t "ftp"))
   "Default method to use for transferring files.
@@ -1018,11 +1022,25 @@ this variable to be set as well."
 ;; for an override of the system default.
 (defcustom tramp-process-connection-type t
   "Overrides `process-connection-type' for connections from Tramp.
-Tramp binds process-connection-type to the value given here before
+Tramp binds `process-connection-type' to the value given here before
 opening a connection to a remote host."
   :group 'tramp
   :type '(choice (const nil) (const t) (const pty)))
 
+(defcustom tramp-connection-min-time-diff 5
+  "Defines seconds between two consecutive connection attempts.
+This is necessary as self defense mechanism, in order to avoid
+yo-yo connection attempts when the remote host is unavailable.
+
+A value of 0 or `nil' suppresses this check.  This might be
+necessary, when several out-of-order copy operations are
+performed, or when several asynchronous processes will be started
+in a short time frame.  In those cases it is recommended to
+let-bind this variable."
+  :group 'tramp
+  :version "24.4"
+  :type '(choice (const nil) integer))
+
 (defcustom tramp-completion-reread-directory-timeout 10
   "Defines seconds since last remote command before rereading a directory.
 A remote directory might have changed its contents.  In order to
@@ -1033,7 +1051,7 @@ have been gone since last remote command execution.  A value of `t'
 would require an immediate reread during filename completion, `nil'
 means to use always cached values for the directory contents."
   :group 'tramp
-  :type '(choice (const nil) integer))
+  :type '(choice (const nil) (const t) integer))
 
 ;;; Internal Variables:
 
@@ -1144,7 +1162,7 @@ If the `tramp-methods' entry does not exist, return nil."
 It checks also, whether NAME is unibyte encoded."
   (save-match-data
     (and (stringp name)
-        (string-equal name (string-as-unibyte name))
+;       (string-equal name (string-as-unibyte name))
         (string-match tramp-file-name-regexp name))))
 
 (defun tramp-find-method (method user host)
@@ -1377,7 +1395,9 @@ ARGS to actually emit the message (if applicable)."
                     (concat
                      "^"
                      (regexp-opt
-                      '("tramp-compat-funcall"
+                      '("tramp-backtrace"
+                        "tramp-compat-condition-case-unless-debug"
+                        "tramp-compat-funcall"
                         "tramp-compat-with-temp-message"
                         "tramp-debug-message"
                         "tramp-error"
@@ -1491,6 +1511,11 @@ an input event arrives.  The other arguments are passed to `tramp-error'."
             "`M-x tramp-cleanup-this-connection'"))
          (sit-for 30))))))
 
+(defsubst tramp-backtrace (vec-or-proc)
+  "Dump a backtrace into the debug buffer.
+This function is meant for debugging purposes."
+  (tramp-message vec-or-proc 10 "\n%s" (with-output-to-string (backtrace))))
+
 (defmacro with-parsed-tramp-file-name (filename var &rest body)
   "Parse a Tramp filename and make components available in the body.
 
@@ -3009,13 +3034,15 @@ User is always nil."
                  (setq tramp-temp-buffer-file-name local-copy))
 
                ;; We must ensure that `file-coding-system-alist'
-               ;; matches `local-copy'.
+               ;; matches `local-copy'.  We must also use `visit',
+               ;; otherwise there might be an error in the
+               ;; `revert-buffer' function under XEmacs.
                (let ((file-coding-system-alist
                       (tramp-find-file-name-coding-system-alist
                        filename local-copy)))
                  (setq result
                        (insert-file-contents
-                        local-copy nil nil nil replace)))))
+                        local-copy visit nil nil replace)))))
 
          ;; Save exit.
          (progn
@@ -3399,7 +3426,9 @@ Erase echoed commands if exists."
                     0 (min tramp-echo-mark-marker-length (1- (point-max))))
                    (tramp-compat-funcall
                     'buffer-substring-no-properties
-                    1 (min (1+ tramp-echo-mark-marker-length) (point-max))))))
+                    (point-min)
+                    (min (+ (point-min) tramp-echo-mark-marker-length)
+                         (point-max))))))
       ;; No echo to be handled, now we can look for the regexp.
       ;; Sometimes, lines are much to long, and we run into a "Stack
       ;; overflow in regexp matcher".  For example, //DIRED// lines of