From 1eba6a9de6af1c3c82049760210f031318f6871f Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 14 Aug 2020 00:55:23 +0000 Subject: [PATCH] MFC r364039: script: Put the terminal in raw mode when playing back a session. PR: 248377 --- usr.bin/script/script.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index d05bd3d6040..8d22ea4251e 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -427,6 +427,33 @@ consume(FILE *fp, off_t len, char *buf, int reg) } \ } while (0/*CONSTCOND*/) +static void +termset(void) +{ + struct termios traw; + + if (tcgetattr(STDOUT_FILENO, &tt) == -1) { + if (errno == EBADF) + err(1, "%d not valid fd", STDOUT_FILENO); + /* errno == ENOTTY */ + return; + } + ttyflg = 1; + traw = tt; + cfmakeraw(&traw); + traw.c_lflag |= ISIG; + (void)tcsetattr(STDOUT_FILENO, TCSANOW, &traw); +} + +static void +termreset(void) +{ + if (ttyflg) { + tcsetattr(STDOUT_FILENO, TCSADRAIN, &tt); + ttyflg = 0; + } +} + static void playback(FILE *fp) { @@ -470,8 +497,11 @@ playback(FILE *fp) ctime(&tclock)); tsi = tso; (void)consume(fp, stamp.scr_len, buf, reg); + termset(); + atexit(termreset); break; case 'e': + termreset(); if (!qflg) (void)printf("\nScript done on %s", ctime(&tclock)); -- 2.45.0