Re: install/54932: A green message overwrite part of screen in sysinst on laptop
"Andreas Gustafsson via gnats" <[email protected]>
| Newsgroups | gmane.os.netbsd.bugs |
|---|---|
| Message-ID | <[email protected]> |
The following reply was made to PR install/54932; it has been noted by GNATS. From: Andreas Gustafsson <[email protected]> To: [email protected] Cc: Subject: Re: install/54932: A green message overwrite part of screen in sysinst on laptop Date: Sat, 27 Jun 2026 15:07:20 +0300 A few weeks ago, I wrote: > Sysinst already intercepts kernel messages using TIOCCONS, but only while > running external commands. It should intercept them at all times. I propose the following patch. Index: src/usr.sbin/sysinst/defs.h =================================================================== RCS file: /cvsroot/src/usr.sbin/sysinst/defs.h,v retrieving revision 1.95 diff -u -r1.95 defs.h --- src/usr.sbin/sysinst/defs.h 26 Apr 2026 13:31:47 -0000 1.95 +++ src/usr.sbin/sysinst/defs.h 15 Jun 2026 16:21:19 -0000 @@ -919,6 +919,8 @@ struct disk_partitions*); void free_install_desc(struct install_partition_desc*); bool may_swap_if_not_sdmmc(const char*); +void redirect_console(int, int); +void discard_console_output(void); /* from target.c */ #if defined(DEBUG) || defined(DEBUG_ROOT) Index: src/usr.sbin/sysinst/main.c =================================================================== RCS file: /cvsroot/src/usr.sbin/sysinst/main.c,v retrieving revision 1.36 diff -u -r1.36 main.c --- src/usr.sbin/sysinst/main.c 26 Apr 2026 13:31:47 -0000 1.36 +++ src/usr.sbin/sysinst/main.c 15 Jun 2026 16:21:19 -0000 @@ -274,6 +274,9 @@ no_https = 1; } + /* Prevent kernel conole messages from messing up the display */ + discard_console_output(); + /* initialize message window */ if (menu_init()) { __menu_initerror(); Index: src/usr.sbin/sysinst/run.c =================================================================== RCS file: /cvsroot/src/usr.sbin/sysinst/run.c,v retrieving revision 1.16 diff -u -r1.16 run.c --- src/usr.sbin/sysinst/run.c 4 Oct 2024 15:11:09 -0000 1.16 +++ src/usr.sbin/sysinst/run.c 15 Jun 2026 16:21:19 -0000 @@ -419,7 +419,6 @@ char *cp, *ncp; struct termios rtt, tt; struct timeval tmo; - static int do_tioccons = 2; (void)tcgetattr(STDIN_FILENO, &tt); if (openpty(&master, &slave, NULL, &tt, win) == -1) { @@ -433,20 +432,7 @@ ttysig_ignore = 1; ioctl(master, TIOCPKT, &ttysig_ignore); - /* Try to get console output into our pipe */ - if (do_tioccons) { - if (ioctl(slave, TIOCCONS, &do_tioccons) == 0 - && do_tioccons == 2) { - /* test our output - we don't want it grabbed */ - write(1, " \b", 2); - ioctl(master, FIONREAD, &do_tioccons); - if (do_tioccons != 0) { - do_tioccons = 0; - ioctl(slave, TIOCCONS, &do_tioccons); - } else - do_tioccons = 1; - } - } + redirect_console(master, slave); if (logfp) fflush(logfp); @@ -589,6 +575,7 @@ } close(master); close(slave); + discard_console_output(); if (logfp) fflush(logfp); Index: src/usr.sbin/sysinst/util.c =================================================================== RCS file: /cvsroot/src/usr.sbin/sysinst/util.c,v retrieving revision 1.78 diff -u -r1.78 util.c --- src/usr.sbin/sysinst/util.c 5 Aug 2025 14:52:43 -0000 1.78 +++ src/usr.sbin/sysinst/util.c 15 Jun 2026 16:21:20 -0000 @@ -193,6 +193,8 @@ programs available on install media */ int have_raid, have_vnd, have_cgd, have_lvm, have_gpt, have_dk; +int console_tty = -1; /* tty where console is currently redirected */ + /* * local prototypes */ @@ -2682,3 +2684,48 @@ return strncmp(parent, "sdmmc", 5) != 0; } #endif + +/* + * Redirect console output to the pty associated with master/slave + */ +void +redirect_console(int master, int slave) { + static int do_tioccons = 2; + /* Try to get console output into our pipe */ + if (do_tioccons) { + /* Turn off any existing console redirection */ + if (console_tty != -1) { + int off = 0; + ioctl(console_tty, TIOCCONS, &off); + console_tty = -1; + } + if (ioctl(slave, TIOCCONS, &do_tioccons) == 0) { + console_tty = slave; + if (do_tioccons == 2) { + /* test our output - we don't want it grabbed */ + write(1, " \b", 2); + ioctl(master, FIONREAD, &do_tioccons); + if (do_tioccons != 0) { + do_tioccons = 0; + ioctl(slave, TIOCCONS, &do_tioccons); + console_tty = -1; + } else + do_tioccons = 1; + } + } + } +} + +/* + * Redirect console output to nowhere + */ +void +discard_console_output(void) { + static int master = -1, slave = -1; + if (slave == -1) + /* Return value ignored */ + openpty(&master, &slave, NULL, NULL, NULL); + if (slave == -1) + return; + redirect_console(master, slave); +}