aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/script/script.c
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2004-02-15 17:30:13 +0000
committerColin Percival <cperciva@FreeBSD.org>2004-02-15 17:30:13 +0000
commitd6a68195afb81df3adb0eefffea083d219e8035e (patch)
tree4ce8c64fd19756fb195c1ad97da43d433878f6c0 /usr.bin/script/script.c
parenta20e9655b95f468ced5400abf4797004abeaa593 (diff)
downloadsrc-d6a68195afb81df3adb0eefffea083d219e8035e.tar.gz
src-d6a68195afb81df3adb0eefffea083d219e8035e.zip
Attempt #2 to fix script(1) if the standard input is closed: If we
read EOF from STDIN_FILENO, write zero bytes into the pseudo-terminal; this is interpreted as an EOF by the program being scripted. I've tested this with two non-interactive scripts: # echo 5 | script foo sh -c 'read x; sleep $x; echo bar' # echo bar | xargs script foo echo and one interactive program: # script foo more /etc/passwd and everything seems to work properly... PR: bin/56166, bin/57414, ports/57415, ports/60534 Approved by: rwatson (mentor) MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=125848
Diffstat (limited to 'usr.bin/script/script.c')
-rw-r--r--usr.bin/script/script.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c
index 48f026bd9149..ad706dcdd350 100644
--- a/usr.bin/script/script.c
+++ b/usr.bin/script/script.c
@@ -178,8 +178,10 @@ main(int argc, char *argv[])
break;
if (n > 0 && FD_ISSET(STDIN_FILENO, &rfd)) {
cc = read(STDIN_FILENO, ibuf, BUFSIZ);
- if (cc <= 0)
+ if (cc < 0)
break;
+ if (cc == 0)
+ (void)write(master, ibuf, 0);
if (cc > 0) {
(void)write(master, ibuf, cc);
if (kflg && tcgetattr(master, &stt) >= 0 &&