Fix Bug#24698

* lisp/net/tramp-sh.el (tramp-open-connection-setup-interactive-shell):
Don't send "stty tab0" to *BSD and Darwin machines.  (Bug#24698)
This commit is contained in:
Michael Albinus 2016-10-18 20:41:19 +02:00
parent baa8ba4ed4
commit 9a758b4ccc

View file

@ -4186,10 +4186,10 @@ process to set up. VEC specifies the connection."
(case-fold-search t)) (case-fold-search t))
(tramp-open-shell vec (tramp-get-method-parameter vec 'tramp-remote-shell)) (tramp-open-shell vec (tramp-get-method-parameter vec 'tramp-remote-shell))
;; Disable tab and echo expansion. ;; Disable echo expansion.
(tramp-message vec 5 "Setting up remote shell environment") (tramp-message vec 5 "Setting up remote shell environment")
(tramp-send-command (tramp-send-command
vec "stty tab0 -inlcr -onlcr -echo kill '^U' erase '^H'" t) vec "stty -inlcr -onlcr -echo kill '^U' erase '^H'" t)
;; Check whether the echo has really been disabled. Some ;; Check whether the echo has really been disabled. Some
;; implementations, like busybox of embedded GNU/Linux, don't ;; implementations, like busybox of embedded GNU/Linux, don't
;; support disabling. ;; support disabling.
@ -4206,7 +4206,8 @@ process to set up. VEC specifies the connection."
(tramp-message vec 5 "Setting shell prompt") (tramp-message vec 5 "Setting shell prompt")
(tramp-send-command (tramp-send-command
vec (format "PS1=%s PS2='' PS3='' PROMPT_COMMAND=''" vec (format "PS1=%s PS2='' PS3='' PROMPT_COMMAND=''"
(tramp-shell-quote-argument tramp-end-of-output)) t) (tramp-shell-quote-argument tramp-end-of-output))
t)
;; Check whether the output of "uname -sr" has been changed. If ;; Check whether the output of "uname -sr" has been changed. If
;; yes, this is a strong indication that we must expire all ;; yes, this is a strong indication that we must expire all
@ -4214,26 +4215,26 @@ process to set up. VEC specifies the connection."
;; `tramp-maybe-open-connection', it will be caught there. ;; `tramp-maybe-open-connection', it will be caught there.
(tramp-message vec 5 "Checking system information") (tramp-message vec 5 "Checking system information")
(let ((old-uname (tramp-get-connection-property vec "uname" nil)) (let ((old-uname (tramp-get-connection-property vec "uname" nil))
(new-uname (uname
(tramp-set-connection-property (tramp-set-connection-property
vec "uname" vec "uname"
(tramp-send-command-and-read vec "echo \\\"`uname -sr`\\\"")))) (tramp-send-command-and-read vec "echo \\\"`uname -sr`\\\""))))
(when (and (stringp old-uname) (not (string-equal old-uname new-uname))) (when (and (stringp old-uname) (not (string-equal old-uname uname)))
(tramp-message (tramp-message
vec 3 vec 3
"Connection reset, because remote host changed from `%s' to `%s'" "Connection reset, because remote host changed from `%s' to `%s'"
old-uname new-uname) old-uname uname)
;; We want to keep the password. ;; We want to keep the password.
(tramp-cleanup-connection vec t t) (tramp-cleanup-connection vec t t)
(throw 'uname-changed (tramp-maybe-open-connection vec)))) (throw 'uname-changed (tramp-maybe-open-connection vec)))
;; Try to set up the coding system correctly. ;; Try to set up the coding system correctly.
;; CCC this can't be the right way to do it. Hm. ;; CCC this can't be the right way to do it. Hm.
(tramp-message vec 5 "Determining coding system") (tramp-message vec 5 "Determining coding system")
(with-current-buffer (process-buffer proc) (with-current-buffer (process-buffer proc)
(if (featurep 'mule) (if (featurep 'mule)
;; Use MULE to select the right EOL convention for communicating ;; Use MULE to select the right EOL convention for
;; with the process. ;; communicating with the process.
(let ((cs (or (and (memq 'utf-8 (coding-system-list)) (let ((cs (or (and (memq 'utf-8 (coding-system-list))
(string-match "utf-?8" (tramp-get-remote-locale vec)) (string-match "utf-?8" (tramp-get-remote-locale vec))
(cons 'utf-8 'utf-8)) (cons 'utf-8 'utf-8))
@ -4245,18 +4246,14 @@ process to set up. VEC specifies the connection."
cs-encode (or (cdr cs) 'undecided)) cs-encode (or (cdr cs) 'undecided))
(setq cs-encode (setq cs-encode
(tramp-compat-coding-system-change-eol-conversion (tramp-compat-coding-system-change-eol-conversion
cs-encode cs-encode (if (string-match "^Darwin" uname) 'mac 'unix)))
(if (string-match
"^Darwin" (tramp-get-connection-property vec "uname" ""))
'mac 'unix)))
(tramp-send-command vec "echo foo ; echo bar" t) (tramp-send-command vec "echo foo ; echo bar" t)
(goto-char (point-min)) (goto-char (point-min))
(when (search-forward "\r" nil t) (when (search-forward "\r" nil t)
(setq cs-decode (tramp-compat-coding-system-change-eol-conversion (setq cs-decode (tramp-compat-coding-system-change-eol-conversion
cs-decode 'dos))) cs-decode 'dos)))
;; Special setting for Mac OS X. ;; Special setting for Mac OS X.
(when (and (string-match (when (and (string-match "^Darwin" uname)
"^Darwin" (tramp-get-connection-property vec "uname" ""))
(memq 'utf-8-hfs (coding-system-list))) (memq 'utf-8-hfs (coding-system-list)))
(setq cs-decode 'utf-8-hfs (setq cs-decode 'utf-8-hfs
cs-encode 'utf-8-hfs)) cs-encode 'utf-8-hfs))
@ -4266,19 +4263,19 @@ process to set up. VEC specifies the connection."
vec 5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode)) vec 5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode))
;; Look for ^M and do something useful if found. ;; Look for ^M and do something useful if found.
(when (search-forward "\r" nil t) (when (search-forward "\r" nil t)
;; We have found a ^M but cannot frob the process coding system ;; We have found a ^M but cannot frob the process coding
;; because we're running on a non-MULE Emacs. Let's try ;; system because we're running on a non-MULE Emacs. Let's
;; stty, instead. ;; try stty, instead.
(tramp-send-command vec "stty -onlcr" t)))) (tramp-send-command vec "stty -onlcr" t))))
(tramp-send-command vec "set +o vi +o emacs" t) (tramp-send-command vec "set +o vi +o emacs" t)
;; Check whether the remote host suffers from buggy ;; Check whether the remote host suffers from buggy
;; `send-process-string'. This is known for FreeBSD (see comment in ;; `send-process-string'. This is known for FreeBSD (see comment
;; `send_process', file process.c). I've tested sending 624 bytes ;; in `send_process', file process.c). I've tested sending 624
;; successfully, sending 625 bytes failed. Emacs makes a hack when ;; bytes successfully, sending 625 bytes failed. Emacs makes a
;; this host type is detected locally. It cannot handle remote ;; hack when this host type is detected locally. It cannot handle
;; hosts, though. ;; remote hosts, though.
(with-tramp-connection-property proc "chunksize" (with-tramp-connection-property proc "chunksize"
(cond (cond
((and (integerp tramp-chunksize) (> tramp-chunksize 0)) ((and (integerp tramp-chunksize) (> tramp-chunksize 0))
@ -4286,23 +4283,21 @@ process to set up. VEC specifies the connection."
(t (t
(tramp-message (tramp-message
vec 5 "Checking remote host type for `send-process-string' bug") vec 5 "Checking remote host type for `send-process-string' bug")
(if (string-match (if (string-match "^FreeBSD" uname) 500 0))))
"^FreeBSD" (tramp-get-connection-property vec "uname" ""))
500 0))))
;; Set remote PATH variable. ;; Set remote PATH variable.
(tramp-set-remote-path vec) (tramp-set-remote-path vec)
;; Search for a good shell before searching for a command which ;; Search for a good shell before searching for a command which
;; checks if a file exists. This is done because Tramp wants to use ;; checks if a file exists. This is done because Tramp wants to
;; "test foo; echo $?" to check if various conditions hold, and ;; use "test foo; echo $?" to check if various conditions hold,
;; there are buggy /bin/sh implementations which don't execute the ;; and there are buggy /bin/sh implementations which don't execute
;; "echo $?" part if the "test" part has an error. In particular, ;; the "echo $?" part if the "test" part has an error. In
;; the OpenSolaris /bin/sh is a problem. There are also other ;; particular, the OpenSolaris /bin/sh is a problem. There are
;; problems with /bin/sh of OpenSolaris, like redirection of stderr ;; also other problems with /bin/sh of OpenSolaris, like
;; in function declarations, or changing HISTFILE in place. ;; redirection of stderr in function declarations, or changing
;; Therefore, OpenSolaris' /bin/sh is replaced by bash, when ;; HISTFILE in place. Therefore, OpenSolaris' /bin/sh is replaced
;; detected. ;; by bash, when detected.
(tramp-find-shell vec) (tramp-find-shell vec)
;; Disable unexpected output. ;; Disable unexpected output.
@ -4311,13 +4306,13 @@ process to set up. VEC specifies the connection."
;; IRIX64 bash expands "!" even when in single quotes. This ;; IRIX64 bash expands "!" even when in single quotes. This
;; destroys our shell functions, we must disable it. See ;; destroys our shell functions, we must disable it. See
;; <http://stackoverflow.com/questions/3291692/irix-bash-shell-expands-expression-in-single-quotes-yet-shouldnt>. ;; <http://stackoverflow.com/questions/3291692/irix-bash-shell-expands-expression-in-single-quotes-yet-shouldnt>.
(when (string-match "^IRIX64" (tramp-get-connection-property vec "uname" "")) (when (string-match "^IRIX64" uname)
(tramp-send-command vec "set +H" t)) (tramp-send-command vec "set +H" t))
;; On BSD-like systems, ?\t is expanded to spaces. Suppress this. ;; Disable tab expansion.
(when (string-match "BSD\\|Darwin" (if (string-match "BSD\\|Darwin" uname)
(tramp-get-connection-property vec "uname" "")) (tramp-send-command vec "stty tabs" t)
(tramp-send-command vec "stty -oxtabs" t)) (tramp-send-command vec "stty tab0" t))
;; Set utf8 encoding. Needed for Mac OS X, for example. This is ;; Set utf8 encoding. Needed for Mac OS X, for example. This is
;; non-POSIX, so we must expect errors on some systems. ;; non-POSIX, so we must expect errors on some systems.
@ -4355,7 +4350,7 @@ process to set up. VEC specifies the connection."
t)) t))
(when unset (when unset
(tramp-send-command (tramp-send-command
vec (format "unset %s" (mapconcat 'identity unset " ")) t)))) vec (format "unset %s" (mapconcat 'identity unset " ")) t)))))
;; Old text from documentation of tramp-methods: ;; Old text from documentation of tramp-methods:
;; Using a uuencode/uudecode inline method is discouraged, please use one ;; Using a uuencode/uudecode inline method is discouraged, please use one