unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39399: tramp depends on unstable details of shell command line processing
@ 2020-02-02 21:28 John F Carr
  2020-02-03  8:58 ` Michael Albinus
  2020-07-27  4:12 ` 内藤 祐一郎
  0 siblings, 2 replies; 9+ messages in thread
From: John F Carr @ 2020-02-02 21:28 UTC (permalink / raw)
  To: 39399

I use emacs tramp mode for remote editing.  It stopped working on my FreeBSD systems when I upgraded to a development version.  The cause appears to be due to /bin/sh reprinting the entire line when a backspace is sent rather than sending only a backspace-space-backspace sequence.  The failure follows a change in the line editing library (shared with NetBSD) rather than the shell itself.

Environment is emacs 24.5 or 26.3 running on Mac OS Catalina.  The remote system is FreeBSD 13.0 development.  Tramp works with Linux or FreeBSD 12.1 as the remote system.

Here's what happens.

I load tramp and open a file like /ssh:user@host:/.  Emacs spawns ssh to connect.  The first thing tramp does is send

stty -inlcr -onlcr -echo kill '^U' erase '^H'

But this doesn't do much because the tty is in raw mode rather than cooked due to the shell's line editor.  So tramp falls back to a hack to detect echoed input.  It sends "_echo" followed by a string of backspace characters.  "_echo" is unlikely to appear in program output.

Here is the next command after the initial stty:

_echo^H^H^H^H^Hstty icanon erase ^H cols 32767_echo^H^H^H^H^H

The groups of 5 ^H represent 5 backspace characters and the lone ^H in the middle is a two character sequence for stty.

The terminal output from a 12.1 system is

_echo^H ^H^H ^H^H ^H^H ^H^H ^Hstty icanon erase ^H cols 32767_echo^H ^H^H ^H^H ^H^H ^H^H ^H
#$ 

where again the middle ^H is a two character sequence and the others are backspace characters. There is a carriage return between the two lines.  "#$ " is the shell prompt set by tramp.

The terminal output from a FreeBSD 13.0 development branch system is

_echo
#$ _ech ^H
#$ _ec ^H
#$ _e ^H
#$ _ ^H
#$  ^Hstty icanon erase ^H cols 32767_echo
#$ stty icanon erase ^H cols 32767_ech ^H
#$ stty icanon erase ^H cols 32767_ec ^H
#$ stty icanon erase ^H cols 32767_e ^H
#$ stty icanon erase ^H cols 32767_ ^H
#$ stty icanon erase ^H cols 32767 ^H
#$ 

with carriage returns between lines.  This does not make sense to emacs, which hangs waiting for something it recognizes.  I can recover by hitting control-G which aborts the tramp connection.

