bug-gawk
[Top][All Lists]
Advanced

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

Re: iolint race condition


From: Miguel Pineiro Jr.
Subject: Re: iolint race condition
Date: Mon, 06 Dec 2021 21:37:26 -0500
User-agent: Cyrus-JMAP/3.5.0-alpha0-4492-g121c2470aa-fm-20211206.001-g121c2470

Hi, Andy

On Mon, 29 Nov 2021 17:33:35 -0500, Andrew J. Schorr wrote:
> P.S. I'm getting a "make check" ordering error for the iolint test in the
> master branch, but I imagine that's unrelated:
>
> --- iolint.ok   2021-11-21 18:16:26.442106000 -0500
> +++ _iolint     2021-11-29 17:30:29.657143000 -0500
> @@ -20,9 +20,9 @@
>  0
>  0
>  gawk: iolint.awk:53: warning: `cat' used for output file and output pipe
> -0
>  hello
>  0
> +0
>  gawk: iolint.awk:67: warning: `eval $CMD_TO_RUN' used for input pipe and 
> output
>  pipe
>  0
>  0

I haven't done any testing, but after looking at the code, I believe
the problem is here:

        print "hello" | "cat"
        print "/bin/cat \"$@\"" > "cat"
        print close("cat")
        print close("cat")

Redirections are maintained in a most-recently-used list (io.c ::
redirect_string). Therefore the first close() corresponds to the
regular file of the second print statement. This creates a race
between when the child process "cat" prints "hello" and the
printing of the first close statement's return value.

If I'm correct, the fix is to reverse the order of the redirections
so that nothing can print between the time the child is forked
and the time it's waited on:

        print "/bin/cat \"$@\"" > "cat"
        print "hello" | "cat"
        print close("cat")
        print close("cat")

Regards,
Miguel

P. S. Nice work refactoring efwrite. Great idea.



reply via email to

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