bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Does gawk deal with signal pipe correctly?


From: arnold
Subject: Re: [bug-gawk] Does gawk deal with signal pipe correctly?
Date: Sun, 17 Jun 2018 12:46:44 -0600
User-agent: Heirloom mailx 12.4 7/29/08

OK. I banged on this some more and managed to track it down.
A fix is below.  I will push this out to git shortly.

Thanks,

Arnold

Peng Yu <address@hidden> wrote:

> $ awk --version | head -n 1
> GNU Awk 4.2.0, API: 2.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
>
> On Sun, Jun 17, 2018 at 6:34 AM,  <address@hidden> wrote:
> > What is the output from gawk --version?
> >
> > Peng Yu <address@hidden> wrote:
> >
> >> Here is what I have. It is tested on a virtual machine (hosted on KVM
> >> on another Ubuntu physical machine). Are you able to get the same
> >> version vm to test?
> >>
> >> $ cat DCt7x2zD | awk '{ print }' | head -n 1
> >>
> >> $ echo address@hidden
> >> 0 141 0
> >> $ cat DCt7x2zD | awk '{ print }' | head -n 1
> >>
> >> $ echo address@hidden
> >> 0 1 0
--------------------------
diff --git a/awk.h b/awk.h
index f32e30a..31e661d 100644
--- a/awk.h
+++ b/awk.h
@@ -1574,7 +1574,7 @@ extern struct redirect *redirect_string(const char 
*redir_exp_str,
                int *errflg, int extfd, bool failure_fatal);
 extern NODE *do_close(int nargs);
 extern int flush_io(void);
-extern int close_io(bool *stdio_problem);
+extern int close_io(bool *stdio_problem, bool *got_EPIPE);
 typedef enum { CLOSE_ALL, CLOSE_TO, CLOSE_FROM } two_way_close_type;
 extern int close_rp(struct redirect *rp, two_way_close_type how);
 extern int devopen_simple(const char *name, const char *mode, bool 
try_real_open);
diff --git a/debug.c b/debug.c
index ed763e3..2e68cde 100644
--- a/debug.c
+++ b/debug.c
@@ -5405,11 +5405,11 @@ save_options(const char *file)
 static void
 close_all()
 {
-       bool stdio_problem;
+       bool stdio_problem, got_EPIPE;
        struct command_source *cs;
 
        (void) nextfile(& curfile, true);       /* close input data file */
-       (void) close_io(& stdio_problem);
+       (void) close_io(& stdio_problem, & got_EPIPE);
        if (cur_srcfile->fd != INVALID_HANDLE) {
                close(cur_srcfile->fd);
                cur_srcfile->fd = INVALID_HANDLE;
diff --git a/interpret.h b/interpret.h
index 20fcb7a..8408a53 100644
--- a/interpret.h
+++ b/interpret.h
@@ -110,6 +110,7 @@ top:
                case Op_atexit:
                {
                        bool stdio_problem = false;
+                       bool got_EPIPE = false;
 
                        /* avoid false source indications */
                        source = NULL;
@@ -125,7 +126,7 @@ top:
                         * and pipes, in that it doesn't affect their exit 
status.
                         * So we no longer do either.
                         */
-                       (void) close_io(& stdio_problem);
+                       (void) close_io(& stdio_problem, & got_EPIPE);
                        /*
                         * However, we do want to exit non-zero if there was a 
problem
                         * with stdout/stderr, so we reinstate a slightly 
different
@@ -135,6 +136,9 @@ top:
                                exit_val = 1;
 
                        close_extensions();
+
+                       if (got_EPIPE)
+                               die_via_sigpipe();
                }
                        break;
 
diff --git a/io.c b/io.c
index 9ca29da..a3d68ce 100644
--- a/io.c
+++ b/io.c
@@ -1474,12 +1474,13 @@ flush_io()
 /* close_io --- close all open files, called when exiting */
 
 int
-close_io(bool *stdio_problem)
+close_io(bool *stdio_problem, bool *got_EPIPE)
 {
        struct redirect *rp;
        struct redirect *next;
        int status = 0;
 
+       *stdio_problem = *got_EPIPE = false;
        errno = 0;
        for (rp = red_head; rp != NULL; rp = next) {
                next = rp->next;
@@ -1505,6 +1506,9 @@ close_io(bool *stdio_problem)
 #endif
                if (errno != EPIPE)
                        warning(_("error writing standard output (%s)"), 
strerror(errno));
+               else
+                       *got_EPIPE = true;
+
                status++;
                *stdio_problem = true;
        }
@@ -1515,6 +1519,9 @@ close_io(bool *stdio_problem)
 #endif
                if (errno != EPIPE)
                        warning(_("error writing standard error (%s)"), 
strerror(errno));
+               else
+                       *got_EPIPE = true;
+
                status++;
                *stdio_problem = true;
        }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]