[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] [PATCH] Avoid silent misbehaviour on pthread join failur
From: |
Mike Crowe |
Subject: |
[libmicrohttpd] [PATCH] Avoid silent misbehaviour on pthread join failure |
Date: |
Fri, 9 Oct 2009 12:23:40 +0100 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
I've just spent a while investigating a problem that was causing
pthread_join to fail. It was all of my own making but it took me a
while to track down because libmicrohttpd just continued regardless
and raced with the thread that it thought should be dead by that
point. Most of the time this was benign but very rarely it would go
bang.
Anyway, this patch means that libmicrohttpd should no longer continue
regardless. I've tried to follow the style of the existing code.
Thanks.
Mike.
--- libmicrohttpd-0.4.2.orig/src/daemon/daemon.c 2009-04-02
02:47:04.000000000 +0100
+++ libmicrohttpd-0.4.2/src/daemon/daemon.c 2009-10-09 12:12:30.000000000
+0100
@@ -755,8 +755,10 @@ MHD_cleanup_connections (struct MHD_Daem
prev->next = pos->next;
if (0 != (pos->daemon->options & MHD_USE_THREAD_PER_CONNECTION))
{
- pthread_kill (pos->pid, SIGALRM);
- pthread_join (pos->pid, &unused);
+ if (0 != pthread_kill (pos->pid, SIGALRM))
+ abort();
+ if (0 != pthread_join (pos->pid, &unused))
+ abort();
}
MHD_destroy_response (pos->response);
MHD_pool_destroy (pos->pool);
@@ -1442,7 +1444,8 @@ MHD_stop_daemon (struct MHD_Daemon *daem
pthread_kill (daemon->worker_pool[i].pid, SIGALRM);
for (i = 0; i < daemon->worker_pool_size; ++i)
{
- pthread_join (daemon->worker_pool[i].pid, &unused);
+ if (0 != pthread_join (daemon->worker_pool[i].pid, &unused))
+ abort();
MHD_close_connections (&daemon->worker_pool[i]);
}
free (daemon->worker_pool);
@@ -1451,8 +1454,10 @@ MHD_stop_daemon (struct MHD_Daemon *daem
((0 != (daemon->options & MHD_USE_SELECT_INTERNALLY))
&& (0 == daemon->worker_pool_size)))
{
- pthread_kill (daemon->pid, SIGALRM);
- pthread_join (daemon->pid, &unused);
+ if (0 != pthread_kill (daemon->pid, SIGALRM))
+ abort();
+ if (0 != pthread_join (daemon->pid, &unused))
+ abort();
}
MHD_close_connections (daemon);
- [libmicrohttpd] [PATCH] Avoid silent misbehaviour on pthread join failure,
Mike Crowe <=