Skip to content

Commit 05c9b3d

Browse files
committed
libmpathutil: runner: use pthread_cleanup_push()
... instead of relying on -fexceptions and __attribute__((cleanup)). The latter causes sporadic occurences of SIGSEGV on MUSL libc. Signed-off-by: Martin Wilck <mwilck@suse.com>
1 parent 382dd99 commit 05c9b3d

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

libmpathutil/runner.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ struct runner_context {
4040
char __attribute__((aligned(sizeof(void *)))) data[];
4141
};
4242

43-
static void cleanup_context(struct runner_context **prctx)
43+
static void cleanup_context(void *arg)
4444
{
45-
struct runner_context *rctx = *prctx;
4645
int st;
46+
struct runner_context *rctx = arg;
4747

4848
if (!rctx) {
4949
condlog(0, "ERROR: %s: rctx is NULL", __func__);
@@ -82,7 +82,9 @@ static void *runner_thread(void *arg)
8282
* The cleanup function makes sure memory is freed if the thread is
8383
* cancelled (-fexceptions).
8484
*/
85-
struct runner_context *rctx __attribute__((cleanup(cleanup_context))) = arg;
85+
struct runner_context *rctx = arg;
86+
87+
pthread_cleanup_push(cleanup_context, arg);
8688

8789
#ifdef RUNNER_START_DELAY_US
8890
/*
@@ -98,10 +100,12 @@ static void *runner_thread(void *arg)
98100
#endif
99101

100102
st = uatomic_cmpxchg(&rctx->status, RUNNER_IDLE, RUNNER_RUNNING);
101-
if (st != RUNNER_IDLE)
102-
return NULL;
103103

104-
(*rctx->func)(rctx->data);
104+
/* Only run the function if we haven't been cancelled */
105+
if (st == RUNNER_IDLE)
106+
(*rctx->func)(rctx->data);
107+
108+
pthread_cleanup_pop(1);
105109
return NULL;
106110
}
107111

0 commit comments

Comments
 (0)