NetBSD Problem Report #52517

From www@NetBSD.org  Thu Aug 31 21:46:45 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 072B67A1BE
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 31 Aug 2017 21:46:45 +0000 (UTC)
Message-Id: <20170831214644.09F2B7A2A6@mollari.NetBSD.org>
Date: Thu, 31 Aug 2017 21:46:44 +0000 (UTC)
From: jhdub23@gmail.com
Reply-To: jhdub23@gmail.com
To: gnats-bugs@NetBSD.org
Subject: TTY settings modified and not restored on exit.
X-Send-Pr-Version: www-1.0

>Number:         52517
>Category:       lib
>Synopsis:       TTY settings modified and not restored on exit.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 31 21:50:00 +0000 2017
>Closed-Date:    Mon Jun 04 10:58:27 +0000 2018
>Last-Modified:  Mon Jun 04 10:58:27 +0000 2018
>Originator:     Jay West
>Release:        libedit (NetBSD-current)
>Organization:
Self
>Environment:
Linux [deleted] 2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
>Description:
libedit modifies TTY settings when used, and does not have a mechanism to fully save and restore TTY settings.  This causes problems when libedit is used as a GNU readline replacement.

Specifically, after running python+GnuReadline, TTY settings are untouched after python exits.  However, python+libedit has noticeable TTY changes after python exits.

This will be true for any application linked against libedit instead of GnuReadline.
>How-To-Repeat:
% stty -a > orig.txt
% python # Run python compiled with libedit, and immediately exit (or any application using libedit).
% stty -a > after.txt
% diff orig.txt after.txt  # Differences exist

