ettercap: Use alternative `pthread_cancel` workaround

This commit is contained in:
Tee KOBAYASHI 2022-12-13 09:11:19 +09:00 committed by xtkoba
parent ba23db420a
commit 5abf5e869a
8 changed files with 89 additions and 57 deletions

View File

@ -3,10 +3,10 @@ TERMUX_PKG_DESCRIPTION="Comprehensive suite for MITM attacks, can sniff live con
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=0.8.3.1
TERMUX_PKG_REVISION=6
TERMUX_PKG_REVISION=7
TERMUX_PKG_SRCURL=https://github.com/Ettercap/ettercap/archive/v${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=d0c3ef88dfc284b61d3d5b64d946c1160fd04276b448519c1ae4438a9cdffaf3
TERMUX_PKG_DEPENDS="libpcap, openssl, zlib, curl, pcre, ncurses, libiconv, libnet, libltdl, ethtool"
TERMUX_PKG_DEPENDS="ethtool, libcurl, libiconv, libnet, libpcap, ncurses, ncurses-ui-libs, openssl, pcre, zlib"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DCMAKE_BUILD_TYPE=Release
-DENABLE_GTK=off

View File

@ -1,34 +0,0 @@
--- ../ec_threads.c.orig 2019-08-27 20:09:25.304142288 +0200
+++ ./src/ec_threads.c 2019-08-27 20:14:11.753262944 +0200
@@ -233,13 +233,6 @@
DEBUG_MSG("ec_thread_init -- %lu", PTHREAD_ID(id));
INIT_LOCK;
-
- /*
- * allow a thread to be cancelled as soon as the
- * cancellation request is received
- */
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/* sync with the creator */
if ((e = pthread_cond_signal(&init_cond)))
@@ -263,7 +256,7 @@
/* send the cancel signal to the thread */
- pthread_cancel((pthread_t)id);
+ pthread_kill((pthread_t)id, 0);
DEBUG_MSG("ec_thread_destroy -- [%s] terminated", ec_thread_getname(id));
@@ -319,7 +312,7 @@
DEBUG_MSG("ec_thread_kill_all -- terminating %lu [%s]", PTHREAD_ID(current->t.id), current->t.name);
/* send the cancel signal to the thread */
- pthread_cancel((pthread_t)current->t.id);
+ pthread_kill((pthread_t)current->t.id, 0);
#ifndef BROKEN_PTHREAD_JOIN
if (!current->t.detached) {

View File

@ -1,21 +0,0 @@
--- ../ec_ui.c.orig 2019-08-27 20:07:21.158532026 +0200
+++ ./src/ec_ui.c 2019-08-27 20:07:36.117841510 +0200
@@ -256,9 +256,6 @@
if (STAILQ_EMPTY(&messages_queue))
return 0;
- // don't allow the thread to cancel while holding the ui mutex
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old);
-
/* the queue is updated by other threads */
UI_MSG_LOCK;
@@ -280,8 +277,6 @@
UI_MSG_UNLOCK;
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old);
-
/* returns the number of displayed messages */
return i;

View File

@ -0,0 +1,58 @@
--- a/src/ec_threads.c
+++ b/src/ec_threads.c
@@ -233,6 +233,13 @@ pthread_t ec_thread_new_detached(char *n
return id;
}
+#ifdef __ANDROID__
+static void thread_signal_handler(int signum)
+{
+ pthread_exit(0);
+}
+#endif
+
/*
* set the state of a thread
* all the new thread MUST call this on startup
@@ -250,8 +257,17 @@ void ec_thread_init(void)
* allow a thread to be cancelled as soon as the
* cancellation request is received
*/
+#ifndef __ANDROID__
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+#else
+ struct sigaction actions;
+ memset(&actions, 0, sizeof(actions));
+ sigemptyset(&actions.sa_mask);
+ actions.sa_flags = 0;
+ actions.sa_handler = thread_signal_handler;
+ sigaction(SIGUSR2, &actions, NULL);
+#endif
/* sync with the creator */
if ((e = pthread_cond_signal(&init_cond)))
@@ -275,7 +291,11 @@ void ec_thread_destroy(pthread_t id)
/* send the cancel signal to the thread */
+#ifndef __ANDROID__
pthread_cancel((pthread_t)id);
+#else
+ pthread_kill((pthread_t)id, SIGUSR2);
+#endif
DEBUG_MSG("ec_thread_destroy -- [%s] terminated", ec_thread_getname(id));
@@ -331,7 +351,11 @@ void ec_thread_kill_all(void)
DEBUG_MSG("ec_thread_kill_all -- terminating %lu [%s]", PTHREAD_ID(current->t.id), current->t.name);
/* send the cancel signal to the thread */
+#ifndef __ANDROID__
pthread_cancel((pthread_t)current->t.id);
+#else
+ pthread_kill((pthread_t)current->t.id, SIGUSR2);
+#endif
#ifndef BROKEN_PTHREAD_JOIN
if (!current->t.detached) {

View File

@ -0,0 +1,29 @@
--- a/src/ec_ui.c
+++ b/src/ec_ui.c
@@ -262,7 +262,14 @@ int ui_msg_flush(int max)
return 0;
// don't allow the thread to cancel while holding the ui mutex
+#ifndef __ANDROID__
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old);
+#else
+ sigset_t pthread_cancel_block;
+ sigemptyset(&pthread_cancel_block);
+ sigaddset(&pthread_cancel_block, SIGUSR2);
+ sigprocmask(SIG_BLOCK, &pthread_cancel_block, NULL);
+#endif
/* the queue is updated by other threads */
UI_MSG_LOCK;
@@ -285,7 +292,11 @@ int ui_msg_flush(int max)
UI_MSG_UNLOCK;
+#ifndef __ANDROID__
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old);
+#else
+ sigprocmask(SIG_UNBLOCK, &pthread_cancel_block, NULL);
+#endif
/* returns the number of displayed messages */
return i;