diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2020-07-20 18:55:16 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2020-07-20 18:55:16 +0000 |
commit | 79d7c51d638887c3eb7157f2be65ebaab49fe34c (patch) | |
tree | e968107daeeeb2179a9a9fe9afa83e2aac30d39c /usr.bin | |
parent | e6511ff6827474f7567b50e107a187c0936ad1e6 (diff) |
In closeall(), skip stdin and flush std{err,out} instead of closing.
Otherwise awk could fclose(stdin) twice (it may appear more than once)
and closing stderr means awk cannot report errors closing other streams.
OK tim@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/awk/run.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/usr.bin/awk/run.c b/usr.bin/awk/run.c index 4ba6c79eac1..a826182672e 100644 --- a/usr.bin/awk/run.c +++ b/usr.bin/awk/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.63 2020/07/02 19:06:22 millert Exp $ */ +/* $OpenBSD: run.c,v 1.64 2020/07/20 18:55:15 millert Exp $ */ /**************************************************************** Copyright (C) Lucent Technologies 1997 All Rights Reserved @@ -1977,8 +1977,12 @@ void closeall(void) continue; if (ferror(files[i].fp)) FATAL( "i/o error occurred on %s", files[i].fname ); + if (files[i].fp == stdin) + continue; if (files[i].mode == '|' || files[i].mode == LE) stat = pclose(files[i].fp) == -1; + else if (files[i].fp == stdout || files[i].fp == stderr) + stat = fflush(files[i].fp) == EOF; else stat = fclose(files[i].fp) == EOF; if (stat) |