>Fix:
Patch to save TTY settings on init, and restore on program exit.
-------------------------
diff --git a/src/terminal.c b/src/terminal.c
index 26838e813d..53441ea6d8 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -268,6 +268,7 @@ terminal_setflags(EditLine *el)
 libedit_private int
 terminal_init(EditLine *el)
 {
+	tty_save();

 	el->el_terminal.t_buf = el_malloc(TC_BUFSIZE *
 	    sizeof(*el->el_terminal.t_buf));
diff --git a/src/tty.c b/src/tty.c
index f524da4734..e3adcdd659 100644
--- a/src/tty.c
+++ b/src/tty.c
@@ -467,6 +467,190 @@ static void	tty_setup_flags(EditLine *, struct termios *, int);

 #define	t_qu	t_ts

+/**********
+ * Acknowledgement:  tty_save/tty_restore/tty_signal is from
+ *      https://cboard.cprogramming.com/linux-programming/158476-termios-examples.html
+ **********/
+
+static int            tty_descriptor = -1;
+static struct termios tty_original;
+static struct termios tty_settings;
+
+struct termios* tty_get_original() {
+  return &tty_original;
+}
+
+/* Restore terminal to original settings
+*/
+static void tty_restore(void)
+{
+    if (tty_descriptor != -1)
+        tcsetattr(tty_descriptor, TCSANOW, &tty_original);
+}
+
+/* "Default" signal handler: restore terminal, then exit.
+*/
+static void tty_signal(int signum)
+{
+    if (tty_descriptor != -1)
+        tcsetattr(tty_descriptor, TCSANOW, &tty_original);
+
+    /* exit() is not async-signal safe, but _exit() is.
+     * Use the common idiom of 128 + signal number for signal exits.
+     * Alternative approach is to reset the signal to default handler,
+     * and immediately raise() it. */
+    _exit(128 + signum);
+}
+
+/* Initialize terminal for non-canonical, non-echo mode,
+ * that should be compatible with standard C I/O.
+ * Returns 0 if success, nonzero errno otherwise.
+*/
+libedit_private int
+tty_save(void)
+{
+    struct sigaction act;
+
+    /* Already initialized? */
+    if (tty_descriptor != -1)
+        return errno = 0;
+
+    /* Which standard stream is connected to our TTY? */
+    if (isatty(STDERR_FILENO))
+        tty_descriptor = STDERR_FILENO;
+    else
+    if (isatty(STDIN_FILENO))
+        tty_descriptor = STDIN_FILENO;
+    else
+    if (isatty(STDOUT_FILENO))
+        tty_descriptor = STDOUT_FILENO;
+    else
+        return errno = ENOTTY;
+
+    /* Obtain terminal settings. */
+    if (tcgetattr(tty_descriptor, &tty_original) ||
+        tcgetattr(tty_descriptor, &tty_settings))
+        return errno = ENOTSUP;
+
+    /* Disable buffering for terminal streams. */
+    /*
+    if (isatty(STDIN_FILENO))
+        setvbuf(stdin, NULL, _IONBF, 0);
+    if (isatty(STDOUT_FILENO))
+        setvbuf(stdout, NULL, _IONBF, 0);
+    if (isatty(STDERR_FILENO))
+        setvbuf(stderr, NULL, _IONBF, 0);
+    */
+
+    /* At exit() or return from main(),
+     * restore the original settings. */
+    if (atexit(tty_restore))
+        return errno = ENOTSUP;
+
+    /* Set new "default" handlers for typical signals,
+     * so that if this process is killed by a signal,
+     * the terminal settings will still be restored first. */
+    sigemptyset(&act.sa_mask);
+    act.sa_handler = tty_signal;
+    act.sa_flags = 0;
+    if (sigaction(SIGHUP,  &act, NULL) ||
+        sigaction(SIGINT,  &act, NULL) ||
+        sigaction(SIGQUIT, &act, NULL) ||
+        sigaction(SIGTERM, &act, NULL) ||
+#ifdef SIGXCPU
+        sigaction(SIGXCPU, &act, NULL) ||
+#endif
+#ifdef SIGXFSZ
+        sigaction(SIGXFSZ, &act, NULL) ||
+#endif
+#ifdef SIGIO
+        sigaction(SIGIO,   &act, NULL) ||
+#endif
+        sigaction(SIGPIPE, &act, NULL) ||
+        sigaction(SIGALRM, &act, NULL) ||
+        sigaction(SIGSEGV, &act, NULL) ||
+        sigaction(SIGABRT, &act, NULL))
+      return errno = ENOTSUP;
+
+    /* Let BREAK cause a SIGINT in input. */
+    /*
+    tty_settings.c_iflag &= ~IGNBRK;
+    tty_settings.c_iflag |=  BRKINT;
+    */
+
+    /* Ignore framing and parity errors in input. */
+    /*
+    tty_settings.c_iflag |=  IGNPAR;
+    tty_settings.c_iflag &= ~PARMRK;
+    */
+
+    /* Do not strip eighth bit on input. */
+    /*
+    tty_settings.c_iflag &= ~ISTRIP;
+    */
+
+    /* Do not do newline translation on input. */
+    /*
+    tty_settings.c_iflag &= ~(INLCR | IGNCR | ICRNL);
+    */
+
+#ifdef IUCLC
+    /* Do not do uppercase-to-lowercase mapping on input. */
+    tty_settings.c_iflag &= ~IUCLC;
+#endif
+
+    /* Use 8-bit characters. This too may affect standard streams,
+     * but any sane C library can deal with 8-bit characters. */
+    tty_settings.c_cflag &= ~CSIZE;
+    tty_settings.c_cflag |=  CS8;
+    tty_settings.c_cflag |=  IUTF8;
+
+    /* Enable receiver. */
+    /*
+    tty_settings.c_cflag |=  CREAD;
+    */
+
+    /* Let INTR/QUIT/SUSP/DSUSP generate the corresponding signals. */
+    tty_settings.c_lflag |=  ISIG;
+
+    /* Enable noncanonical mode.
+     * This is the most important bit, as it disables line buffering etc. */
+    /*
+    tty_settings.c_lflag &= ~ICANON;
+    */
+
+    /* Enable echoing input characters. */
+    /*
+    tty_settings.c_lflag |= (ECHO | ECHOE | ECHOK | ECHONL);
+    */
+
+    /* Disable echoing input characters. */
+    /*
+    tty_settings.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
+    */
+
+    /* Disable implementation-defined input processing. */
+    /*
+    tty_settings.c_lflag &= ~IEXTEN;
+    */
+
+    /* To maintain best compatibility with normal behaviour of terminals,
+     * we set TIME=0 and MAX=1 in noncanonical mode. This means that
+     * read() will block until at least one byte is available. */
+    /*
+    tty_settings.c_cc[VTIME] = 0;
+    tty_settings.c_cc[VMIN] = 1;
+    */
+
+    /* Set the new terminal settings.
+     * Note that we don't actually check which ones were successfully
+     * set and which not, because there isn't much we can do about it. */
+    tcsetattr(tty_descriptor, TCSANOW, &tty_settings);
+
+    /* Done. */
+    return errno = 0;
+}
+
 /* tty_getty():
  *	Wrapper for tcgetattr to handle EINTR
  */
diff --git a/src/tty.h b/src/tty.h
index 2603e1ad2d..331a507a26 100644
--- a/src/tty.h
+++ b/src/tty.h
@@ -456,6 +456,7 @@ typedef struct {

 typedef unsigned char ttychar_t[NN_IO][C_NCC];

+libedit_private int	tty_save();
 libedit_private int	tty_init(EditLine *);
 libedit_private void	tty_end(EditLine *);
 libedit_private int	tty_stty(EditLine *, int, const wchar_t **);

>Release-Note:

>Audit-Trail:
From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: lib/52517: TTY settings modified and not restored on exit.
Date: Fri, 1 Sep 2017 03:35:12 -0400

 On Aug 31,  9:50pm, jhdub23@gmail.com (jhdub23@gmail.com) wrote:
 -- Subject: lib/52517: TTY settings modified and not restored on exit.

 | >Number:         52517
 | >Category:       lib
 | >Synopsis:       TTY settings modified and not restored on exit.
 | >Confidential:   no
 | >Severity:       non-critical
 | >Priority:       medium
 | >Responsible:    lib-bug-people
 | >State:          open
 | >Class:          sw-bug
 | >Submitter-Id:   net
 | >Arrival-Date:   Thu Aug 31 21:50:00 +0000 2017
 | >Originator:     Jay West
 | >Release:        libedit (NetBSD-current)
 | >Organization:
 | Self
 | >Environment:
 | Linux [deleted] 2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
 | >Description:
 | libedit modifies TTY settings when used, and does not have a mechanism to fully save and restore TTY settings.  This causes problems when libedit is used as a GNU readline replacement.
 | 
 | Specifically, after running python+GnuReadline, TTY settings are untouched after python exits.  However, python+libedit has noticeable TTY changes after python exits.
 | 
 | This will be true for any application linked against libedit instead of GnuReadline.
 | >How-To-Repeat:
 | % stty -a > orig.txt
 | % python # Run python compiled with libedit, and immediately exit (or any application using libedit).
 | % stty -a > after.txt
 | % diff orig.txt after.txt  # Differences exist
 | 


 Can you provide a small program that calls readline and reproduces this?

 christos

From: Jay West <jhdub23@gmail.com>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: lib/52517: TTY settings modified and not restored on exit.
Date: Tue, 5 Sep 2017 09:47:42 -0700

 --001a113dbbea72c120055873fce9
 Content-Type: text/plain; charset="UTF-8"

 I couldn't find a way to update the bug report directly, so I'm replying by
 email.  Please let me know if there is a better way.

 The before/after tty settings differences only appear if your original
 settings are different from libedit's defaults.  It turns out that the
 differences do not show up with xterm (in my environment).  The changes are
 very noticeable when running an emacs shell.  I've modified the test to
 highlight the issue regardless of default shell tty settings.

 Jay

 /*---------------------------------------
 * Simple program: tty_test.c
 *---------------------------------------*/
 #include "editline/readline.h"

 int main(int argc, char* argv[]) {
   rl_initialize();
   return 0;
 }

 /*---------------------------------------
 * Compile
 *---------------------------------------*/
 % gcc -o tty_test -Ilibedit_install/include tty_test.c
 libedit_install/lib/libedit.a -lncurses

 /*----------------------------------------
 * Modified test:
 *----------------------------------------*/
 % stty -icanon # Force tty settings to be different from libedit default.
 % stty -a > orig.txt
 % tty_test
 % stty -a > after.txt
 % diff orig.txt after.txt  # Differences exist


 On Fri, Sep 1, 2017 at 12:40 AM, Christos Zoulas <christos@zoulas.com>
 wrote:

 > The following reply was made to PR lib/52517; it has been noted by GNATS.
 >
 > From: christos@zoulas.com (Christos Zoulas)
 > To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org,
 >         gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
 > Cc:
 > Subject: Re: lib/52517: TTY settings modified and not restored on exit.
 > Date: Fri, 1 Sep 2017 03:35:12 -0400
 >
 >  On Aug 31,  9:50pm, jhdub23@gmail.com (jhdub23@gmail.com) wrote:
 >  -- Subject: lib/52517: TTY settings modified and not restored on exit.
 >
 >  | >Number:         52517
 >  | >Category:       lib
 >  | >Synopsis:       TTY settings modified and not restored on exit.
 >  | >Confidential:   no
 >  | >Severity:       non-critical
 >  | >Priority:       medium
 >  | >Responsible:    lib-bug-people
 >  | >State:          open
 >  | >Class:          sw-bug
 >  | >Submitter-Id:   net
 >  | >Arrival-Date:   Thu Aug 31 21:50:00 +0000 2017
 >  | >Originator:     Jay West
 >  | >Release:        libedit (NetBSD-current)
 >  | >Organization:
 >  | Self
 >  | >Environment:
 >  | Linux [deleted] 2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:22
 > UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
 >  | >Description:
 >  | libedit modifies TTY settings when used, and does not have a mechanism
 > to fully save and restore TTY settings.  This causes problems when libedit
 > is used as a GNU readline replacement.
 >  |
 >  | Specifically, after running python+GnuReadline, TTY settings are
 > untouched after python exits.  However, python+libedit has noticeable TTY
 > changes after python exits.
 >  |
 >  | This will be true for any application linked against libedit instead of
 > GnuReadline.
 >  | >How-To-Repeat:
 >  | % stty -a > orig.txt
 >  | % python # Run python compiled with libedit, and immediately exit (or
 > any application using libedit).
 >  | % stty -a > after.txt
 >  | % diff orig.txt after.txt  # Differences exist
 >  |
 >
 >
 >  Can you provide a small program that calls readline and reproduces this?
 >
 >  christos
 >
 >

 --001a113dbbea72c120055873fce9
 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: quoted-printable

 <div dir=3D"ltr">I couldn&#39;t find a way to update the bug report directl=
 y, so I&#39;m replying by email.=C2=A0 Please let me know if there is a bet=
 ter way.<div><br></div><div>The before/after tty settings differences only =
 appear if your original settings are different from libedit&#39;s defaults.=
 =C2=A0 It turns out that the differences do not show up with xterm (in my e=
 nvironment).=C2=A0 The changes are very noticeable when running an emacs sh=
 ell.=C2=A0 I&#39;ve modified the test to highlight the issue regardless of =
 default shell tty settings.</div><div><br></div><div>Jay</div><div><div><br=
 ></div><div>/*----------------------------<wbr>-----------<br></div><div>* =
 Simple program: tty_test.c</div><div>*-----------------------------<wbr>---=
 -------*/</div><div><div>#include &quot;editline/readline.h&quot;</div><div=
 ><br></div><div>int main(int argc, char* argv[]) {</div><div>=C2=A0 rl_init=
 ialize();</div><div>=C2=A0 return 0;</div><div>}</div></div><div><br></div>=
 <div><div>/*----------------------------<wbr>-----------<br></div><div>* Co=
 mpile</div><div>*-----------------------------<wbr>----------*/</div></div>=
 <div>% gcc -o tty_test -Ilibedit_install/include tty_test.c libedit_install=
 /lib/libedit.a -lncurses<br></div><div><br></div><div>/*-------------------=
 ---------<wbr>------------<br></div><div>* Modified test:=C2=A0</div><div>*=
 -----------------------------<wbr>-----------*/<br></div><div>% stty -icano=
 n # Force tty settings to be different from libedit default.</div><div>% st=
 ty -a &gt; orig.txt</div><div>% tty_test</div><div>% stty -a &gt; after.txt=
 </div><div>%=C2=A0<span style=3D"font-size:12.8px">diff orig.txt after.txt=
 =C2=A0 # Differences exist</span></div><div><span style=3D"font-size:12.8px=
 "><br></span></div></div></div><div class=3D"gmail_extra"><br><div class=3D=
 "gmail_quote">On Fri, Sep 1, 2017 at 12:40 AM, Christos Zoulas <span dir=3D=
 "ltr">&lt;<a href=3D"mailto:christos@zoulas.com" target=3D"_blank">christos=
 @zoulas.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" styl=
 e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The fol=
 lowing reply was made to PR lib/52517; it has been noted by GNATS.<br>
 <br>
 From: <a href=3D"mailto:christos@zoulas.com">christos@zoulas.com</a> (Chris=
 tos Zoulas)<br>
 To: gnats-bugs@NetBSD.org, <a href=3D"mailto:lib-bug-people@netbsd.org">lib=
 -bug-people@netbsd.org</a>,<br>
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 <a href=3D"mailto:gnats-admin@netbsd.org">gnats=
 -admin@netbsd.org</a>, <a href=3D"mailto:netbsd-bugs@netbsd.org">netbsd-bug=
 s@netbsd.org</a><br>
 Cc:<br>
 Subject: Re: lib/52517: TTY settings modified and not restored on exit.<br>
 Date: Fri, 1 Sep 2017 03:35:12 -0400<br>
 <br>
 =C2=A0On Aug 31,=C2=A0 9:50pm, <a href=3D"mailto:jhdub23@gmail.com">jhdub23=
 @gmail.com</a> (<a href=3D"mailto:jhdub23@gmail.com">jhdub23@gmail.com</a>)=
  wrote:<br>
 =C2=A0-- Subject: lib/52517: TTY settings modified and not restored on exit=
 .<br>
 <br>
 =C2=A0| &gt;Number:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A052517<br>
 =C2=A0| &gt;Category:=C2=A0 =C2=A0 =C2=A0 =C2=A0lib<br>
 <span class=3D"">=C2=A0| &gt;Synopsis:=C2=A0 =C2=A0 =C2=A0 =C2=A0TTY settin=
 gs modified and not restored on exit.<br>
 </span>=C2=A0| &gt;Confidential:=C2=A0 =C2=A0no<br>
 =C2=A0| &gt;Severity:=C2=A0 =C2=A0 =C2=A0 =C2=A0non-critical<br>
 =C2=A0| &gt;Priority:=C2=A0 =C2=A0 =C2=A0 =C2=A0medium<br>
 =C2=A0| &gt;Responsible:=C2=A0 =C2=A0 lib-bug-people<br>
 =C2=A0| &gt;State:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 open<br>
 =C2=A0| &gt;Class:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 sw-bug<br>
 =C2=A0| &gt;Submitter-Id:=C2=A0 =C2=A0net<br>
 <span class=3D"">=C2=A0| &gt;Arrival-Date:=C2=A0 =C2=A0Thu Aug 31 21:50:00 =
 +0000 2017<br>
 </span>=C2=A0| &gt;Originator:=C2=A0 =C2=A0 =C2=A0Jay West<br>
 =C2=A0| &gt;Release:=C2=A0 =C2=A0 =C2=A0 =C2=A0 libedit (NetBSD-current)<br=
 >
 =C2=A0| &gt;Organization:<br>
 =C2=A0| Self<br>
 =C2=A0| &gt;Environment:<br>
 =C2=A0| Linux [deleted] 2.6.32-696.6.3.el6.x86_64 #1 SMP Wed Jul 12 14:17:2=
 2 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux<br>
 =C2=A0| &gt;Description:<br>
 =C2=A0| libedit modifies TTY settings when used, and does not have a mechan=
 ism to fully save and restore TTY settings.=C2=A0 This causes problems when=
  libedit is used as a GNU readline replacement.<br>
 =C2=A0|<br>
 =C2=A0| Specifically, after running python+GnuReadline, TTY settings are un=
 touched after python exits.=C2=A0 However, python+libedit has noticeable TT=
 Y changes after python exits.<br>
 =C2=A0|<br>
 =C2=A0| This will be true for any application linked against libedit instea=
 d of GnuReadline.<br>
 =C2=A0| &gt;How-To-Repeat:<br>
 =C2=A0| % stty -a &gt; orig.txt<br>
 =C2=A0| % python # Run python compiled with libedit, and immediately exit (=
 or any application using libedit).<br>
 =C2=A0| % stty -a &gt; after.txt<br>
 =C2=A0| % diff orig.txt after.txt=C2=A0 # Differences exist<br>
 =C2=A0|<br>
 <br>
 <br>
 =C2=A0Can you provide a small program that calls readline and reproduces th=
 is?<br>
 <span class=3D"HOEnZb"><font color=3D"#888888"><br>
 =C2=A0christos<br>
 <br>
 </font></span></blockquote></div><br></div>

 --001a113dbbea72c120055873fce9--