This issue is also reported to FreeBSD at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=243807.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-02-02 21:28 bug#39399: tramp depends on unstable details of shell command line processing John F Carr
@ 2020-02-03  8:58 ` Michael Albinus
  2020-02-04  8:34   ` Michael Albinus
  2020-07-27  4:12 ` 内藤 祐一郎
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-02-03  8:58 UTC (permalink / raw)
  To: John F Carr; +Cc: 39399

John F Carr <jfc@mit.edu> writes:

Hi John,

> I use emacs tramp mode for remote editing.  It stopped working on my
> FreeBSD systems when I upgraded to a development version.  The cause
> appears to be due to /bin/sh reprinting the entire line when a
> backspace is sent rather than sending only a backspace-space-backspace
> sequence.  The failure follows a change in the line editing library
> (shared with NetBSD) rather than the shell itself.
>
> Environment is emacs 24.5 or 26.3 running on Mac OS Catalina.  The
> remote system is FreeBSD 13.0 development.  Tramp works with Linux or
> FreeBSD 12.1 as the remote system.

Thanks a lot for your report! Since I'm not running FreeBSD anywhere, I
count on your support fixing the problem :-)

> Here's what happens.
>
> I load tramp and open a file like /ssh:user@host:/.  Emacs spawns ssh to connect.  The first thing tramp does is send
>
> stty -inlcr -onlcr -echo kill '^U' erase '^H'
>
> But this doesn't do much because the tty is in raw mode rather than
> cooked due to the shell's line editor.  So tramp falls back to a hack
> to detect echoed input.  It sends "_echo" followed by a string of
> backspace characters.  "_echo" is unlikely to appear in program
> output.
>
> Here is the next command after the initial stty:
>
> _echo^H^H^H^H^Hstty icanon erase ^H cols 32767_echo^H^H^H^H^H
>
> The groups of 5 ^H represent 5 backspace characters and the lone ^H in the middle is a two character sequence for stty.
>
> The terminal output from a 12.1 system is
>
> _echo^H ^H^H ^H^H ^H^H ^H^H ^Hstty icanon erase ^H cols 32767_echo^H ^H^H ^H^H ^H^H ^H^H ^H
> #$
>
> where again the middle ^H is a two character sequence and the others
> are backspace characters. There is a carriage return between the two
> lines.  "#$ " is the shell prompt set by tramp.

Well, and this works for years.

> The terminal output from a FreeBSD 13.0 development branch system is
>
> _echo
> #$ _ech ^H
> #$ _ec ^H
> #$ _e ^H
> #$ _ ^H
> #$  ^Hstty icanon erase ^H cols 32767_echo
> #$ stty icanon erase ^H cols 32767_ech ^H
> #$ stty icanon erase ^H cols 32767_ec ^H
> #$ stty icanon erase ^H cols 32767_e ^H
> #$ stty icanon erase ^H cols 32767_ ^H
> #$ stty icanon erase ^H cols 32767 ^H
> #$
>
> with carriage returns between lines.  This does not make sense to
> emacs, which hangs waiting for something it recognizes.  I can recover
> by hitting control-G which aborts the tramp connection.
>
> This issue is also reported to FreeBSD at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=243807.

IIUC the discussion in that bug, it is due to the changed libedit of
FreeBSD 13. Hmm, don't know this beast. But wouldn't it help, if Tramps
sends initially "stty cooked"?

Best regards, Michael.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-02-03  8:58 ` Michael Albinus
@ 2020-02-04  8:34   ` Michael Albinus
  2020-02-05 23:42     ` John F Carr
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-02-04  8:34 UTC (permalink / raw)
  To: John F Carr; +Cc: 39399

[-- Attachment #1: Type: text/plain, Size: 1518 bytes --]

Michael Albinus <michael.albinus@gmx.de> writes:

Hi John,

>> The terminal output from a FreeBSD 13.0 development branch system is
>>
>> _echo
>> #$ _ech ^H
>> #$ _ec ^H
>> #$ _e ^H
>> #$ _ ^H
>> #$  ^Hstty icanon erase ^H cols 32767_echo
>> #$ stty icanon erase ^H cols 32767_ech ^H
>> #$ stty icanon erase ^H cols 32767_ec ^H
>> #$ stty icanon erase ^H cols 32767_e ^H
>> #$ stty icanon erase ^H cols 32767_ ^H
>> #$ stty icanon erase ^H cols 32767 ^H
>> #$
>>
>> with carriage returns between lines.  This does not make sense to
>> emacs, which hangs waiting for something it recognizes.  I can recover
>> by hitting control-G which aborts the tramp connection.
>>
>> This issue is also reported to FreeBSD at
>> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=243807.
>
> IIUC the discussion in that bug, it is due to the changed libedit of
> FreeBSD 13. Hmm, don't know this beast. But wouldn't it help, if Tramps
> sends initially "stty cooked"?

I've digged further. Likely, the problem can be avoided if we disable
command line editing of the shell. Tramp does it already if the remote
shell is zsh; I've added a similar parameter to the bash invocation. For
other shells, like ksh, I haven't found a simple parameter.

For that class of shells, I've added code which installs a temporary
~/.editrc file, containing the line 'edit off'.

Could you please migrate to Tramp 2.4.3.1 from GNU ELPA? On top of this,
install the appended patch.

And pls report, whether it works for you.

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2633 bytes --]

diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el
index 661e344d..49519926 100644
--- a/lisp/tramp-sh.el
+++ b/lisp/tramp-sh.el
@@ -537,12 +537,13 @@ based on the Tramp and Emacs versions, and should not be set here."

 ;;;###tramp-autoload
 (defcustom tramp-sh-extra-args
-  '(("/bash\\'" . "-norc -noprofile")
+  '(("/bash\\'" . "-noediting -norc -noprofile")
     ("/zsh\\'" . "-f +Z -V"))
   "Alist specifying extra arguments to pass to the remote shell.
 Entries are (REGEXP . ARGS) where REGEXP is a regular expression
 matching the shell file name and ARGS is a string specifying the
-arguments.
+arguments.  These arguments shall disable line editing, see
+`tramp-open-shell'.

 This variable is only used when Tramp needs to start up another shell
 for tilde expansion.  The extra arguments should typically prevent the
@@ -4107,6 +4108,24 @@ file exists and nonzero exit status otherwise."
       vec 5 (format-message "Opening remote shell `%s'" shell)
     ;; Find arguments for this shell.
     (let ((extra-args (tramp-get-sh-extra-args shell)))
+      ;; The readline library can disturb Tramp.  For example, the
+      ;; very recent version of libedit, the *BSD implementation of
+      ;; readline, confuses Tramp.  So we disable line editing.  Since
+      ;; $EDITRC is not supported on all target systems, we must move
+      ;; ~/.editrc temporarily somewhere else.  For bash and zsh we
+      ;; have disabled this already, see `tramp-sh-extra-args'.  Bug#39399.
+      (unless extra-args
+	(tramp-send-command
+	 vec (eval-when-compile
+	       (concat
+		"(rm -f ~/.editrc.tramp; "
+		"mv -f ~/.editrc ~/.editrc.tramp; "
+		"echo 'edit off' >~/.editrc)"))
+	 t t)
+	(while
+	    (tramp-accept-process-output (tramp-get-connection-process vec) 0)))
+      ;; It is useful to set the prompt in the following command
+      ;; because some people have a setting for $PS1 which /bin/sh
       ;; doesn't know about and thus /bin/sh will display a strange
       ;; prompt.  For example, if $PS1 has "${CWD}" in the value, then
       ;; ksh will display the current working directory but /bin/sh
@@ -4140,6 +4159,9 @@ file exists and nonzero exit status otherwise."
 	    (tramp-shell-quote-argument tramp-end-of-output)
 	    shell (or extra-args ""))
        t)
+      (unless extra-args
+	(tramp-send-command
+	 vec "test -e ~/.editrc.tramp && mv -f ~/.editrc.tramp ~/.editrc" t))
       ;; Check proper HISTFILE setting.  We give up when not working.
       (when (and (stringp tramp-histfile-override)
 		 (file-name-directory tramp-histfile-override))

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-02-04  8:34   ` Michael Albinus
@ 2020-02-05 23:42     ` John F Carr
  2020-02-06  9:13       ` Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: John F Carr @ 2020-02-05 23:42 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 39399@debbugs.gnu.org

On Feb 4, 2020, at 03:34 , Michael Albinus <michael.albinus@gmx.de> wrote:
> 
> Michael Albinus <michael.albinus@gmx.de> writes:
> 
> Hi John,
> 
>>> The terminal output from a FreeBSD 13.0 development branch system is
>>> 
>>> _echo
>>> #$ _ech ^H
>>> #$ _ec ^H
>>> #$ _e ^H
>>> #$ _ ^H
>>> #$  ^Hstty icanon erase ^H cols 32767_echo
>>> #$ stty icanon erase ^H cols 32767_ech ^H
>>> #$ stty icanon erase ^H cols 32767_ec ^H
>>> #$ stty icanon erase ^H cols 32767_e ^H
>>> #$ stty icanon erase ^H cols 32767_ ^H
>>> #$ stty icanon erase ^H cols 32767 ^H
>>> #$
>>> 
>>> with carriage returns between lines.  This does not make sense to
>>> emacs, which hangs waiting for something it recognizes.  I can recover
>>> by hitting control-G which aborts the tramp connection.
>>> 
>>> This issue is also reported to FreeBSD at
>>> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=243807.
>> 
>> IIUC the discussion in that bug, it is due to the changed libedit of
>> FreeBSD 13. Hmm, don't know this beast. But wouldn't it help, if Tramps
>> sends initially "stty cooked"?
> 
> I've digged further. Likely, the problem can be avoided if we disable
> command line editing of the shell. Tramp does it already if the remote
> shell is zsh; I've added a similar parameter to the bash invocation. For
> other shells, like ksh, I haven't found a simple parameter.
> 
> For that class of shells, I've added code which installs a temporary
> ~/.editrc file, containing the line 'edit off'.
> 
> Could you please migrate to Tramp 2.4.3.1 from GNU ELPA? On top of this,
> install the appended patch.
> 
> And pls report, whether it works for you.
> 
> Best regards, Michael.
> 
> <Mail Attachment>

Your change applied to tramp 2.4.3 from ELPA works.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-02-05 23:42     ` John F Carr
@ 2020-02-06  9:13       ` Michael Albinus
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Albinus @ 2020-02-06  9:13 UTC (permalink / raw)
  To: John F Carr; +Cc: 39399@debbugs.gnu.org

Version: 27.2

John F Carr <jfc@mit.edu> writes:

Hi John,

>> I've digged further. Likely, the problem can be avoided if we disable
>> command line editing of the shell. Tramp does it already if the remote
>> shell is zsh; I've added a similar parameter to the bash invocation. For
>> other shells, like ksh, I haven't found a simple parameter.
>>
>> For that class of shells, I've added code which installs a temporary
>> ~/.editrc file, containing the line 'edit off'.
>>
>> Could you please migrate to Tramp 2.4.3.1 from GNU ELPA? On top of this,
>> install the appended patch.
>>
>> And pls report, whether it works for you.
>
> Your change applied to tramp 2.4.3 from ELPA works.

Thanks for the feedback. Since I have no *BSD machine, I couldn't test
the patch; it was rather a shot into the dark.

I've pushed the patch, slightly modified, to the Emacs and Tramp
repositories. It won't appear with Emacs 27.1, because it is too late to
commit such serious changes so close to its release; but I will merge it
into the emacs-27 codebase after Emacs 27.1 has been released.

The next GNU ELPA Tramp release, 2.4.3.2, will carry this patch. It will
appear in a couple of weeks.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-02-02 21:28 bug#39399: tramp depends on unstable details of shell command line processing John F Carr
  2020-02-03  8:58 ` Michael Albinus
@ 2020-07-27  4:12 ` 内藤 祐一郎
  2020-07-27 18:01   ` Michael Albinus
  1 sibling, 1 reply; 9+ messages in thread
From: 内藤 祐一郎 @ 2020-07-27  4:12 UTC (permalink / raw)
  To: 39399

[-- Attachment #1: Type: text/plain, Size: 1002 bytes --]

Hi.

I could find a another way to solve this problem that avoids changing ~/.editrc and it's more simple.
See my patch attached on this mail.

This problem happens on the latest libedit and FreeBSD sh uses Emacs edit mode by default.

If libedit runs on edit mode, libedit rewrites line by each control character.
On '^H', libedit sends line feed and write characters on the line that is held in the internal screen buffer of libedit.

If edit mode turns off, line edit works on terminal that is as same as previous behavior.

Shell command `set +E` escapes from edit mode in spite of libedit has two edit mode (Emacs and Vi). `set +E` disables both of them.

Although libedit has been developed and used by NetBSD, NetBSD doesn’t have this problem.
Because NetBSD sh doesn't use edit mode by default.

I could confirm my patch solves this problem on emacs-26.3.
And also works to FreeBSD current & OpenBSD current & RedHat 7.8.

—
Yuichiro NAITO
naito.yuichiro@gmail.com


[-- Attachment #2: tramp.patch --]
[-- Type: application/octet-stream, Size: 509 bytes --]

diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 18ae295108..ee64b3b13d 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -4059,6 +4059,7 @@ process to set up.  VEC specifies the connection."
 
     ;; Disable echo expansion.
     (tramp-message vec 5 "Setting up remote shell environment")
+    (tramp-send-command vec "set +E" t)
     (tramp-send-command
      vec "stty -inlcr -onlcr -echo kill '^U' erase '^H'" t)
     ;; Check whether the echo has really been disabled.  Some

[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-07-27  4:12 ` 内藤 祐一郎
@ 2020-07-27 18:01   ` Michael Albinus
  2020-07-28  2:51     ` 内藤 祐一郎
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-07-27 18:01 UTC (permalink / raw)
  To: 内藤 祐一郎; +Cc: 39399

[-- Attachment #1: Type: text/plain, Size: 1619 bytes --]

内藤 祐一郎 <naito.yuichiro@gmail.com> writes:

> Hi.

Hi,

> I could find a another way to solve this problem that avoids changing
> ~/.editrc and it's more simple.
> See my patch attached on this mail.
>
> This problem happens on the latest libedit and FreeBSD sh uses Emacs
> edit mode by default.
>
> If libedit runs on edit mode, libedit rewrites line by each control character.
> On '^H', libedit sends line feed and write characters on the line that
> is held in the internal screen buffer of libedit.
>
> If edit mode turns off, line edit works on terminal that is as same as
> previous behavior.
>
> Shell command `set +E` escapes from edit mode in spite of libedit has
> two edit mode (Emacs and Vi). `set +E` disables both of them.
>
> Although libedit has been developed and used by NetBSD, NetBSD doesn’t
> have this problem.
> Because NetBSD sh doesn't use edit mode by default.

Thanks for the report. However, your patch is not applicable in general,
because the "+E" option is not POSIX conform, and it isn't supported by
all shells. I thought already about this when I was fixing bug#39399.

But wait - "set +o emacs +o vi" might give the same effect, and it is
much more supported by shells. And reading the sources, Tramp calls it
already (might have been added by Kai, many years ago). Maybe it is
sufficient to move it earlier in the initialization machinery?

Appended is a patch for Tramp 2.4.4. You might install it from GNU
ELPA. Please check, whether this works for you.

> Yuichiro NAITO
> naito.yuichiro@gmail.com

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 8309 bytes --]

*** /tmp/ediffbojDZA	2020-07-27 19:49:26.025530831 +0200
--- /home/albinus/src/tramp-2-4-stable/lisp/tramp-sh.el	2020-07-27 19:38:04.853551455 +0200
***************
*** 4104,4183 ****

  (defun tramp-open-shell (vec shell)
    "Open shell SHELL."
    (with-tramp-progress-reporter
        vec 5 (format-message "Opening remote shell `%s'" shell)
!     ;; Find arguments for this shell.
!     (let ((extra-args (tramp-get-sh-extra-args shell))
! 	  (p (tramp-get-connection-process vec)))
!       ;; The readline library can disturb Tramp.  For example, the
!       ;; very recent version of libedit, the *BSD implementation of
!       ;; readline, confuses Tramp.  So we disable line editing.  Since
!       ;; $EDITRC is not supported on all target systems, we must move
!       ;; ~/.editrc temporarily somewhere else.  For bash and zsh we
!       ;; have disabled this already during shell invocation, see
!       ;; `tramp-sh-extra-args' (Bug#39399).
!       ;; The shell prompt might not be set yet, so we must read any
!       ;; prompt via `tramp-barf-if-no-shell-prompt'.
!       (unless extra-args
! 	(tramp-send-command vec "rm -f ~/.editrc.tramp" t t)
! 	(tramp-barf-if-no-shell-prompt p 10 "Couldn't find remote shell prompt")
! 	(tramp-send-command
! 	 vec "test -e ~/.editrc && mv -f ~/.editrc ~/.editrc.tramp" t t)
! 	(tramp-barf-if-no-shell-prompt p 10 "Couldn't find remote shell prompt")
! 	(tramp-send-command vec "echo 'edit off' >~/.editrc" t t)
! 	(tramp-barf-if-no-shell-prompt
! 	 p 10 "Couldn't find remote shell prompt"))
!       ;; It is useful to set the prompt in the following command
!       ;; because some people have a setting for $PS1 which /bin/sh
!       ;; doesn't know about and thus /bin/sh will display a strange
!       ;; prompt.  For example, if $PS1 has "${CWD}" in the value, then
!       ;; ksh will display the current working directory but /bin/sh
!       ;; will display a dollar sign.  The following command line sets
!       ;; $PS1 to a sane value, and works under Bourne-ish shells as
!       ;; well as csh-like shells.  We also unset the variable $ENV
!       ;; because that is read by some sh implementations (eg, bash
!       ;; when called as sh) on startup; this way, we avoid the startup
!       ;; file clobbering $PS1.  $PROMPT_COMMAND is another way to set
!       ;; the prompt in /bin/bash, it must be discarded as well.
!       ;; $HISTFILE is set according to `tramp-histfile-override'.
!       ;; $TERM and $INSIDE_EMACS set here to ensure they have the
!       ;; correct values when the shell starts, not just processes
!       ;; run within the shell.  (Which processes include our
!       ;; initial probes to ensure the remote shell is usable.)
!       (tramp-send-command
!        vec (format
! 	    (eval-when-compile
! 	      (concat
! 	       "exec env TERM='%s' INSIDE_EMACS='%s,tramp:%s' "
! 	       "ENV=%s %s PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"))
!             tramp-terminal-type
!             emacs-version tramp-version  ; INSIDE_EMACS
!             (or (getenv-internal "ENV" tramp-remote-process-environment) "")
! 	    (if (stringp tramp-histfile-override)
! 		(format "HISTFILE=%s"
! 			(tramp-shell-quote-argument tramp-histfile-override))
! 	      (if tramp-histfile-override
! 		  "HISTFILE='' HISTFILESIZE=0 HISTSIZE=0"
! 		""))
! 	    (tramp-shell-quote-argument tramp-end-of-output)
! 	    shell (or extra-args ""))
!        t)
!       ;; Reset ~/.editrc.
!       (unless extra-args
! 	(tramp-send-command vec "rm -f ~/.editrc" t)
! 	(tramp-send-command
! 	 vec "test -e ~/.editrc.tramp && mv -f ~/.editrc.tramp ~/.editrc" t))
!       ;; Check proper HISTFILE setting.  We give up when not working.
!       (when (and (stringp tramp-histfile-override)
! 		 (file-name-directory tramp-histfile-override))
! 	(tramp-barf-unless-okay
! 	 vec
! 	 (format
! 	  "(cd %s)"
! 	  (tramp-shell-quote-argument
! 	   (file-name-directory tramp-histfile-override)))
! 	 "`tramp-histfile-override' uses invalid file `%s'"
! 	 tramp-histfile-override)))

      (tramp-set-connection-property
       (tramp-get-connection-process vec) "remote-shell" shell)))
