diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | builtin.c | 3 | ||||
-rw-r--r-- | io.c | 3 | ||||
-rw-r--r-- | test/ChangeLog | 2 | ||||
-rw-r--r-- | test/clos1way2.awk | 1 | ||||
-rw-r--r-- | test/clos1way2.ok | 3 |
6 files changed, 16 insertions, 2 deletions
@@ -1,3 +1,9 @@ +2016-04-04 Arnold D. Robbins <arnold@skeeve.com> + + * builtin.c (do_fflush): Add warning for flush to two-way + pipe where write end was closed. + * io.c (flush_io): Add some braces for the for loop. + 2016-04-02 Arnold D. Robbins <arnold@skeeve.com> * builtin.c (do_printf): If the redirection is two way but the @@ -237,6 +237,9 @@ do_fflush(int nargs) fp = rp->output.fp; if (fp != NULL) status = rp->output.gawk_fflush(fp, rp->output.opaque); + else if ((rp->flag & RED_TWOWAY) != 0) + warning(_("fflush: cannot flush: two-way pipe `%s' has closed write end"), + file); } else if ((fp = stdfile(tmp->stptr, tmp->stlen)) != NULL) { status = fflush(fp); } else { @@ -1328,7 +1328,7 @@ flush_io() warning(_("error writing standard error (%s)"), strerror(errno)); status++; } - for (rp = red_head; rp != NULL; rp = rp->next) + for (rp = red_head; rp != NULL; rp = rp->next) { /* flush both files and pipes, what the heck */ if ((rp->flag & RED_WRITE) != 0 && rp->output.fp != NULL) { if (rp->output.gawk_fflush(rp->output.fp, rp->output.opaque)) { @@ -1344,6 +1344,7 @@ flush_io() status++; } } + } if (status != 0) status = -1; /* canonicalize it */ return status; diff --git a/test/ChangeLog b/test/ChangeLog index 80b2c233..2867f6cb 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -5,6 +5,8 @@ * clos1way2.awk, clos1way2.in, clos1way2.ok, clos1way3.awk, clos1way3.ok, clos1way4.awk, clos1way4.ok, clos1way5.awk, clos1way5.ok: New files. + * clos1way2.awk: Add call to fflush() to test it too. + * clos1way2.ok: Updated after code change. 2016-02-18 Arnold D. Robbins <arnold@skeeve.com> diff --git a/test/clos1way2.awk b/test/clos1way2.awk index 7dab6a67..5794bec5 100644 --- a/test/clos1way2.awk +++ b/test/clos1way2.awk @@ -1,5 +1,6 @@ { cmd = "cat - 1>&2; sleep 2" print |& cmd; close(cmd, "to") + fflush(cmd) print |& cmd; print ERRNO } diff --git a/test/clos1way2.ok b/test/clos1way2.ok index 22bd3e17..063c4213 100644 --- a/test/clos1way2.ok +++ b/test/clos1way2.ok @@ -1,3 +1,4 @@ -gawk: clos1way2.awk:4: (FILENAME=- FNR=1) fatal: print: attempt to write to closed write end of two-way pipe +gawk: clos1way2.awk:4: (FILENAME=- FNR=1) warning: fflush: cannot flush: two-way pipe `cat - 1>&2; sleep 2' has closed write end +gawk: clos1way2.awk:5: (FILENAME=- FNR=1) fatal: print: attempt to write to closed write end of two-way pipe test CODE: 2 |