From 8a0bde7a0b5b61a08a43a5bf374fc4705b788684 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Thu, 30 Nov 2017 07:17:31 +0100 Subject: [PATCH] jobs: Fix possible race condition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Sending the signal while not being sure that is is expected could be a race condition. Taking the mutex avoids it. In the same time, switch to broadcasting. Change-Id: I3f43d0d860cccc61ec140ceef223f572f806872c Signed-off-by: José Bollo --- src/jobs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/jobs.c b/src/jobs.c index 464f1e11..e3df8f57 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -636,7 +636,9 @@ static int on_evloop_efd(sd_event_source *s, int fd, uint32_t revents, void *use uint64_t x; struct evloop *evloop = userdata; read(evloop->efd, &x, sizeof x); - pthread_cond_signal(&evloop->cond); + pthread_mutex_lock(&mutex); + pthread_cond_broadcast(&evloop->cond); + pthread_mutex_unlock(&mutex); return 1; } @@ -656,7 +658,7 @@ struct sd_event *jobs_get_sd_event() el = &evloop[0]; if (!el->sdev) { /* creates the eventfd for waking up polls */ - el->efd = eventfd(0, EFD_CLOEXEC|EFD_SEMAPHORE); + el->efd = eventfd(0, EFD_CLOEXEC); if (el->efd < 0) { ERROR("can't make eventfd for events"); goto error1; -- 2.16.6