Re: ccache interrupt handling bug

Tom Lane <[email protected]> Wed, 19 Aug 2015 00:17:39 -0400
Newsgroups gmane.comp.compilers.ccache
Message-ID <[email protected]>
Joel Rosdahl <[email protected]> writes:
> Tom Lane <[email protected]> wrote:
>> Actually, that's a bug not just a cosmetic problem, because it introduces
>> a race condition.

> Yes, sounds like a race condition that could happen.
> I just pushed this change as a fix:
> https://git.samba.org/?p=ccache.git;a=commitdiff;h=4fdb9580fedac9669508bef0837f46f1e9310e24.
> Opinions on it are welcome.

Hm.  In principle there are still race conditions here: consider what
happens if the SIGINT is received between fork() and storing the PID
into *pid, or after waitpid() and before clearing *pid.

Those windows are probably narrow enough to not be an issue in practice,
but it's a bit nervous-making.

One thing that might be worth doing is declaring pid (and hence the
pointer argument) to be volatile so that the compiler wouldn't be tempted
to rearrange the code and maybe make those windows bigger.  That's
required for formal C-spec-compliance anyway, given that pid is accessed
by a signal handler.

			regards, tom lane