diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/daemon.c | 32 | ||||
-rw-r--r-- | src/daemon/daemontest1.c | 1 | ||||
-rw-r--r-- | src/daemon/internal.h | 1 |
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) { | |||
286 | daemon->connections = pos->next; | 286 | daemon->connections = pos->next; |
287 | else | 287 | else |
288 | prev->next = pos->next; | 288 | prev->next = pos->next; |
289 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 289 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { |
290 | pthread_kill(pos->pid, SIGALRM); | ||
290 | pthread_join(pos->pid, &unused); | 291 | pthread_join(pos->pid, &unused); |
292 | } | ||
291 | free(pos->addr); | 293 | free(pos->addr); |
292 | if (pos->url != NULL) | 294 | if (pos->url != NULL) |
293 | free(pos->url); | 295 | free(pos->url); |
@@ -545,9 +547,10 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) { | |||
545 | close(daemon->socket_fd); | 547 | close(daemon->socket_fd); |
546 | daemon->socket_fd = -1; | 548 | daemon->socket_fd = -1; |
547 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || | 549 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) || |
548 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) | 550 | (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) { |
551 | pthread_kill(daemon->pid, SIGALRM); | ||
549 | pthread_join(daemon->pid, &unused); | 552 | pthread_join(daemon->pid, &unused); |
550 | 553 | } | |
551 | while (daemon->connections != NULL) { | 554 | while (daemon->connections != NULL) { |
552 | if (-1 != daemon->connections->socket_fd) { | 555 | if (-1 != daemon->connections->socket_fd) { |
553 | close(daemon->connections->socket_fd); | 556 | close(daemon->connections->socket_fd); |
@@ -558,4 +561,27 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) { | |||
558 | free(daemon); | 561 | free(daemon); |
559 | } | 562 | } |
560 | 563 | ||
564 | static struct sigaction sig; | ||
565 | |||
566 | static struct sigaction old; | ||
567 | |||
568 | static void sigalrmHandler(int sig) { | ||
569 | } | ||
570 | |||
571 | /** | ||
572 | * Initialize the signal handler for SIGALRM. | ||
573 | */ | ||
574 | void __attribute__ ((constructor)) pthread_handlers_ltdl_init() { | ||
575 | /* make sure SIGALRM does not kill us */ | ||
576 | memset(&sig, 0, sizeof(struct sigaction)); | ||
577 | memset(&old, 0, sizeof(struct sigaction)); | ||
578 | sig.sa_flags = SA_NODEFER; | ||
579 | sig.sa_handler = &sigalrmHandler; | ||
580 | sigaction(SIGALRM, &sig, &old); | ||
581 | } | ||
582 | |||
583 | void __attribute__ ((destructor)) pthread_handlers_ltdl_fini() { | ||
584 | sigaction(SIGALRM, &old, &sig); | ||
585 | } | ||
586 | |||
561 | /* end of daemon.c */ | 587 | /* 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() { | |||
142 | MHD_stop_daemon(d); | 142 | MHD_stop_daemon(d); |
143 | return 8; | 143 | return 8; |
144 | } | 144 | } |
145 | |||
146 | MHD_stop_daemon(d); | 145 | MHD_stop_daemon(d); |
147 | 146 | ||
148 | return 0; | 147 | 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 @@ | |||
38 | #include <stdarg.h> | 38 | #include <stdarg.h> |
39 | #include <errno.h> | 39 | #include <errno.h> |
40 | #include <fcntl.h> | 40 | #include <fcntl.h> |
41 | #include <signal.h> | ||
41 | #include <pthread.h> | 42 | #include <pthread.h> |
42 | #include <netinet/in.h> | 43 | #include <netinet/in.h> |
43 | 44 | ||