diff options
author | cperciva <cperciva@FreeBSD.org> | 2004-01-22 21:01:14 +0000 |
---|---|---|
committer | cperciva <cperciva@FreeBSD.org> | 2004-01-22 21:01:14 +0000 |
commit | 1fdea8077aa73fac8d966ce74ffe7910dc163efb (patch) | |
tree | ec798441a32d8b0ddc532a4f76045411734cdfbc /usr.bin/script | |
parent | 92bbd9c60a7606aa605c857452e675c01cd6f75c (diff) | |
download | FreeBSD-src-1fdea8077aa73fac8d966ce74ffe7910dc163efb.zip FreeBSD-src-1fdea8077aa73fac8d966ce74ffe7910dc163efb.tar.gz |
Two fixes for script(1):
1. Don't do tty stuff to stdin if stdin isn't a tty.
2. When running in non-interactive mode, don't select(2)
on the standard input.
This un-breaks non-interactive portupgrade.
PR: bin/59036 [1]
PR: bin/56166, bin/57414, ports/57415, ports/60534 [2]
MFC after: 7 days
Approved by: rwatson (mentor)
Diffstat (limited to 'usr.bin/script')
-rw-r--r-- | usr.bin/script/script.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 25c5bdc..339439e 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -67,7 +67,7 @@ FILE *fscript; int master, slave; int child; const char *fname; -int qflg; +int qflg, ttyflg; struct termios tt; @@ -126,10 +126,17 @@ main(int argc, char *argv[]) if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL) err(1, "%s", fname); - (void)tcgetattr(STDIN_FILENO, &tt); - (void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win); - if (openpty(&master, &slave, NULL, &tt, &win) == -1) - err(1, "openpty"); + if (ttyflg = isatty(STDIN_FILENO)) { + 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) + err(1, "openpty"); + } else { + if (openpty(&master, &slave, NULL, NULL, NULL) == -1) + err(1, "openpty"); + } if (!qflg) { tvec = time(NULL); @@ -137,10 +144,12 @@ main(int argc, char *argv[]) (void)fprintf(fscript, "Script started on %s", ctime(&tvec)); fflush(fscript); } - rtt = tt; - cfmakeraw(&rtt); - rtt.c_lflag &= ~ECHO; - (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt); + if (ttyflg) { + rtt = tt; + cfmakeraw(&rtt); + rtt.c_lflag &= ~ECHO; + (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &rtt); + } child = fork(); if (child < 0) { @@ -159,7 +168,8 @@ main(int argc, char *argv[]) FD_ZERO(&rfd); for (;;) { FD_SET(master, &rfd); - FD_SET(STDIN_FILENO, &rfd); + if (argv[0] == NULL) + FD_SET(STDIN_FILENO, &rfd); if (flushtime > 0) { tv.tv_sec = flushtime; tv.tv_usec = 0; @@ -260,7 +270,8 @@ done(int eno) { time_t tvec; - (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt); + if (ttyflg) + (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt); tvec = time(NULL); if (!qflg) { (void)fprintf(fscript,"\nScript done on %s", ctime(&tvec)); |