summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-06-14 00:37:55 +0000
committerChristian Grothoff <christian@grothoff.org>2007-06-14 00:37:55 +0000
commita01593e2f832856619bc2540ef4c135788cab24b (patch)
treeef1f9ad47b0c66150265c18c3c6584fa88c1a5af
parent3d39029f14a63af8cd26b1b0c9000cecea97931c (diff)
stop nicely
-rw-r--r--src/daemon/daemon.c32
-rw-r--r--src/daemon/daemontest1.c1
-rw-r--r--src/daemon/internal.h1
3 files changed, 30 insertions, 4 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 33f048ed..e00d1c45 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -286,8 +286,10 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) {
daemon->connections = pos->next;
else
prev->next = pos->next;
- if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
+ if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) {
+ pthread_kill(pos->pid, SIGALRM);
pthread_join(pos->pid, &unused);
+ }
free(pos->addr);
if (pos->url != NULL)
free(pos->url);
@@ -545,9 +547,10 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) {
close(daemon->socket_fd);
daemon->socket_fd = -1;
if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) ||
- (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
+ (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) {
+ pthread_kill(daemon->pid, SIGALRM);
pthread_join(daemon->pid, &unused);
-
+ }
while (daemon->connections != NULL) {
if (-1 != daemon->connections->socket_fd) {
close(daemon->connections->socket_fd);
@@ -558,4 +561,27 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) {
free(daemon);
}
+static struct sigaction sig;
+
+static struct sigaction old;
+
+static void sigalrmHandler(int sig) {
+}
+
+/**
+ * Initialize the signal handler for SIGALRM.
+ */
+void __attribute__ ((constructor)) pthread_handlers_ltdl_init() {
+ /* make sure SIGALRM does not kill us */
+ memset(&sig, 0, sizeof(struct sigaction));
+ memset(&old, 0, sizeof(struct sigaction));
+ sig.sa_flags = SA_NODEFER;
+ sig.sa_handler = &sigalrmHandler;
+ sigaction(SIGALRM, &sig, &old);
+}
+
+void __attribute__ ((destructor)) pthread_handlers_ltdl_fini() {
+ sigaction(SIGALRM, &old, &sig);
+}
+
/* end of daemon.c */
diff --git a/src/daemon/daemontest1.c b/src/daemon/daemontest1.c
index 4c2103f1..d347323b 100644
--- a/src/daemon/daemontest1.c
+++ b/src/daemon/daemontest1.c
@@ -142,7 +142,6 @@ static int testInternalGet() {
MHD_stop_daemon(d);
return 8;
}
-
MHD_stop_daemon(d);
return 0;
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
index 9a3ec5a2..ee5e1f97 100644
--- a/src/daemon/internal.h
+++ b/src/daemon/internal.h
@@ -38,6 +38,7 @@
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <pthread.h>
#include <netinet/in.h>