znc: Fix logic for pthread_cancel
alternative
This commit is contained in:
parent
fc79a51a92
commit
f94de55e72
@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="An advanced IRC bouncer"
|
||||
TERMUX_PKG_LICENSE="Apache-2.0"
|
||||
TERMUX_PKG_MAINTAINER="@termux"
|
||||
TERMUX_PKG_VERSION=1.8.2
|
||||
TERMUX_PKG_REVISION=1
|
||||
TERMUX_PKG_SRCURL=https://znc.in/releases/archive/znc-${TERMUX_PKG_VERSION}.tar.gz
|
||||
TERMUX_PKG_SHA256=ff238aae3f2ae0e44e683c4aee17dc8e4fdd261ca9379d83b48a7d422488de0d
|
||||
TERMUX_PKG_DEPENDS="libc++, libicu, libsasl, openssl, zlib"
|
||||
|
@ -8,29 +8,25 @@
|
||||
|
||||
#if defined(HAVE_LIBSSL) && defined(HAVE_PTHREAD) && \
|
||||
(!defined(OPENSSL_VERSION_NUMBER) || OPENSSL_VERSION_NUMBER < 0x10100004)
|
||||
@@ -180,7 +181,7 @@
|
||||
@@ -177,10 +178,11 @@
|
||||
sigset_t signals;
|
||||
sigfillset(&signals);
|
||||
pthread_sigmask(SIG_SETMASK, &signals, nullptr);
|
||||
+ m_thread_cancel.test_and_set();
|
||||
m_thread = std::thread([=]() { HandleSignals(pZNC); });
|
||||
}
|
||||
~CSignalHandler() {
|
||||
- pthread_cancel(m_thread.native_handle());
|
||||
+ m_thread_cancel.test_and_set();
|
||||
+ m_thread_cancel.clear();
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
@@ -203,6 +204,7 @@
|
||||
};
|
||||
|
||||
void HandleSignals(CZNC* pZNC) {
|
||||
+ m_thread_cancel.clear();
|
||||
sigset_t signals;
|
||||
sigemptyset(&signals);
|
||||
sigaddset(&signals, SIGHUP);
|
||||
@@ -216,11 +218,10 @@
|
||||
pthread_sigmask(SIG_SETMASK, &signals, nullptr);
|
||||
while (true) {
|
||||
int sig;
|
||||
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, nullptr);
|
||||
+ if (m_thread_cancel.test_and_set()) pthread_exit(nullptr);
|
||||
+ if (!m_thread_cancel.test_and_set()) pthread_exit(nullptr);
|
||||
// This thread can be cancelled, but only during this function.
|
||||
// Such cancel will be the only way to finish this thread.
|
||||
if (sigwait(&signals, &sig) == -1) continue;
|
||||
|
Loading…
Reference in New Issue
Block a user