comparison lisp/net/tramp.el @ 84942:437d3bb02139

* net/tramp.el (tramp-maybe-open-connection): Make test for alive connection more robust.
author Michael Albinus <michael.albinus@gmx.de>
date Thu, 27 Sep 2007 04:37:33 +0000
parents b8f420afb6df
children fa9dd0b54e54
comparison
equal deleted inserted replaced
84941:89bab9e0761d 84942:437d3bb02139
2420 '(0 0) '(0 0) '(0 0) ;CCC how to find out? 2420 '(0 0) '(0 0) '(0 0) ;CCC how to find out?
2421 ;; 7. Size in bytes (-1, if number is out of range). 2421 ;; 7. Size in bytes (-1, if number is out of range).
2422 res-size 2422 res-size
2423 ;; 8. File modes, as a string of ten letters or dashes as in ls -l. 2423 ;; 8. File modes, as a string of ten letters or dashes as in ls -l.
2424 res-filemodes 2424 res-filemodes
2425 ;; 9. t iff file's gid would change if file were deleted and 2425 ;; 9. t if file's gid would change if file were deleted and
2426 ;; recreated. Will be set in `tramp-convert-file-attributes' 2426 ;; recreated. Will be set in `tramp-convert-file-attributes'
2427 t 2427 t
2428 ;; 10. inode number. 2428 ;; 10. inode number.
2429 res-inode 2429 res-inode
2430 ;; 11. Device number. Will be replaced by a virtual device number. 2430 ;; 11. Device number. Will be replaced by a virtual device number.
5686 ;; stty, instead. 5686 ;; stty, instead.
5687 (tramp-send-command-internal vec "stty -onlcr")))) 5687 (tramp-send-command-internal vec "stty -onlcr"))))
5688 (tramp-send-command-internal vec "set +o vi +o emacs") 5688 (tramp-send-command-internal vec "set +o vi +o emacs")
5689 (tramp-message vec 5 "Setting shell prompt") 5689 (tramp-message vec 5 "Setting shell prompt")
5690 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we must 5690 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we must
5691 ;; use "\n" here, not tramp-rsh-end-of-line. We also manually frob 5691 ;; use "\n" here, not tramp-rsh-end-of-line.
5692 ;; the last time we sent a command, to avoid `tramp-send-command' to
5693 ;; send "echo are you awake".
5694 (tramp-send-command 5692 (tramp-send-command
5695 vec 5693 vec
5696 (format "PROMPT_COMMAND=''; PS1='%s%s%s'; PS2=''; PS3=''" 5694 (format "PROMPT_COMMAND=''; PS1='%s%s%s'; PS2=''; PS3=''"
5697 tramp-rsh-end-of-line 5695 tramp-rsh-end-of-line
5698 tramp-end-of-output 5696 tramp-end-of-output
6042 ;; using ssh, it can sometimes happen that the remote end has hung 6040 ;; using ssh, it can sometimes happen that the remote end has hung
6043 ;; up but the local ssh client doesn't recognize this until it 6041 ;; up but the local ssh client doesn't recognize this until it
6044 ;; tries to send some data to the remote end. So that's why we 6042 ;; tries to send some data to the remote end. So that's why we
6045 ;; try to send a command from time to time, then look again 6043 ;; try to send a command from time to time, then look again
6046 ;; whether the process is really alive. 6044 ;; whether the process is really alive.
6047 (when (and (> (tramp-time-diff 6045 (condition-case nil
6048 (current-time) 6046 (when (and (> (tramp-time-diff
6049 (tramp-get-connection-property p "last-cmd-time" '(0 0 0))) 6047 (current-time)
6050 60) 6048 (tramp-get-connection-property
6051 p (processp p) (memq (process-status p) '(run open))) 6049 p "last-cmd-time" '(0 0 0)))
6052 (tramp-send-command vec "echo are you awake" t t) 6050 60)
6053 (unless (and (memq (process-status p) '(run open)) 6051 p (processp p) (memq (process-status p) '(run open)))
6054 (tramp-wait-for-output p 10)) 6052 (tramp-send-command vec "echo are you awake" t t)
6055 (delete-process p) 6053 (unless (and (memq (process-status p) '(run open))
6056 (setq p nil))) 6054 (tramp-wait-for-output p 10))
6055 ;; The error will be catched locally.
6056 (tramp-error vec 'file-error "Awake did fail")))
6057 (file-error
6058 (tramp-flush-connection-property vec nil)
6059 (tramp-flush-connection-property p nil)
6060 (delete-process p)
6061 (setq p nil)))
6057 6062
6058 ;; New connection must be opened. 6063 ;; New connection must be opened.
6059 (unless (and p (processp p) (memq (process-status p) '(run open))) 6064 (unless (and p (processp p) (memq (process-status p) '(run open)))
6060 6065
6061 ;; We call `tramp-get-buffer' in order to get a debug buffer for 6066 ;; We call `tramp-get-buffer' in order to get a debug buffer for
6569 (and (stringp host) 6574 (and (stringp host)
6570 (string-match tramp-host-with-port-regexp host) 6575 (string-match tramp-host-with-port-regexp host)
6571 (string-to-number (match-string 2 host))))) 6576 (string-to-number (match-string 2 host)))))
6572 6577
6573 (defun tramp-tramp-file-p (name) 6578 (defun tramp-tramp-file-p (name)
6574 "Return t iff NAME is a tramp file." 6579 "Return t if NAME is a tramp file."
6575 (save-match-data 6580 (save-match-data
6576 (string-match tramp-file-name-regexp name))) 6581 (string-match tramp-file-name-regexp name)))
6577 6582
6578 (defun tramp-find-method (method user host) 6583 (defun tramp-find-method (method user host)
6579 "Return the right method string to use. 6584 "Return the right method string to use.