Skip to content

Commit 486b051

Browse files
committed
Add cleanup function for the probe_worker_runfn thread
We should make sure that receiver gets something (error should do it), even if the worker thread suddenly terminates (e.g. thread_exit).
1 parent 7991d70 commit 486b051

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/OVAL/probes/probe/worker.c

+11
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ static void preload_libraries_before_chroot()
7272
pthread_join(t, NULL);
7373
}
7474

75+
static void pthread_pair_cleanup_handler(void *arg)
76+
{
77+
probe_pwpair_t *pair = (probe_pwpair_t *)arg;
78+
dW("Probe worker thread finished unxpectedly, trying to avoid deadlock now...");
79+
SEAP_replyerr(pair->probe->SEAP_ctx, pair->probe->sd, pair->pth->msg, -100);
80+
}
81+
7582
void *probe_worker_runfn(void *arg)
7683
{
7784
dD("probe_worker_runfn has started");
@@ -88,6 +95,8 @@ void *probe_worker_runfn(void *arg)
8895
# endif
8996
#endif
9097
dD("handling SEAP message ID %u", pair->pth->sid);
98+
pthread_cleanup_push(pthread_pair_cleanup_handler, (void *)pair);
99+
91100
//
92101
probe_ret = -1;
93102
probe_res = pair->pth->msg_handler(pair->probe, pair->pth->msg, &probe_ret);
@@ -172,6 +181,8 @@ void *probe_worker_runfn(void *arg)
172181
free(pair);
173182
pthread_detach(pthread_self());
174183

184+
pthread_cleanup_pop(0);
185+
175186
dD("probe_worker_runfn has finished");
176187
return (NULL);
177188
}

0 commit comments

Comments
 (0)