diff options
author | Colin Percival <cperciva@FreeBSD.org> | 2004-02-15 17:30:13 +0000 |
---|---|---|
committer | Colin Percival <cperciva@FreeBSD.org> | 2004-02-15 17:30:13 +0000 |
commit | d6a68195afb81df3adb0eefffea083d219e8035e (patch) | |
tree | 4ce8c64fd19756fb195c1ad97da43d433878f6c0 /usr.bin/script/script.c | |
parent | a20e9655b95f468ced5400abf4797004abeaa593 (diff) | |
download | src-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.c | 4 |
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 && |