bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gawk 3.1.4: reproducible hang, regression from 3.1.3


From: Aharon Robbins
Subject: Re: gawk 3.1.4: reproducible hang, regression from 3.1.3
Date: Mon, 29 Nov 2004 18:39:36 +0200

Greetings. Re this:

> To: address@hidden
> Subject: gawk 3.1.4: reproducible hang, regression from 3.1.3
> From: James Troup <address@hidden>
> Date: Fri, 26 Nov 2004 03:14:05 +0000
>
> Hi,
>
> A Debian user reported[0] gawk 3.1.4 broke a (relatively) complex
> program that makes extensive use of awk, called 'apt-move'.  I finally
> managed to reduced the problem down to a 3 line test case, enclosed
> below[1].
>
> I believe the problem comes from the following code, introduced in
> 3.1.4:
>
> [io.c, line 560]
> |     for (rp = red_head; rp != NULL; rp = rp->next) {
> |             if ((rp->flag & RED_EOF) && tree->type == Node_redirect_pipein) 
> {
> |                     if (rp->pid != -1)
> |                             wait_any(0);
> |             }
>
> The problem is that, if we have an existing redirect which is a simple
> file redirect[b] and it's hit EOF and we try to create a new '|'
> redirect[c], this new code will try to wait(2) and if there are any
> other redirects which _did_ spawn a child (like [a]) the wait() will
> hang indefinitely waiting for it to exit.
>
> Hope that makes sense :)
>
> -- 
> James
>
> [0] http://bugs.debian.org/263964
>
> [1] 
> ================================================================================
> #!/usr/bin/gawk -f
>
> BEGIN {
>       printf "" | "cat"             # [a]
>       getline line < "/dev/null"    # [b]
>       "true" | getline line         # [c]
> }
> ================================================================================

First, THANK YOU for the excellent bug report. I'll be adding this to
the gawk test suite.  Secondly, your analysis of the problem is correct,
and this patch looks to me to do the trick.

Arnold
-------------------
Mon Nov 29 18:36:25 2004   Arnold D. Robbins    <address@hidden>

        * io.c (redirect): When allocating a new struct redirect, set
        rp->pid to -1, not 0, so that code checking for EOF on an
        input pipe works correctly.

--- ../gawk-3.1.4/io.c  2004-07-28 16:41:56.000000000 +0300
+++ io.c        2004-11-29 18:35:59.000000000 +0200
@@ -602,7 +602,7 @@
                rp->flag = tflag;
                rp->fp = NULL;
                rp->iop = NULL;
-               rp->pid = 0;    /* unlikely that we're worried about init */
+               rp->pid = -1;
                rp->status = 0;
                /* maintain list in most-recently-used first order */
                if (red_head != NULL)




reply via email to

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