script: Put the terminal in raw mode when playing back a session.

Otherwise recorded sessions of some interactive programs do not play
back properly.

PR:		248377
Submitted by:	Soumendra Ganguly <0.gangzta@gmail.com>
MFC after:	1 week
This commit is contained in:
Mark Johnston 2020-08-07 18:48:56 +00:00
parent c34e4b5c63
commit 69bc4fa916

View File

@ -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));