git: 7041245be62b - stable/13 - kboot: Make console raw when we start

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:11:41 UTC
The branch stable/13 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=7041245be62b9760a3bf8103935bb6f0d9561343

commit 7041245be62b9760a3bf8103935bb6f0d9561343
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-07-26 23:39:45 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:29 +0000

    kboot: Make console raw when we start
    
    Put the console into raw mode on startup. This allows the menus to work
    as expected. Boot is now interruptable.
    
    Note: Likely should restore the terminal settings on most exists.  It's
    not clear the best way to do this, and most shells have an auto stty
    sane anyway, so note it for future improvement.
    
    Sponsored by:           Netflix
    
    (cherry picked from commit 9579540144880e0a612ec2fdfc66de46c08d28d6)
---
 stand/kboot/hostcons.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/stand/kboot/hostcons.c b/stand/kboot/hostcons.c
index 31dceb019973..80d4a1c4319b 100644
--- a/stand/kboot/hostcons.c
+++ b/stand/kboot/hostcons.c
@@ -29,6 +29,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/types.h>
 #include "bootstrap.h"
 #include "host_syscall.h"
+#include "termios.h"
 
 static void hostcons_probe(struct console *cp);
 static int hostcons_init(int arg);
@@ -47,6 +48,8 @@ struct console hostconsole = {
 	hostcons_poll,
 };
 
+static struct host_termios old_settings;
+
 static void
 hostcons_probe(struct console *cp)
 {
@@ -57,9 +60,12 @@ hostcons_probe(struct console *cp)
 static int
 hostcons_init(int arg)
 {
+	struct host_termios new_settings;
 
-	/* XXX: set nonblocking */
-	/* tcsetattr(~(ICANON | ECHO)) */
+	host_tcgetattr(0, &old_settings);
+	new_settings = old_settings;
+	host_cfmakeraw(&new_settings);
+	host_tcsetattr(0, HOST_TCSANOW, &new_settings);
 
 	return (0);
 }
@@ -94,4 +100,3 @@ hostcons_poll()
 	ret = host_select(32, &fds, NULL, NULL, &tv);
 	return (ret > 0);
 }
-