--- 4104,4157 ----

  (defun tramp-open-shell (vec shell)
    "Open shell SHELL."
+   ;; Find arguments for this shell.
    (with-tramp-progress-reporter
        vec 5 (format-message "Opening remote shell `%s'" shell)
!     ;; It is useful to set the prompt in the following command because
!     ;; some people have a setting for $PS1 which /bin/sh doesn't know
!     ;; about and thus /bin/sh will display a strange prompt.  For
!     ;; example, if $PS1 has "${CWD}" in the value, then ksh will
!     ;; display the current working directory but /bin/sh will display
!     ;; a dollar sign.  The following command line sets $PS1 to a sane
!     ;; value, and works under Bourne-ish shells as well as csh-like
!     ;; shells.  We also unset the variable $ENV because that is read
!     ;; by some sh implementations (eg, bash when called as sh) on
!     ;; startup; this way, we avoid the startup file clobbering $PS1.
!     ;; $PROMPT_COMMAND is another way to set the prompt in /bin/bash,
!     ;; it must be discarded as well.  $HISTFILE is set according to
!     ;; `tramp-histfile-override'.  $TERM and $INSIDE_EMACS set here to
!     ;; ensure they have the correct values when the shell starts, not
!     ;; just processes run within the shell.  (Which processes include
!     ;; our initial probes to ensure the remote shell is usable.)
!     (tramp-send-command
!      vec (format
! 	  (eval-when-compile
! 	    (concat
! 	     "exec env TERM='%s' INSIDE_EMACS='%s,tramp:%s' "
! 	     "ENV=%s %s PROMPT_COMMAND='' PS1=%s PS2='' PS3='' %s %s"))
!           tramp-terminal-type
!           emacs-version tramp-version  ; INSIDE_EMACS
!           (or (getenv-internal "ENV" tramp-remote-process-environment) "")
! 	  (if (stringp tramp-histfile-override)
! 	      (format "HISTFILE=%s"
! 		      (tramp-shell-quote-argument tramp-histfile-override))
! 	    (if tramp-histfile-override
! 		"HISTFILE='' HISTFILESIZE=0 HISTSIZE=0"
! 	      ""))
! 	  (tramp-shell-quote-argument tramp-end-of-output)
! 	  shell (or (tramp-get-sh-extra-args shell) ""))
!      t)
!     ;; Check proper HISTFILE setting.  We give up when not working.
!     (when (and (stringp tramp-histfile-override)
! 	       (file-name-directory tramp-histfile-override))
!       (tramp-barf-unless-okay
!        vec
!        (format
! 	"(cd %s)"
! 	(tramp-shell-quote-argument
! 	 (file-name-directory tramp-histfile-override)))
!        "`tramp-histfile-override' uses invalid file `%s'"
!        tramp-histfile-override))

      (tramp-set-connection-property
       (tramp-get-connection-process vec) "remote-shell" shell)))
