From c0f367e51454dc9d2610bbd3266a80cec7b4ad69 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Mon, 7 Oct 2013 16:03:15 +0200 Subject: [PATCH] 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. --- src/base/pollevent.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base/pollevent.cc b/src/base/pollevent.cc index 67708c129..cb44d8728 100644 --- a/src/base/pollevent.cc +++ b/src/base/pollevent.cc @@ -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 -- 2.30.2