signal: fix race in Signal_receiver pending_signal

In the past, we had the lock of the context we found for the rest of the scope
of pending_signal. Now we use for_each_locked to find the context and the
lock is released as soon as we return from for_each_locked. Thus, we need to
lock the context again before returning it to avoid that the copy constructor
during the return reads values that are currently changing.

Fixes #2532
This commit is contained in:
Martin Stein 2017-12-05 11:46:26 +01:00 committed by Christian Helmuth
parent bf60e1486d
commit b812179e82
1 changed files with 1 additions and 0 deletions

View File

@ -175,6 +175,7 @@ Signal Signal_receiver::pending_signal()
throw Context_ring::Break_for_each();
});
if (result.context) {
Lock::Guard lock_guard(result.context->_lock);
if (result.num == 0)
warning("returning signal with num == 0");