From de23ab7bfbea6ee03ef7386c6c203a4b2b7b7116 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 23 Jul 2016 22:10:25 +0300 Subject: Make return status of close on a pipe like system. --- io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index b9bce694..42986091 100644 --- a/io.c +++ b/io.c @@ -1227,7 +1227,8 @@ do_close(int nargs) * POSIX says close() returns 0 on success, non-zero otherwise. * For POSIX, at this point we just return 0. Otherwise we * return the exit status of the process or of pclose(), depending. - * This whole business is a mess. + * Down in the call tree of close_redir(), we rationalize the + * value like we do for system(). */ if (do_posix) { unref(tmp); @@ -1269,13 +1270,14 @@ close_rp(struct redirect *rp, two_way_close_type how) #endif /* HAVE_SOCKETS */ (void) iop_close(rp->iop); } else + /* status already sanitized */ status = gawk_pclose(rp); rp->iop = NULL; } } else if ((rp->flag & (RED_PIPE|RED_WRITE)) == (RED_PIPE|RED_WRITE)) { /* write to pipe */ - status = pclose(rp->output.fp); + status = sanitize_exit_status(pclose(rp->output.fp)); if ((BINMODE & BINMODE_INPUT) != 0) os_setbinmode(fileno(stdin), O_BINARY); @@ -2519,7 +2521,7 @@ gawk_pclose(struct redirect *rp) /* process previously found, return stored status */ if (rp->pid == -1) return rp->status; - rp->status = wait_any(rp->pid); + rp->status = sanitize_exit_status(wait_any(rp->pid)); rp->pid = -1; return rp->status; } -- cgit v1.2.3