aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2007-10-22 19:09:51 +0000
committerMichael Albinus2007-10-22 19:09:51 +0000
commit7e780ff12c9e8a6cf30b7377232f1f214706e440 (patch)
tree62d0ced8c40f0b6f46fcdd640d08c978ce5a2b8f
parent916e6880262ac111c24886f815ce8a42d0b29fb7 (diff)
downloademacs-7e780ff12c9e8a6cf30b7377232f1f214706e440.tar.gz
emacs-7e780ff12c9e8a6cf30b7377232f1f214706e440.zip
* net/tramp.el (tramp-find-shell)
(tramp-open-connection-setup-interactive-shell): Improve sending initial commands. (tramp-action-terminal): Send debug message. (tramp-wait-for-shell-prompt, tramp-send-command-internal): Removed. (tramp-barf-if-no-shell-prompt): Insert code of `tramp-wait-for-shell-prompt'.
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/net/tramp.el104
2 files changed, 59 insertions, 55 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 32c70dc3479..374fc19531d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12007-10-22 Michael Albinus <michael.albinus@gmx.de>
2
3 * net/tramp.el (tramp-find-shell)
4 (tramp-open-connection-setup-interactive-shell): Improve sending
5 initial commands.
6 (tramp-action-terminal): Send debug message.
7 (tramp-wait-for-shell-prompt, tramp-send-command-internal): Removed.
8 (tramp-barf-if-no-shell-prompt): Insert code of
9 `tramp-wait-for-shell-prompt'.
10
12007-10-22 Stefan Monnier <monnier@iro.umontreal.ca> 112007-10-22 Stefan Monnier <monnier@iro.umontreal.ca>
2 12
3 * term/AT386.el (terminal-init-AT386): Use input-decode-map. 13 * term/AT386.el (terminal-init-AT386): Use input-decode-map.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 865a3c51837..881fa6ceb5a 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -5306,7 +5306,7 @@ file exists and nonzero exit status otherwise."
5306 (unless (tramp-get-connection-property vec "remote-shell" nil) 5306 (unless (tramp-get-connection-property vec "remote-shell" nil)
5307 (let (shell) 5307 (let (shell)
5308 (with-current-buffer (tramp-get-buffer vec) 5308 (with-current-buffer (tramp-get-buffer vec)
5309 (tramp-send-command vec "echo ~root") 5309 (tramp-send-command vec "echo ~root" t)
5310 (cond 5310 (cond
5311 ((string-match "^~root$" (buffer-string)) 5311 ((string-match "^~root$" (buffer-string))
5312 (setq shell 5312 (setq shell
@@ -5328,8 +5328,11 @@ file exists and nonzero exit status otherwise."
5328 (when extra-args (setq shell (concat shell " " extra-args)))) 5328 (when extra-args (setq shell (concat shell " " extra-args))))
5329 (tramp-message 5329 (tramp-message
5330 vec 5 "Starting remote shell `%s' for tilde expansion..." shell) 5330 vec 5 "Starting remote shell `%s' for tilde expansion..." shell)
5331 (tramp-send-command-internal 5331 (tramp-message
5332 vec (concat "PROMPT_COMMAND='' PS1='$ ' exec " shell)) 5332 vec 6 (format "PROMPT_COMMAND='' PS1='$ ' exec %s" shell))
5333 ;; We just send a string only without checking resulting prompt.
5334 (tramp-send-string
5335 vec (format "PROMPT_COMMAND='' PS1='$ ' exec %s" shell))
5333 (tramp-message vec 5 "Setting remote shell prompt...") 5336 (tramp-message vec 5 "Setting remote shell prompt...")
5334 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we 5337 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we
5335 ;; must use "\n" here, not tramp-rsh-end-of-line. Kai left the 5338 ;; must use "\n" here, not tramp-rsh-end-of-line. Kai left the
@@ -5340,7 +5343,8 @@ file exists and nonzero exit status otherwise."
5340 (format "PROMPT_COMMAND=''; PS1='%s%s%s'; PS2=''; PS3=''" 5343 (format "PROMPT_COMMAND=''; PS1='%s%s%s'; PS2=''; PS3=''"
5341 tramp-rsh-end-of-line 5344 tramp-rsh-end-of-line
5342 tramp-end-of-output 5345 tramp-end-of-output
5343 tramp-rsh-end-of-line)) 5346 tramp-rsh-end-of-line)
5347 t)
5344 (tramp-message vec 5 "Setting remote shell prompt...done")) 5348 (tramp-message vec 5 "Setting remote shell prompt...done"))
5345 (t (tramp-message 5349 (t (tramp-message
5346 vec 5 "Remote `%s' groks tilde expansion, good" 5350 vec 5 "Remote `%s' groks tilde expansion, good"
@@ -5417,6 +5421,8 @@ See also `tramp-action-yesno'."
5417 "Tell the remote host which terminal type to use. 5421 "Tell the remote host which terminal type to use.
5418The terminal type can be configured with `tramp-terminal-type'." 5422The terminal type can be configured with `tramp-terminal-type'."
5419 (tramp-message vec 5 "Setting `%s' as terminal type." tramp-terminal-type) 5423 (tramp-message vec 5 "Setting `%s' as terminal type." tramp-terminal-type)
5424 (with-current-buffer (tramp-get-connection-buffer vec)
5425 (tramp-message vec 6 "\n%s" (buffer-string)))
5420 (tramp-send-string vec tramp-terminal-type)) 5426 (tramp-send-string vec tramp-terminal-type))
5421 5427
5422(defun tramp-action-process-alive (proc vec) 5428(defun tramp-action-process-alive (proc vec)
@@ -5562,33 +5568,28 @@ nil."
5562 (tramp-error proc 'file-error "[[Regexp `%s' not found]]" regexp))) 5568 (tramp-error proc 'file-error "[[Regexp `%s' not found]]" regexp)))
5563 found))) 5569 found)))
5564 5570
5565(defun tramp-wait-for-shell-prompt (proc timeout)
5566 "Wait for the shell prompt to appear from process PROC within TIMEOUT seconds.
5567See `tramp-wait-for-regexp' for more details.
5568Shell prompt pattern is determined by variables `shell-prompt-pattern'
5569and `tramp-shell-prompt-pattern'."
5570 (tramp-wait-for-regexp
5571 proc timeout
5572 (format "\\(%s\\|%s\\)\\'"
5573 shell-prompt-pattern tramp-shell-prompt-pattern)))
5574
5575(defun tramp-barf-if-no-shell-prompt (proc timeout &rest error-args) 5571(defun tramp-barf-if-no-shell-prompt (proc timeout &rest error-args)
5576 "Wait for shell prompt and barf if none appears. 5572 "Wait for shell prompt and barf if none appears.
5577Looks at process PROC to see if a shell prompt appears in TIMEOUT 5573Looks at process PROC to see if a shell prompt appears in TIMEOUT
5578seconds. If not, it produces an error message with the given ERROR-ARGS." 5574seconds. If not, it produces an error message with the given ERROR-ARGS."
5579 (unless (tramp-wait-for-shell-prompt proc timeout) 5575 (unless
5576 (tramp-wait-for-regexp
5577 proc timeout
5578 (format
5579 "\\(%s\\|%s\\)\\'" shell-prompt-pattern tramp-shell-prompt-pattern))
5580 (apply 'tramp-error-with-buffer nil proc 'file-error error-args))) 5580 (apply 'tramp-error-with-buffer nil proc 'file-error error-args)))
5581 5581
5582;; We don't call `tramp-send-string' in order to hide the password from the 5582;; We don't call `tramp-send-string' in order to hide the password
5583;; debug buffer, and because end-of-line handling of the string. 5583;; from the debug buffer, and because end-of-line handling of the
5584(defun tramp-enter-password (p) 5584;; string.
5585(defun tramp-enter-password (proc)
5585 "Prompt for a password and send it to the remote end." 5586 "Prompt for a password and send it to the remote end."
5586 (process-send-string 5587 (process-send-string
5587 p (concat (tramp-read-passwd p) 5588 proc (concat (tramp-read-passwd proc)
5588 (or (tramp-get-method-parameter 5589 (or (tramp-get-method-parameter
5589 tramp-current-method 5590 tramp-current-method
5590 'tramp-password-end-of-line) 5591 'tramp-password-end-of-line)
5591 tramp-default-password-end-of-line)))) 5592 tramp-default-password-end-of-line))))
5592 5593
5593(defun tramp-open-connection-setup-interactive-shell (proc vec) 5594(defun tramp-open-connection-setup-interactive-shell (proc vec)
5594 "Set up an interactive shell. 5595 "Set up an interactive shell.
@@ -5607,17 +5608,32 @@ process to set up. VEC specifies the connection."
5607 ;; called as sh) on startup; this way, we avoid the startup file 5608 ;; called as sh) on startup; this way, we avoid the startup file
5608 ;; clobbering $PS1. $PROMP_COMMAND is another way to set the prompt 5609 ;; clobbering $PS1. $PROMP_COMMAND is another way to set the prompt
5609 ;; in /bin/bash, it must be discarded as well. 5610 ;; in /bin/bash, it must be discarded as well.
5610 (tramp-send-command-internal 5611 (tramp-message
5612 vec 6 (format "exec env 'ENV=' 'PROMPT_COMMAND=' 'PS1=$ ' %s"
5613 (tramp-get-method-parameter
5614 (tramp-file-name-method vec) 'tramp-remote-sh)))
5615 ;; We just send a string only without checking resulting prompt.
5616 (tramp-send-string
5611 vec 5617 vec
5612 (format "exec env 'ENV=' 'PROMPT_COMMAND=' 'PS1=$ ' %s" 5618 (format "exec env 'ENV=' 'PROMPT_COMMAND=' 'PS1=$ ' %s"
5613 (tramp-get-method-parameter 5619 (tramp-get-method-parameter
5614 (tramp-file-name-method vec) 'tramp-remote-sh))) 5620 (tramp-file-name-method vec) 'tramp-remote-sh)))
5621 (tramp-message vec 5 "Setting shell prompt")
5622 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we must
5623 ;; use "\n" here, not tramp-rsh-end-of-line.
5624 (tramp-send-command
5625 vec
5626 (format "PROMPT_COMMAND=''; PS1='%s%s%s'; PS2=''; PS3=''"
5627 tramp-rsh-end-of-line
5628 tramp-end-of-output
5629 tramp-rsh-end-of-line)
5630 t)
5615 (tramp-message vec 5 "Setting up remote shell environment") 5631 (tramp-message vec 5 "Setting up remote shell environment")
5616 (tramp-send-command-internal vec "stty -inlcr -echo kill '^U' erase '^H'") 5632 (tramp-send-command vec "stty -inlcr -echo kill '^U' erase '^H'" t)
5617 ;; Check whether the echo has really been disabled. Some 5633 ;; Check whether the echo has really been disabled. Some
5618 ;; implementations, like busybox of embedded GNU/Linux, don't 5634 ;; implementations, like busybox of embedded GNU/Linux, don't
5619 ;; support disabling. 5635 ;; support disabling.
5620 (tramp-send-command-internal vec "echo foo") 5636 (tramp-send-command vec "echo foo" t)
5621 (with-current-buffer (process-buffer proc) 5637 (with-current-buffer (process-buffer proc)
5622 (goto-char (point-min)) 5638 (goto-char (point-min))
5623 (when (looking-at "echo foo") 5639 (when (looking-at "echo foo")
@@ -5625,11 +5641,11 @@ process to set up. VEC specifies the connection."
5625 (tramp-message vec 5 "Remote echo still on. Ok.") 5641 (tramp-message vec 5 "Remote echo still on. Ok.")
5626 ;; Make sure backspaces and their echo are enabled and no line 5642 ;; Make sure backspaces and their echo are enabled and no line
5627 ;; width magic interferes with them. 5643 ;; width magic interferes with them.
5628 (tramp-send-command-internal vec "stty icanon erase ^H cols 32767"))) 5644 (tramp-send-command vec "stty icanon erase ^H cols 32767" t)))
5629 ;; Try to set up the coding system correctly. 5645 ;; Try to set up the coding system correctly.
5630 ;; CCC this can't be the right way to do it. Hm. 5646 ;; CCC this can't be the right way to do it. Hm.
5631 (tramp-message vec 5 "Determining coding system") 5647 (tramp-message vec 5 "Determining coding system")
5632 (tramp-send-command-internal vec "echo foo ; echo bar") 5648 (tramp-send-command vec "echo foo ; echo bar" t)
5633 (with-current-buffer (process-buffer proc) 5649 (with-current-buffer (process-buffer proc)
5634 (goto-char (point-min)) 5650 (goto-char (point-min))
5635 (if (featurep 'mule) 5651 (if (featurep 'mule)
@@ -5655,17 +5671,8 @@ process to set up. VEC specifies the connection."
5655 ;; We have found a ^M but cannot frob the process coding system 5671 ;; We have found a ^M but cannot frob the process coding system
5656 ;; because we're running on a non-MULE Emacs. Let's try 5672 ;; because we're running on a non-MULE Emacs. Let's try
5657 ;; stty, instead. 5673 ;; stty, instead.
5658 (tramp-send-command-internal vec "stty -onlcr")))) 5674 (tramp-send-command vec "stty -onlcr" t))))
5659 (tramp-send-command-internal vec "set +o vi +o emacs") 5675 (tramp-send-command vec "set +o vi +o emacs" t)
5660 (tramp-message vec 5 "Setting shell prompt")
5661 ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we must
5662 ;; use "\n" here, not tramp-rsh-end-of-line.
5663 (tramp-send-command
5664 vec
5665 (format "PROMPT_COMMAND=''; PS1='%s%s%s'; PS2=''; PS3=''"
5666 tramp-rsh-end-of-line
5667 tramp-end-of-output
5668 tramp-rsh-end-of-line))
5669 ;; Check whether the remote host suffers from buggy `send-process-string'. 5676 ;; Check whether the remote host suffers from buggy `send-process-string'.
5670 ;; This is known for FreeBSD (see comment in `send_process', file process.c). 5677 ;; This is known for FreeBSD (see comment in `send_process', file process.c).
5671 ;; I've tested sending 624 bytes successfully, sending 625 bytes failed. 5678 ;; I've tested sending 624 bytes successfully, sending 625 bytes failed.
@@ -5695,7 +5702,7 @@ process to set up. VEC specifies the connection."
5695 ;; ksh. Whee... 5702 ;; ksh. Whee...
5696 (tramp-find-shell vec) 5703 (tramp-find-shell vec)
5697 ;; Disable unexpected output. 5704 ;; Disable unexpected output.
5698 (tramp-send-command vec "mesg n; biff n") 5705 (tramp-send-command vec "mesg n; biff n" t)
5699 ;; Set the environment. 5706 ;; Set the environment.
5700 (tramp-message vec 5 "Setting default environment") 5707 (tramp-message vec 5 "Setting default environment")
5701 (let ((env (copy-sequence tramp-remote-process-environment)) 5708 (let ((env (copy-sequence tramp-remote-process-environment))
@@ -5704,12 +5711,12 @@ process to set up. VEC specifies the connection."
5704 (setq item (split-string (car env) "=")) 5711 (setq item (split-string (car env) "="))
5705 (if (and (stringp (cadr item)) (not (string-equal (cadr item) ""))) 5712 (if (and (stringp (cadr item)) (not (string-equal (cadr item) "")))
5706 (tramp-send-command 5713 (tramp-send-command
5707 vec (format "%s=%s; export %s" (car item) (cadr item) (car item))) 5714 vec (format "%s=%s; export %s" (car item) (cadr item) (car item)) t)
5708 (push (car item) unset)) 5715 (push (car item) unset))
5709 (setq env (cdr env))) 5716 (setq env (cdr env)))
5710 (when unset 5717 (when unset
5711 (tramp-send-command 5718 (tramp-send-command
5712 vec (format "unset %s" (mapconcat 'identity unset " ")))))) 5719 vec (format "unset %s" (mapconcat 'identity unset " "))))) t)
5713 5720
5714;; CCC: We should either implement a Perl version of base64 encoding 5721;; CCC: We should either implement a Perl version of base64 encoding
5715;; and decoding. Then we just use that in the last item. The other 5722;; and decoding. Then we just use that in the last item. The other
@@ -6181,19 +6188,6 @@ function waits for output unless NOOUTPUT is set."
6181 (tramp-send-string vec command) 6188 (tramp-send-string vec command)
6182 (unless nooutput (tramp-wait-for-output p)))) 6189 (unless nooutput (tramp-wait-for-output p))))
6183 6190
6184(defun tramp-send-command-internal (vec command)
6185 "Send command to remote host and wait for success.
6186Sends COMMAND, then waits 30 seconds for shell prompt."
6187 (let ((p (tramp-get-connection-process vec)))
6188 (when (tramp-get-connection-property vec "remote-echo" nil)
6189 ;; We mark the command string that it can be erased in the output buffer.
6190 (tramp-set-connection-property p "check-remote-echo" t)
6191 (setq command (format "%s%s%s" tramp-echo-mark command tramp-echo-mark)))
6192 (tramp-message vec 6 "%s" command)
6193 (tramp-send-string vec command)
6194 (tramp-barf-if-no-shell-prompt
6195 p 30 "Couldn't `%s', see buffer `%s'" command (buffer-name))))
6196
6197(defun tramp-wait-for-output (proc &optional timeout) 6191(defun tramp-wait-for-output (proc &optional timeout)
6198 "Wait for output from remote rsh command." 6192 "Wait for output from remote rsh command."
6199 (with-current-buffer (process-buffer proc) 6193 (with-current-buffer (process-buffer proc)