***************
*** 4248,4256 ****
    (let ((tramp-end-of-output tramp-initial-end-of-output)
  	(case-fold-search t))
      (tramp-open-shell vec (tramp-get-method-parameter vec 'tramp-remote-shell))

      ;; Disable echo expansion.
-     (tramp-message vec 5 "Setting up remote shell environment")
      (tramp-send-command
       vec "stty -inlcr -onlcr -echo kill '^U' erase '^H'" t)
      ;; Check whether the echo has really been disabled.  Some
--- 4222,4233 ----
    (let ((tramp-end-of-output tramp-initial-end-of-output)
  	(case-fold-search t))
      (tramp-open-shell vec (tramp-get-method-parameter vec 'tramp-remote-shell))
+     (tramp-message vec 5 "Setting up remote shell environment")
+
+     ;; Disable line editing.
+     (tramp-send-command vec "set +o vi +o emacs" t)

      ;; Disable echo expansion.
      (tramp-send-command
       vec "stty -inlcr -onlcr -echo kill '^U' erase '^H'" t)
      ;; Check whether the echo has really been disabled.  Some
***************
*** 4320,4327 ****
  	(tramp-message
  	 vec 5 "Setting coding system to `%s' and `%s'" cs-decode cs-encode)))

-     (tramp-send-command vec "set +o vi +o emacs" t)
-
      ;; Check whether the remote host suffers from buggy
      ;; `send-process-string'.  This is known for FreeBSD (see comment
      ;; in `send_process', file process.c).  I've tested sending 624
--- 4297,4302 ----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-07-27 18:01   ` Michael Albinus
@ 2020-07-28  2:51     ` 内藤 祐一郎
  2020-07-28  7:34       ` Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: 内藤 祐一郎 @ 2020-07-28  2:51 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 39399

Thanks for the reply.

> 2020/07/28 3:01、Michael Albinus <michael.albinus@gmx.de>のメール:
>> I could find a another way to solve this problem that avoids changing
>> ~/.editrc and it's more simple.
>> See my patch attached on this mail.
>> 
>> This problem happens on the latest libedit and FreeBSD sh uses Emacs
>> edit mode by default.
>> 
>> If libedit runs on edit mode, libedit rewrites line by each control character.
>> On '^H', libedit sends line feed and write characters on the line that
>> is held in the internal screen buffer of libedit.
>> 
>> If edit mode turns off, line edit works on terminal that is as same as
>> previous behavior.
>> 
>> Shell command `set +E` escapes from edit mode in spite of libedit has
>> two edit mode (Emacs and Vi). `set +E` disables both of them.
>> 
>> Although libedit has been developed and used by NetBSD, NetBSD doesn’t
>> have this problem.
>> Because NetBSD sh doesn't use edit mode by default.
> 
> Thanks for the report. However, your patch is not applicable in general,
> because the "+E" option is not POSIX conform, and it isn't supported by
> all shells. I thought already about this when I was fixing bug#39399.
> 
> But wait - "set +o emacs +o vi" might give the same effect, and it is
> much more supported by shells. And reading the sources, Tramp calls it
> already (might have been added by Kai, many years ago). Maybe it is
> sufficient to move it earlier in the initialization machinery?

Exactly yes it is!
“ set +o emacs +o vi” works as same as “set +E” on FreeBSD sh.
Tramp-mode hung before it, so it was not executed.

> Appended is a patch for Tramp 2.4.4. You might install it from GNU
> ELPA. Please check, whether this works for you.

The appended patch works for me.
But I think just moving "set +o emacs +o vi” before “stty …” is more simple way.

—
Yuichiro NAITO
naito.yuichiro@gmail.com






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#39399: tramp depends on unstable details of shell command line processing
  2020-07-28  2:51     ` 内藤 祐一郎
@ 2020-07-28  7:34       ` Michael Albinus
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Albinus @ 2020-07-28  7:34 UTC (permalink / raw)
  To: 内藤 祐一郎; +Cc: John F Carr, 39399-done

内藤 祐一郎 <naito.yuichiro@gmail.com> writes:

Hi,

>> Appended is a patch for Tramp 2.4.4. You might install it from GNU
>> ELPA. Please check, whether this works for you.
>
> The appended patch works for me.
> But I think just moving "set +o emacs +o vi” before “stty …” is more simple way.

Thanks for the feedback. In fact, the patch does exactly this: moving up
the "set +o emacs +o vi” command. The rest of the patch removes the
handling of "~/.editrc", which was added as first attempt to solve this
bug, and which isn't needed anymore.

@John, I've Cc'ed you that you can check whether the changed fix still
works for you.

I'm closing this bug, again. The patch has been committed to the
repositories. Tramp 2.4.4.1, planned to be released later this week on
GNU ELPA, will contain it.

Furthermore, this patch will also be in Emacs 27.2. For Emacs 27.1 it's
too late to commit.

> Yuichiro NAITO

Best regards, Michael.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-07-28  7:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-02 21:28 bug#39399: tramp depends on unstable details of shell command line processing John F Carr
2020-02-03  8:58 ` Michael Albinus
2020-02-04  8:34   ` Michael Albinus
2020-02-05 23:42     ` John F Carr
2020-02-06  9:13       ` Michael Albinus
2020-07-27  4:12 ` 内藤 祐一郎
2020-07-27 18:01   ` Michael Albinus
2020-07-28  2:51     ` 内藤 祐一郎
2020-07-28  7:34       ` Michael Albinus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).