comparison lisp/net/tramp.el @ 106470:9e96dbbd314e

Handle prompt rules of ksh in OpenBSD 4.5. Reported by Rapha¸«³l Berbain <raphael.berbain@gmail.com>. * net/tramp.el (tramp-end-of-output): Move up. Use `#' and `$' characters. (tramp-initial-end-of-output): New defconst. (tramp-methods, tramp-find-shell) (tramp-open-connection-setup-interactive-shell) (tramp-maybe-open-connection): Use it. (tramp-shell-prompt-pattern, tramp-wait-for-output): Handle existence of `#' and `$'. * net/tramp-fish.el (tramp-fish-maybe-open-connection): Use `tramp-initial-end-of-output'.
author Michael Albinus <michael.albinus@gmx.de>
date Mon, 07 Dec 2009 06:38:06 +0000
parents 4eee659fa954
children 8c836ea59444
comparison
equal deleted inserted replaced
106469:ad4147368f52 106470:9e96dbbd314e
294 Because Tramp wants to parse the output of the remote shell, it is easily 294 Because Tramp wants to parse the output of the remote shell, it is easily
295 confused by ANSI color escape sequences and suchlike. Often, shell init 295 confused by ANSI color escape sequences and suchlike. Often, shell init
296 files conditionalize this setup based on the TERM environment variable." 296 files conditionalize this setup based on the TERM environment variable."
297 :group 'tramp 297 :group 'tramp
298 :type 'string) 298 :type 'string)
299
300 ;; ksh on OpenBSD 4.5 requires, that PS1 contains a `#' character for
301 ;; root users. It uses the `$' character for other users. In order
302 ;; to guarantee a proper prompt, we use "#$" for the prompt.
303
304 (defvar tramp-end-of-output
305 (format
306 "///%s#$"
307 (md5 (concat (prin1-to-string process-environment) (current-time-string))))
308 "String used to recognize end of output.
309 The '$' character at the end is quoted; the string cannot be
310 detected as prompt when being sent on echoing hosts, therefore.")
311
312 (defconst tramp-initial-end-of-output "#$ "
313 "Prompt when establishing a connection.")
299 314
300 (defvar tramp-methods 315 (defvar tramp-methods
301 `(("rcp" (tramp-login-program "rsh") 316 `(("rcp" (tramp-login-program "rsh")
302 (tramp-login-args (("%h") ("-l" "%u"))) 317 (tramp-login-args (("%h") ("-l" "%u")))
303 (tramp-remote-sh "/bin/sh") 318 (tramp-remote-sh "/bin/sh")
583 (tramp-login-program "plink") 598 (tramp-login-program "plink")
584 ;; ("%h") must be a single element, see 599 ;; ("%h") must be a single element, see
585 ;; `tramp-compute-multi-hops'. 600 ;; `tramp-compute-multi-hops'.
586 (tramp-login-args (("-load") ("%h") ("-t") 601 (tramp-login-args (("-load") ("%h") ("-t")
587 (,(format 602 (,(format
588 "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=$ '" 603 "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=%s'"
589 tramp-terminal-type)) 604 tramp-terminal-type
605 tramp-initial-end-of-output))
590 ("/bin/sh"))) 606 ("/bin/sh")))
591 (tramp-remote-sh "/bin/sh") 607 (tramp-remote-sh "/bin/sh")
592 (tramp-copy-program nil) 608 (tramp-copy-program nil)
593 (tramp-copy-args nil) 609 (tramp-copy-args nil)
594 (tramp-copy-keep-date nil) 610 (tramp-copy-keep-date nil)
1028 :type 'regexp) 1044 :type 'regexp)
1029 1045
1030 (defcustom tramp-shell-prompt-pattern 1046 (defcustom tramp-shell-prompt-pattern
1031 ;; Allow a prompt to start right after a ^M since it indeed would be 1047 ;; Allow a prompt to start right after a ^M since it indeed would be
1032 ;; displayed at the beginning of the line (and Zsh uses it). 1048 ;; displayed at the beginning of the line (and Zsh uses it).
1033 "\\(?:^\\|\r\\)[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*" 1049 "\\(?:^\\|\r\\)[^#$%>\n]*#?[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
1034 "Regexp to match prompts from remote shell. 1050 "Regexp to match prompts from remote shell.
1035 Normally, Tramp expects you to configure `shell-prompt-pattern' 1051 Normally, Tramp expects you to configure `shell-prompt-pattern'
1036 correctly, but sometimes it happens that you are connecting to a 1052 correctly, but sometimes it happens that you are connecting to a
1037 remote host which sends a different kind of shell prompt. Therefore, 1053 remote host which sends a different kind of shell prompt. Therefore,
1038 Tramp recognizes things matched by `shell-prompt-pattern' as prompt, 1054 Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
1039 and also things matched by this variable. The default value of this 1055 and also things matched by this variable. The default value of this
1040 variable is similar to the default value of `shell-prompt-pattern', 1056 variable is similar to the default value of `shell-prompt-pattern',
1041 which should work well in many cases." 1057 which should work well in many cases.
1058
1059 This regexp must match both `tramp-initial-end-of-output' and
1060 `tramp-end-of-output'."
1042 :group 'tramp 1061 :group 'tramp
1043 :type 'regexp) 1062 :type 'regexp)
1044 1063
1045 (defcustom tramp-password-prompt-regexp 1064 (defcustom tramp-password-prompt-regexp
1046 "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *" 1065 "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *"
1584 means to use always cached values for the directory contents." 1603 means to use always cached values for the directory contents."
1585 :group 'tramp 1604 :group 'tramp
1586 :type '(choice (const nil) integer)) 1605 :type '(choice (const nil) integer))
1587 1606
1588 ;;; Internal Variables: 1607 ;;; Internal Variables:
1589
1590 (defvar tramp-end-of-output
1591 (format
1592 "///%s$"
1593 (md5 (concat (prin1-to-string process-environment) (current-time-string))))
1594 "String used to recognize end of output.
1595 The '$' character at the end is quoted; the string cannot be
1596 detected as prompt when being sent on echoing hosts, therefore.")
1597 1608
1598 (defvar tramp-current-method nil 1609 (defvar tramp-current-method nil
1599 "Connection method for this *tramp* buffer.") 1610 "Connection method for this *tramp* buffer.")
1600 1611
1601 (defvar tramp-current-user nil 1612 (defvar tramp-current-user nil
6348 (when (string-match (car item) shell) 6359 (when (string-match (car item) shell)
6349 (setq extra-args (cdr item)))) 6360 (setq extra-args (cdr item))))
6350 (when extra-args (setq shell (concat shell " " extra-args)))) 6361 (when extra-args (setq shell (concat shell " " extra-args))))
6351 (tramp-message 6362 (tramp-message
6352 vec 5 "Starting remote shell `%s' for tilde expansion..." shell) 6363 vec 5 "Starting remote shell `%s' for tilde expansion..." shell)
6353 (let ((tramp-end-of-output "$ ")) 6364 (let ((tramp-end-of-output tramp-initial-end-of-output))
6354 (tramp-send-command 6365 (tramp-send-command
6355 vec 6366 vec
6356 (format "PROMPT_COMMAND='' PS1=%s PS2='' PS3='' exec %s" 6367 (format "PROMPT_COMMAND='' PS1=%s PS2='' PS3='' exec %s"
6357 (shell-quote-argument tramp-end-of-output) shell) 6368 (shell-quote-argument tramp-end-of-output) shell)
6358 t)) 6369 t))
6619 6630
6620 (defun tramp-open-connection-setup-interactive-shell (proc vec) 6631 (defun tramp-open-connection-setup-interactive-shell (proc vec)
6621 "Set up an interactive shell. 6632 "Set up an interactive shell.
6622 Mainly sets the prompt and the echo correctly. PROC is the shell 6633 Mainly sets the prompt and the echo correctly. PROC is the shell
6623 process to set up. VEC specifies the connection." 6634 process to set up. VEC specifies the connection."
6624 (let ((tramp-end-of-output "$ ")) 6635 (let ((tramp-end-of-output tramp-initial-end-of-output))
6625 ;; It is useful to set the prompt in the following command because 6636 ;; It is useful to set the prompt in the following command because
6626 ;; some people have a setting for $PS1 which /bin/sh doesn't know 6637 ;; some people have a setting for $PS1 which /bin/sh doesn't know
6627 ;; about and thus /bin/sh will display a strange prompt. For 6638 ;; about and thus /bin/sh will display a strange prompt. For
6628 ;; example, if $PS1 has "${CWD}" in the value, then ksh will 6639 ;; example, if $PS1 has "${CWD}" in the value, then ksh will
6629 ;; display the current working directory but /bin/sh will display 6640 ;; display the current working directory but /bin/sh will display
7145 (when (and p (processp p)) 7156 (when (and p (processp p))
7146 (delete-process p)) 7157 (delete-process p))
7147 (setenv "TERM" tramp-terminal-type) 7158 (setenv "TERM" tramp-terminal-type)
7148 (setenv "LC_ALL" "C") 7159 (setenv "LC_ALL" "C")
7149 (setenv "PROMPT_COMMAND") 7160 (setenv "PROMPT_COMMAND")
7150 (setenv "PS1" "$ ") 7161 (setenv "PS1" tramp-initial-end-of-output)
7151 (let* ((target-alist (tramp-compute-multi-hops vec)) 7162 (let* ((target-alist (tramp-compute-multi-hops vec))
7152 (process-connection-type tramp-process-connection-type) 7163 (process-connection-type tramp-process-connection-type)
7153 (process-adaptive-read-buffering nil) 7164 (process-adaptive-read-buffering nil)
7154 (coding-system-for-read nil) 7165 (coding-system-for-read nil)
7155 ;; This must be done in order to avoid our file name handler. 7166 ;; This must be done in order to avoid our file name handler.
7269 (unless nooutput (tramp-wait-for-output p)))) 7280 (unless nooutput (tramp-wait-for-output p))))
7270 7281
7271 (defun tramp-wait-for-output (proc &optional timeout) 7282 (defun tramp-wait-for-output (proc &optional timeout)
7272 "Wait for output from remote rsh command." 7283 "Wait for output from remote rsh command."
7273 (with-current-buffer (process-buffer proc) 7284 (with-current-buffer (process-buffer proc)
7274 (let* (;; Initially, `tramp-end-of-output' is "$ ". There might 7285 (let* (;; Initially, `tramp-end-of-output' is "#$ ". There might
7275 ;; be leading escape sequences, which must be ignored. 7286 ;; be leading escape sequences, which must be ignored.
7276 (regexp (format "[^$\n]*%s\r?$" (regexp-quote tramp-end-of-output))) 7287 (regexp (format "[^#$\n]*%s\r?$" (regexp-quote tramp-end-of-output)))
7277 ;; Sometimes, the commands do not return a newline but a 7288 ;; Sometimes, the commands do not return a newline but a
7278 ;; null byte before the shell prompt, for example "git 7289 ;; null byte before the shell prompt, for example "git
7279 ;; ls-files -c -z ...". 7290 ;; ls-files -c -z ...".
7280 (regexp1 (format "\\(^\\|\000\\)%s" regexp)) 7291 (regexp1 (format "\\(^\\|\000\\)%s" regexp))
7281 (found (tramp-wait-for-regexp proc timeout regexp1))) 7292 (found (tramp-wait-for-regexp proc timeout regexp1)))