base: Fix a potential race in PollQueue::setupAsyncIO

There is a potential race between enabling asynchronous IO and
selecting the target for the SIGIO signal. This changeset move the
F_SETOWN call to before the F_SETFL call that enables SIGIO
delivery. This ensures that signals are always sent to the correct
process.
This commit is contained in:
Andreas Sandberg 2013-10-07 16:03:15 +02:00
parent 0dd6f87e63
commit c0f367e514

View file

@ -213,13 +213,13 @@ PollQueue::setupAsyncIO(int fd, bool set)
else
flags &= ~(FASYNC);
if (fcntl(fd, F_SETFL, flags) == -1)
panic("Could not set up async IO");
if (set) {
if (fcntl(fd, F_SETOWN, getpid()) == -1)
panic("Could not set up async IO");
}
if (fcntl(fd, F_SETFL, flags) == -1)
panic("Could not set up async IO");
}
void