aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r--src/daemon/daemon.c32
1 files changed, 29 insertions, 3 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
564static struct sigaction sig;
565
566static struct sigaction old;
567
568static void sigalrmHandler(int sig) {
569}
570
571/**
572 * Initialize the signal handler for SIGALRM.
573 */
574void __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
583void __attribute__ ((destructor)) pthread_handlers_ltdl_fini() {
584 sigaction(SIGALRM, &old, &sig);
585}
586
561/* end of daemon.c */ 587/* end of daemon.c */