Skip to content

Commit bb794bf

Browse files
committed
Take patch in downstream termux-packages project and adjust to use HAVE_PTHREAD_CANCEL instead of __ANDROID__
https://github.com/termux/termux-packages/blob/master/packages/cfengine/pthread_cancel.patch Ticket: CFE-4401 Changelog: none (cherry picked from commit 5cebd75)
1 parent cb70ddb commit bb794bf

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

libpromises/evalfunction.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8513,10 +8513,27 @@ struct IsReadableThreadData
85138513
FnCallResult result;
85148514
};
85158515

8516+
#ifndef HAVE_PTHREAD_CANCEL
8517+
#define PTHREAD_CANCELED ((void *)-1)
8518+
static void ThreadSignalHandler(int signum)
8519+
{
8520+
pthread_exit(PTHREAD_CANCELED);
8521+
}
8522+
#endif
8523+
85168524
static void *IsReadableThreadRoutine(void *data)
85178525
{
85188526
assert(data != NULL);
85198527

8528+
#ifndef HAVE_PTHREAD_CANCEL
8529+
struct sigaction actions;
8530+
memset(&actions, 0, sizeof(actions));
8531+
sigemptyset(&actions.sa_mask);
8532+
actions.sa_flags = 0;
8533+
actions.sa_handler = ThreadSignalHandler;
8534+
sigaction(SIGUSR2, &actions, NULL);
8535+
#endif
8536+
85208537
struct IsReadableThreadData *const thread_data = data;
85218538

85228539
// Give main thread time to call pthread_cond_timedwait(3)
@@ -8671,7 +8688,7 @@ static FnCallResult FnCallIsReadable(ARG_UNUSED EvalContext *const ctx,
86718688
#ifdef HAVE_PTHREAD_CANCEL
86728689
ret = pthread_cancel(thread_data.thread);
86738690
#else
8674-
ret = pthread_kill(thread_data.thread, 0);
8691+
ret = pthread_kill(thread_data.thread, SIGUSR2);
86758692
#endif
86768693
if (ret != 0)
86778694
{

0 commit comments

Comments
 (0)