[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: iolint race condition
From: |
Andrew J. Schorr |
Subject: |
Re: iolint race condition |
Date: |
Mon, 6 Dec 2021 22:29:00 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi Miguel,
On Mon, Dec 06, 2021 at 09:37:26PM -0500, Miguel Pineiro Jr. wrote:
> 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")
I guess you're saying that with this change, the results should
consistently be:
hello
0
0
I don't love that it's implementation-dependent, but it may be the most
expedient way of solving the problem.
Arnold -- OK to apply the attached patch?
> P. S. Nice work refactoring efwrite. Great idea.
Thanks -- a happy moment when I was able to escape being a prisoner of
the existing code.
Regards,
Andy
iolint.patch
Description: Text document