From e0f3707fd83493a247360e9c811b4705da01c484 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 14 Aug 2020 00:55:48 +0000 Subject: [PATCH] MFC r364112: script: Minor cleanups. PR: 248377 --- usr.bin/script/script.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 8d22ea4251e..149458baa33 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -176,16 +176,16 @@ main(int argc, char *argv[]) if (pflg) playback(fscript); - if ((ttyflg = isatty(STDIN_FILENO)) != 0) { - if (tcgetattr(STDIN_FILENO, &tt) == -1) - err(1, "tcgetattr"); - if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) - err(1, "ioctl"); - if (openpty(&master, &slave, NULL, &tt, &win) == -1) + if (tcgetattr(STDIN_FILENO, &tt) == -1 || + ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) { + if (errno != ENOTTY) /* For debugger. */ + err(1, "tcgetattr/ioctl"); + if (openpty(&master, &slave, NULL, NULL, NULL) == -1) err(1, "openpty"); } else { - if (openpty(&master, &slave, NULL, NULL, NULL) == -1) + if (openpty(&master, &slave, NULL, &tt, &win) == -1) err(1, "openpty"); + ttyflg = 1; } if (rawout) @@ -433,9 +433,8 @@ termset(void) struct termios traw; if (tcgetattr(STDOUT_FILENO, &tt) == -1) { - if (errno == EBADF) - err(1, "%d not valid fd", STDOUT_FILENO); - /* errno == ENOTTY */ + if (errno != ENOTTY) /* For debugger. */ + err(1, "tcgetattr"); return; } ttyflg = 1; -- 2.45.0