diff --git a/src/Socket.cpp b/src/Socket.cpp index 8e356db9..2ef5ba9a 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -10,6 +10,7 @@ #include #include #include +#include /* We should need 2 DNS threads (host, bindhost) per IRC connection */ static const size_t MAX_IDLE_THREADS = 2; @@ -169,6 +170,21 @@ void CSockManager::StartTDNSThread(TDNSTask* task, bool bBind) { pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_t thr; + sigset_t old_sigmask; + sigset_t sigmask; + sigfillset(&sigmask); + /* Block all signals. The thread will inherit our signal mask and thus + * won't ever try to handle any signals. + */ + if (pthread_sigmask(SIG_SETMASK, &sigmask, &old_sigmask)) { + CString sError = "Couldn't block signals"; + DEBUG(sError); + CZNC::Get().Broadcast(sError, /* bAdminOnly = */ true); + delete arg; + pthread_attr_destroy(&attr); + SetTDNSThreadFinished(task, bBind, NULL); + return; + } if (pthread_create(&thr, &attr, TDNSThread, &m_threadStatus)) { CString sError = "Couldn't create thread for " + sHostname; DEBUG(sError); @@ -178,6 +194,15 @@ void CSockManager::StartTDNSThread(TDNSTask* task, bool bBind) { SetTDNSThreadFinished(task, bBind, NULL); return; } + if (pthread_sigmask(SIG_SETMASK, &old_sigmask, NULL)) { + CString sError = "Couldn't unblock signals"; + DEBUG(sError); + CZNC::Get().Broadcast(sError, /* bAdminOnly = */ true); + delete arg; + pthread_attr_destroy(&attr); + SetTDNSThreadFinished(task, bBind, NULL); + return; + } pthread_attr_destroy(&attr); }