aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-10-18 20:41:19 +0200
committerMichael Albinus2016-10-18 20:41:19 +0200
commit9a758b4ccc9543ce0e74b4d71e5cd3a1443583e1 (patch)
tree3d522f04af76dac79e9b91408aad90b24ecf9cf9
parentbaa8ba4ed471d7fe4bb07c80a9dd16c4712525b4 (diff)
downloademacs-9a758b4ccc9543ce0e74b4d71e5cd3a1443583e1.tar.gz
emacs-9a758b4ccc9543ce0e74b4d71e5cd3a1443583e1.zip
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)
-rw-r--r--lisp/net/tramp-sh.el267
1 files changed, 131 insertions, 136 deletions
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 85712cc9d8a..166bc881676 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -4186,10 +4186,10 @@ process to set up. VEC specifies the connection."
4186 (case-fold-search t)) 4186 (case-fold-search t))
4187 (tramp-open-shell vec (tramp-get-method-parameter vec 'tramp-remote-shell)) 4187 (tramp-open-shell vec (tramp-get-method-parameter vec 'tramp-remote-shell))
4188 4188
4189 ;; Disable tab and echo expansion. 4189 ;; Disable echo expansion.
4190 (tramp-message vec 5 "Setting up remote shell environment") 4190 (tramp-message vec 5 "Setting up remote shell environment")
4191 (tramp-send-command 4191 (tramp-send-command
4192 vec "stty tab0 -inlcr -onlcr -echo kill '^U' erase '^H'" t) 4192 vec "stty -inlcr -onlcr -echo kill '^U' erase '^H'" t)
4193 ;; Check whether the echo has really been disabled. Some 4193 ;; Check whether the echo has really been disabled. Some
4194 ;; implementations, like busybox of embedded GNU/Linux, don't 4194 ;; implementations, like busybox of embedded GNU/Linux, don't
4195 ;; support disabling. 4195 ;; support disabling.
@@ -4206,7 +4206,8 @@ process to set up. VEC specifies the connection."
4206 (tramp-message vec 5 "Setting shell prompt") 4206 (tramp-message vec 5 "Setting shell prompt")
4207 (tramp-send-command 4207 (tramp-send-command
4208 vec (format "PS1=%s PS2='' PS3='' PROMPT_COMMAND=''" 4208 vec (format "PS1=%s PS2='' PS3='' PROMPT_COMMAND=''"
4209 (tramp-shell-quote-argument tramp-end-of-output)) t) 4209 (tramp-shell-quote-argument tramp-end-of-output))
4210 t)
4210 4211
4211 ;; Check whether the output of "uname -sr" has been changed. If 4212 ;; Check whether the output of "uname -sr" has been changed. If
4212 ;; yes, this is a strong indication that we must expire all 4213 ;; yes, this is a strong indication that we must expire all
@@ -4214,148 +4215,142 @@ process to set up. VEC specifies the connection."
4214 ;; `tramp-maybe-open-connection', it will be caught there. 4215 ;; `tramp-maybe-open-connection', it will be caught there.
4215 (tramp-message vec 5 "Checking system information") 4216 (tramp-message vec 5 "Checking system information")
4216 (let ((old-uname (tramp-get-connection-property vec "uname" nil)) 4217 (let ((old-uname (tramp-get-connection-property vec "uname" nil))
4217 (new-uname 4218 (uname
4218 (tramp-set-connection-property 4219 (tramp-set-connection-property
4219 vec "uname" 4220 vec "uname"
4220 (tramp-send-command-and-read vec "echo \\\"`uname -sr`\\\"")))) 4221 (tramp-send-command-and-read vec "echo \\\"`uname -sr`\\\""))))
4221 (when (and (stringp old-uname) (not (string-equal old-uname new-uname))) 4222 (when (and (stringp old-uname) (not (string-equal old-uname uname)))
4222 (tramp-message 4223 (tramp-message
4223 vec 3 4224 vec 3
4224 "Connection reset, because remote host changed from `%s' to `%s'" 4225 "Connection reset, because remote host changed from `%s' to `%s'"
4225 old-uname new-uname) 4226 old-uname uname)
4226 ;; We want to keep the password. 4227 ;; We want to keep the password.
4227 (tramp-cleanup-connection vec t t) 4228 (tramp-cleanup-connection vec t t)
4228 (throw 'uname-changed (tramp-maybe-open-connection vec)))) 4229 (throw 'uname-changed (tramp-maybe-open-connection vec)))
4229 4230
4230 ;; Try to set up the coding system correctly. 4231 ;; Try to set up the coding system correctly.
4231 ;; CCC this can't be the right way to do it. Hm. 4232 ;; CCC this can't be the right way to do it. Hm.
4232 (tramp-message vec 5 "Determining coding system") 4233 (tramp-message vec 5 "Determining coding system")
4233 (with-current-buffer (process-buffer proc) 4234 (with-current-buffer (process-buffer proc)
4234 (if (featurep 'mule) 4235 (if (featurep 'mule)
4235 ;; Use MULE to select the right EOL convention for communicating 4236 ;; Use MULE to select the right EOL convention for
4236 ;; with the process. 4237 ;; communicating with the process.
4237 (let ((cs (or (and (memq 'utf-8 (coding-system-list)) 4238 (let ((cs (or (and (memq 'utf-8 (coding-system-list))
4238 (string-match "utf-?8" (tramp-get-remote-locale vec)) 4239 (string-match "utf-?8" (tramp-get-remote-locale vec))
4239 (cons 'utf-8 'utf-8)) 4240 (cons 'utf-8 'utf-8))
4240 (tramp-compat-funcall 'process-coding-system proc) 4241 (tramp-compat-funcall 'process-coding-system proc)
4241 (cons 'undecided 'undecided))) 4242 (cons 'undecided 'undecided)))
4242 cs-decode cs-encode) 4243 cs-decode cs-encode)
4243 (when (symbolp cs) (setq cs (cons cs cs))) 4244 (when (symbolp cs) (setq cs (cons cs cs)))
4244 (setq cs-decode (or (car cs) 'undecided) 4245 (setq cs-decode (or (car cs) 'undecided)
4245 cs-encode (or (cdr cs) 'undecided)) 4246 cs-encode (or (cdr cs) 'undecided))
4246 (setq cs-encode 4247 (setq cs-encode
4247 (tramp-compat-coding-system-change-eol-conversion 4248 (tramp-compat-coding-system-change-eol-conversion
4248 cs-encode 4249 cs-encode (if (string-match "^Darwin" uname) 'mac 'unix)))
4249 (if (string-match 4250 (tramp-send-command vec "echo foo ; echo bar" t)
4250 "^Darwin" (tramp-get-connection-property vec "uname" "")) 4251 (goto-char (point-min))
4251 'mac 'unix))) 4252 (when (search-forward "\r" nil t)
4252 (tramp-send-command vec "echo foo ; echo bar" t) 4253 (setq cs-decode (tramp-compat-coding-system-change-eol-conversion
4253 (goto-char (point-min)) 4254 cs-decode 'dos)))
4254 (when (search-forward "\r" nil t) 4255 ;; Special setting for Mac OS X.
4255 (setq cs-decode (tramp-compat-coding-system-change-eol-conversion 4256 (when (and (string-match "^Darwin" uname)
4256 cs-decode 'dos))) 4257 (memq 'utf-8-hfs (coding-system-list)))
4257 ;; Special setting for Mac OS X. 4258 (setq cs-decode 'utf-8-hfs
4258 (when (and (string-match 4259 cs-encode 'utf-8-hfs))
4259 "^Darwin" (tramp-get-connection-property vec "uname" "")) 4260 (tramp-compat-funcall
4260 (memq 'utf-8-hfs (coding-system-list))) 4261 'set-buffer-process-coding-system cs-decode cs-encode)
4261 (setq cs-decode 'utf-8-hfs 4262 (tramp-message
4262 cs-encode 'utf-8-hfs)) 4263 vec 5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode))
4263 (tramp-compat-funcall 4264 ;; Look for ^M and do something useful if found.
4264 'set-buffer-process-coding-system cs-decode cs-encode) 4265 (when (search-forward "\r" nil t)
4265 (tramp-message 4266 ;; We have found a ^M but cannot frob the process coding
4266 vec 5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode)) 4267 ;; system because we're running on a non-MULE Emacs. Let's
4267 ;; Look for ^M and do something useful if found. 4268 ;; try stty, instead.
4268 (when (search-forward "\r" nil t) 4269 (tramp-send-command vec "stty -onlcr" t))))
4269 ;; We have found a ^M but cannot frob the process coding system 4270
4270 ;; because we're running on a non-MULE Emacs. Let's try 4271 (tramp-send-command vec "set +o vi +o emacs" t)
4271 ;; stty, instead. 4272
4272 (tramp-send-command vec "stty -onlcr" t)))) 4273 ;; Check whether the remote host suffers from buggy
4273 4274 ;; `send-process-string'. This is known for FreeBSD (see comment
4274 (tramp-send-command vec "set +o vi +o emacs" t) 4275 ;; in `send_process', file process.c). I've tested sending 624
4275 4276 ;; bytes successfully, sending 625 bytes failed. Emacs makes a
4276 ;; Check whether the remote host suffers from buggy 4277 ;; hack when this host type is detected locally. It cannot handle
4277 ;; `send-process-string'. This is known for FreeBSD (see comment in 4278 ;; remote hosts, though.
4278 ;; `send_process', file process.c). I've tested sending 624 bytes 4279 (with-tramp-connection-property proc "chunksize"
4279 ;; successfully, sending 625 bytes failed. Emacs makes a hack when 4280 (cond
4280 ;; this host type is detected locally. It cannot handle remote 4281 ((and (integerp tramp-chunksize) (> tramp-chunksize 0))
4281 ;; hosts, though. 4282 tramp-chunksize)
4282 (with-tramp-connection-property proc "chunksize" 4283 (t
4283 (cond 4284 (tramp-message
4284 ((and (integerp tramp-chunksize) (> tramp-chunksize 0)) 4285 vec 5 "Checking remote host type for `send-process-string' bug")
4285 tramp-chunksize) 4286 (if (string-match "^FreeBSD" uname) 500 0))))
4286 (t 4287
4287 (tramp-message 4288 ;; Set remote PATH variable.
4288 vec 5 "Checking remote host type for `send-process-string' bug") 4289 (tramp-set-remote-path vec)
4289 (if (string-match 4290
4290 "^FreeBSD" (tramp-get-connection-property vec "uname" "")) 4291 ;; Search for a good shell before searching for a command which
4291 500 0)))) 4292 ;; checks if a file exists. This is done because Tramp wants to
4292 4293 ;; use "test foo; echo $?" to check if various conditions hold,
4293 ;; Set remote PATH variable. 4294 ;; and there are buggy /bin/sh implementations which don't execute
4294 (tramp-set-remote-path vec) 4295 ;; the "echo $?" part if the "test" part has an error. In
4295 4296 ;; particular, the OpenSolaris /bin/sh is a problem. There are
4296 ;; Search for a good shell before searching for a command which 4297 ;; also other problems with /bin/sh of OpenSolaris, like
4297 ;; checks if a file exists. This is done because Tramp wants to use 4298 ;; redirection of stderr in function declarations, or changing
4298 ;; "test foo; echo $?" to check if various conditions hold, and 4299 ;; HISTFILE in place. Therefore, OpenSolaris' /bin/sh is replaced
4299 ;; there are buggy /bin/sh implementations which don't execute the 4300 ;; by bash, when detected.
4300 ;; "echo $?" part if the "test" part has an error. In particular, 4301 (tramp-find-shell vec)
4301 ;; the OpenSolaris /bin/sh is a problem. There are also other 4302
4302 ;; problems with /bin/sh of OpenSolaris, like redirection of stderr 4303 ;; Disable unexpected output.
4303 ;; in function declarations, or changing HISTFILE in place. 4304 (tramp-send-command vec "mesg n 2>/dev/null; biff n 2>/dev/null" t)
4304 ;; Therefore, OpenSolaris' /bin/sh is replaced by bash, when 4305
4305 ;; detected. 4306 ;; IRIX64 bash expands "!" even when in single quotes. This
4306 (tramp-find-shell vec) 4307 ;; destroys our shell functions, we must disable it. See
4307 4308 ;; <http://stackoverflow.com/questions/3291692/irix-bash-shell-expands-expression-in-single-quotes-yet-shouldnt>.
4308 ;; Disable unexpected output. 4309 (when (string-match "^IRIX64" uname)
4309 (tramp-send-command vec "mesg n 2>/dev/null; biff n 2>/dev/null" t) 4310 (tramp-send-command vec "set +H" t))
4310 4311
4311 ;; IRIX64 bash expands "!" even when in single quotes. This 4312 ;; Disable tab expansion.
4312 ;; destroys our shell functions, we must disable it. See 4313 (if (string-match "BSD\\|Darwin" uname)
4313 ;; <http://stackoverflow.com/questions/3291692/irix-bash-shell-expands-expression-in-single-quotes-yet-shouldnt>. 4314 (tramp-send-command vec "stty tabs" t)
4314 (when (string-match "^IRIX64" (tramp-get-connection-property vec "uname" "")) 4315 (tramp-send-command vec "stty tab0" t))
4315 (tramp-send-command vec "set +H" t)) 4316
4316 4317 ;; Set utf8 encoding. Needed for Mac OS X, for example. This is
4317 ;; On BSD-like systems, ?\t is expanded to spaces. Suppress this. 4318 ;; non-POSIX, so we must expect errors on some systems.
4318 (when (string-match "BSD\\|Darwin" 4319 (tramp-send-command vec "stty iutf8 2>/dev/null" t)
4319 (tramp-get-connection-property vec "uname" "")) 4320
4320 (tramp-send-command vec "stty -oxtabs" t)) 4321 ;; Set `remote-tty' process property.
4321 4322 (let ((tty (tramp-send-command-and-read vec "echo \\\"`tty`\\\"" 'noerror)))
4322 ;; Set utf8 encoding. Needed for Mac OS X, for example. This is 4323 (unless (zerop (length tty))
4323 ;; non-POSIX, so we must expect errors on some systems. 4324 (tramp-compat-process-put proc 'remote-tty tty)))
4324 (tramp-send-command vec "stty iutf8 2>/dev/null" t) 4325
4325 4326 ;; Dump stty settings in the traces.
4326 ;; Set `remote-tty' process property. 4327 (when (>= tramp-verbose 9)
4327 (let ((tty (tramp-send-command-and-read vec "echo \\\"`tty`\\\"" 'noerror))) 4328 (tramp-send-command vec "stty -a" t))
4328 (unless (zerop (length tty)) 4329
4329 (tramp-compat-process-put proc 'remote-tty tty))) 4330 ;; Set the environment.
4330 4331 (tramp-message vec 5 "Setting default environment")
4331 ;; Dump stty settings in the traces. 4332
4332 (when (>= tramp-verbose 9) 4333 (let ((env (append `(,(tramp-get-remote-locale vec))
4333 (tramp-send-command vec "stty -a" t)) 4334 (copy-sequence tramp-remote-process-environment)))
4334 4335 unset vars item)
4335 ;; Set the environment. 4336 (while env
4336 (tramp-message vec 5 "Setting default environment") 4337 (setq item (tramp-compat-split-string (car env) "="))
4337 4338 (setcdr item (mapconcat 'identity (cdr item) "="))
4338 (let ((env (append `(,(tramp-get-remote-locale vec)) 4339 (if (and (stringp (cdr item)) (not (string-equal (cdr item) "")))
4339 (copy-sequence tramp-remote-process-environment))) 4340 (push (format "%s %s" (car item) (cdr item)) vars)
4340 unset vars item) 4341 (push (car item) unset))
4341 (while env 4342 (setq env (cdr env)))
4342 (setq item (tramp-compat-split-string (car env) "=")) 4343 (when vars
4343 (setcdr item (mapconcat 'identity (cdr item) "=")) 4344 (tramp-send-command
4344 (if (and (stringp (cdr item)) (not (string-equal (cdr item) ""))) 4345 vec
4345 (push (format "%s %s" (car item) (cdr item)) vars) 4346 (format "while read var val; do export $var=$val; done <<'%s'\n%s\n%s"
4346 (push (car item) unset)) 4347 tramp-end-of-heredoc
4347 (setq env (cdr env))) 4348 (mapconcat 'identity vars "\n")
4348 (when vars 4349 tramp-end-of-heredoc)
4349 (tramp-send-command 4350 t))
4350 vec 4351 (when unset
4351 (format "while read var val; do export $var=$val; done <<'%s'\n%s\n%s" 4352 (tramp-send-command
4352 tramp-end-of-heredoc 4353 vec (format "unset %s" (mapconcat 'identity unset " ")) t)))))
4353 (mapconcat 'identity vars "\n")
4354 tramp-end-of-heredoc)
4355 t))
4356 (when unset
4357 (tramp-send-command
4358 vec (format "unset %s" (mapconcat 'identity unset " ")) t))))
4359 4354
4360;; Old text from documentation of tramp-methods: 4355;; Old text from documentation of tramp-methods:
4361;; Using a uuencode/uudecode inline method is discouraged, please use one 4356;; Using a uuencode/uudecode inline method is discouraged, please use one