Package: ncurses-bin
Version: 6.3+20220423-2
Followup-For: Bug #60377
Control: tags -1 patch
Control: tags -1 patch

Dear Maintainer,

This is still a problem. It causes my VT340 serial terminal to hang,
but not immediately. It happens the next time a program tries to open
/dev/ttyUSB0, for example, getty after logging out. I presume this
hasn't been fixed because the bug only affects hardware terminals that
lack a carrier detect line (such as any DEC terminal connected via
DEC423 MMJ).

If anything, clocal ought to be asserted by default, not disabled.
However, I suggest that `reset` should do neither. The man page for
reset is clear on what it does and it does not mention clocal. I have
attached a patch which brings the program back into line with its
documentation.

Thank you,

--Ben



-- System Information:
Debian Release: bookworm/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 6.0.0-4-amd64 (SMP w/8 CPU threads; PREEMPT)
Kernel taint flags: TAINT_SOFTLOCKUP
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages ncurses-bin depends on:
ii  libc6      2.36-6
ii  libtinfo6  6.3+20220423-2

ncurses-bin recommends no packages.

ncurses-bin suggests no packages.

-- no debconf information
--- reset_cmd.c.orig    2021-10-02 11:08:44.000000000 -0700
+++ reset_cmd.c 2022-11-22 16:00:29.005361817 -0800
@@ -190,13 +190,14 @@
 
 /*
  * Reset the terminal mode bits to a sensible state.  Very useful after
- * a child program dies in raw mode.
+ * a child program dies in raw mode. Requires termios(3) to work. 
  */
 void
 reset_tty_settings(int fd, TTY * tty_settings, int noset)
 {
     GET_TTY(fd, tty_settings);
 
+     /* First reset any special characters to their default values */
 #ifdef TERMIOS
 #if defined(VDISCARD) && defined(CDISCARD)
     reset_char(VDISCARD, CDISCARD);
@@ -228,94 +229,38 @@
     reset_char(VWERASE, CWERASE);
 #endif
 
-    tty_settings->c_iflag &= ~((unsigned) (IGNBRK
-                                          | PARMRK
-                                          | INPCK
-                                          | ISTRIP
-                                          | INLCR
-                                          | IGNCR
-#ifdef IUCLC
-                                          | IUCLC
-#endif
-#ifdef IXANY
-                                          | IXANY
-#endif
-                                          | IXOFF));
 
+    /* Next, the reset command does the following
+     *
+     *   sets cooked and echo modes,
+     *   turns off cbreak and raw modes and
+     *   turns on newline translation on output.
+     *
+     * It does not mess with other settings, such as IXOFF and CLOCAL,
+     * as the correct values depend upon what type of terminal (and
+     * even what type of serial cable) is being used.
+     *
+     * Users who need a blunter instrument can try `stty sane` which
+     * makes presumptions about a "typical" setup.
+     */
+
+    /* "Cooked" means: brkint ignpar istrip icrnl ixon opost isig icanon */
+    /* Setting cooked automatically turns off "raw" and "cbreak" */  
     tty_settings->c_iflag |= (BRKINT
-                             | IGNPAR
-                             | ICRNL
-                             | IXON
-#ifdef IMAXBEL
-                             | IMAXBEL
-#endif
-       );
+                              | IGNPAR
+                              | ISTRIP
+                              | ICRNL            /* Input maps CR to NL */
+                              | IXON);
 
-    tty_settings->c_oflag &= ~((unsigned) (0
-#ifdef OLCUC
-                                          | OLCUC
-#endif
-#ifdef OCRNL
-                                          | OCRNL
-#endif
-#ifdef ONOCR
-                                          | ONOCR
-#endif
-#ifdef ONLRET
-                                          | ONLRET
-#endif
-#ifdef OFILL
-                                          | OFILL
-#endif
-#ifdef OFDEL
-                                          | OFDEL
-#endif
-#ifdef NLDLY
-                                          | NLDLY
-#endif
-#ifdef CRDLY
-                                          | CRDLY
-#endif
-#ifdef TABDLY
-                                          | TABDLY
-#endif
-#ifdef BSDLY
-                                          | BSDLY
-#endif
-#ifdef VTDLY
-                                          | VTDLY
-#endif
-#ifdef FFDLY
-                                          | FFDLY
-#endif
-                              ));
+    tty_settings->c_iflag &= ~(INLCR);   /* Input does not map NL to CR */
 
     tty_settings->c_oflag |= (OPOST
 #ifdef ONLCR
-                             | ONLCR
+                              | ONLCR        /* Output maps NL to CR-NL */
 #endif
-       );
+        );
 
-    tty_settings->c_cflag &= ~((unsigned) (CSIZE
-                                          | CSTOPB
-                                          | PARENB
-                                          | PARODD
-                                          | CLOCAL));
-    tty_settings->c_cflag |= (CS8 | CREAD);
-    tty_settings->c_lflag &= ~((unsigned) (ECHONL
-                                          | NOFLSH
-#ifdef TOSTOP
-                                          | TOSTOP
-#endif
-#ifdef ECHOPTR
-                                          | ECHOPRT
-#endif
-#ifdef XCASE
-                                          | XCASE
-#endif
-                              ));
-
-    tty_settings->c_lflag |= (ISIG
+    tty_settings->c_lflag |= (ISIG         /* Generate signal on ^C, ^Z, etc  
*/
                              | ICANON
                              | ECHO
                              | ECHOE
@@ -327,7 +272,7 @@
                              | ECHOKE
 #endif
        );
-#endif
+#endif /* Matches #ifdef TERMIOS */
 
     if (!noset) {
        SET_TTY(fd, tty_settings);

Reply via email to