commit a01593e2f832856619bc2540ef4c135788cab24b
parent 3d39029f14a63af8cd26b1b0c9000cecea97931c
Author: Christian Grothoff <christian@grothoff.org>
Date: Thu, 14 Jun 2007 00:37:55 +0000
stop nicely
Diffstat:
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git 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
@@ -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
@@ -38,6 +38,7 @@
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <pthread.h>
#include <netinet/in.h>