From: Jay West <jhdub23@gmail.com>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: lib/52517: TTY settings modified and not restored on exit.
Date: Tue, 5 Sep 2017 10:00:35 -0700

 Resending in plain text mode:

 I couldn't find a way to update the bug report directly, so I'm
 replying by email.  Please let me know if there is a better way.

 The before/after tty settings differences only appear if your original
 settings are different from libedit's defaults.  It turns out that the
 differences do not show up with xterm (in my environment).  The
 changes are very noticeable when running an emacs shell.  I've
 modified the test to highlight the issue regardless of default shell
 tty settings.

 Jay

 /*---------------------------------------
 * Simple program: tty_test.c
 *---------------------------------------*/
 #include "editline/readline.h"

 int main(int argc, char* argv[]) {
   rl_initialize();
   return 0;
 }

 /*---------------------------------------
 * Compile
 *---------------------------------------*/
 % gcc -o tty_test -Ilibedit_install/include tty_test.c
 libedit_install/lib/libedit.a -lncurses

 /*----------------------------------------
 * Modified test:
 *----------------------------------------*/
 % stty -icanon # Force tty settings to be different from libedit default.
 % stty -a > orig.txt
 % tty_test
 % stty -a > after.txt
 % diff orig.txt after.txt  # Differences exist

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, lib-bug-people@netbsd.org, 
	gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, jhdub23@gmail.com
