aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2020-08-11 14:19:05 +0000
committerMark Johnston <markj@FreeBSD.org>2020-08-11 14:19:05 +0000
commit8bc30d2afda0dae4b708b298c6b1e9d8ec2b8a7d (patch)
treecefdb751b3b0523174de454d3eb3c04cffefc0c2
parent74d3a63559e0ab55db91e8a67171917a4f0fb3ea (diff)
downloadsrc-8bc30d2afda0dae4b708b298c6b1e9d8ec2b8a7d.tar.gz
src-8bc30d2afda0dae4b708b298c6b1e9d8ec2b8a7d.zip
script: Minor cleanups.
- Instead of using isatty() to decide whether to call tcgetattr(), just call tcgetattr() directly, since that's all that isatty() does anyway. - Simplify error handling in termset(). Check for errno != ENOTTY from tcgetattr() to handle errors that may be raised while running script(1) under a debugger. PR: 248377 Submitted by: Soumendra Ganguly <soumendraganguly@gmail.com> MFC after: 1 week
Notes
Notes: svn path=/head/; revision=364112
-rw-r--r--usr.bin/script/script.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c
index 8d22ea4251e7..149458baa331 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;