[PATCH seastar] reactor: block all signals early

14 views
Skip to first unread message

Avi Kivity

<avi@scylladb.com>
unread,
Jan 20, 2016, 5:56:10 AM1/20/16
to seastar-dev@googlegroups.com
Some signals can only be handled on specific threads; we block them on all
others to prevent the wrong thread from handling a signal. But if a
library (in our case DPDK) spawns a thread, it may inherit a permissive
signal mask and handle the signal itself, resulting in confusing.

Fix by blocking all signals early, before libraries get a chance to spawn
threads.

See scylladb/scylla#601.
---
core/reactor.cc | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/core/reactor.cc b/core/reactor.cc
index 4fb5247..ec36a57 100644
--- a/core/reactor.cc
+++ b/core/reactor.cc
@@ -2309,6 +2309,13 @@ void smp::cleanup() {

void smp::configure(boost::program_options::variables_map configuration)
{
+ // mask all signals, to prevent threads (esp. dpdk helper threads)
+ // from servicing a signal. Individual reactors will unmask signals
+ // as they become prepared to handle them.
+ sigset_t sigs;
+ sigfillset(&sigs);
+ pthread_sigmask(SIG_BLOCK, &sigs, nullptr);
+
smp::count = 1;
smp::_tmain = std::this_thread::get_id();
auto nr_cpus = resource::nr_processing_units();
--
2.5.0

Avi Kivity

<avi@scylladb.com>
unread,
Jan 20, 2016, 7:55:08 AM1/20/16
to seastar-dev@googlegroups.com
Some signals can only be handled on specific threads; we block them on all
others to prevent the wrong thread from handling a signal. But if a
library (in our case DPDK) spawns a thread, it may inherit a permissive
signal mask and handle the signal itself, resulting in confusing.

Fix by blocking all signals early, before libraries get a chance to spawn
threads.

See scylladb/scylla#601.
---

v2: leave some signals (that we don't handle) unmasked to preserve
default behavior

core/reactor.cc | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/core/reactor.cc b/core/reactor.cc
index e1e34f9..d6c47ca 100644
--- a/core/reactor.cc
+++ b/core/reactor.cc
@@ -2309,6 +2309,19 @@ void smp::cleanup() {

void smp::configure(boost::program_options::variables_map configuration)
{
+ // Mask most, to prevent threads (esp. dpdk helper threads)
+ // from servicing a signal. Individual reactors will unmask signals
+ // as they become prepared to handle them.
+ //
+ // We leave some signals unmasked since we don't handle them ourself.
+ sigset_t sigs;
+ sigfillset(&sigs);
+ for (auto sig : {SIGHUP, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV,
+ SIGALRM, SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU}) {
+ sigdelset(&sigs, sig);
+ }

Commit Bot

<bot@cloudius-systems.com>
unread,
Jan 20, 2016, 7:59:23 AM1/20/16
to seastar-dev@googlegroups.com, Avi Kivity
From: Avi Kivity <a...@scylladb.com>
Committer: Avi Kivity <a...@scylladb.com>

reactor: block all signals early

Some signals can only be handled on specific threads; we block them on all
others to prevent the wrong thread from handling a signal. But if a
library (in our case DPDK) spawns a thread, it may inherit a permissive
signal mask and handle the signal itself, resulting in confusing.

Fix by blocking all signals early, before libraries get a chance to spawn
threads.

See scylladb/scylla#601.

---
diff --git a/core/reactor.cc b/core/reactor.cc
Reply all
Reply to author
Forward
0 new messages