Cc: 
Subject: Re: lib/52517: TTY settings modified and not restored on exit.
Date: Tue, 5 Sep 2017 14:36:55 -0400

 On Sep 5,  5:05pm, jhdub23@gmail.com (Jay West) wrote:
 -- Subject: Re: lib/52517: TTY settings modified and not restored on exit.

 Thanks, I've committed a fix.

 christos

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Mon, 04 Jun 2018 10:58:27 +0000
State-Changed-Why:
COmmitted by christos who referenced the wrong PR. Thanks for the report & patch!

Module Name:    src
Committed By:   christos
Date:           Fri Sep  1 10:19:10 UTC 2017

Modified Files:
        src/lib/libedit: editline.3 hist.h histedit.h history.c readline.c
        src/lib/libedit/readline: readline.h

Log Message:
PR/51517: Jay West: Tty settings not restored on exit
PR/51518: Jay West: prompt is interleaved with client output

Both these issues are caused by rl_restore_handler not DTRT; fix
it so that it kills the internal libedit state completely. This is
inefficient, but it works.

Also fix:
1. add append_history()/H_NSAVE_FP
2. call the rl_startup_hook before printing the first prompt as documented.
   callint it from rl_initialize breaks python, because the callback ends
   up being invoked before the readline module is installed, and we end up
   dereferencing a NULL pointer.

3. add el_resize_terminal.                                                                  

With those changes, s/lreadline/ledit/g in python works.                                    


To generate a diff of this commit:                                                          
cvs rdiff -u -r1.96 -r1.97 src/lib/libedit/editline.3                                       
cvs rdiff -u -r1.22 -r1.23 src/lib/libedit/hist.h                                           
cvs rdiff -u -r1.56 -r1.57 src/lib/libedit/histedit.h                                       
cvs rdiff -u -r1.57 -r1.58 src/lib/libedit/history.c                                        
cvs rdiff -u -r1.141 -r1.142 src/lib/libedit/readline.c                                     
cvs rdiff -u -r1.41 -r1.42 src/lib/libedit/readline/readline.h                              



>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.