Fix directory validation after handler
[MonkeyD.git] / src / signals.c
blob682cdbcedcfc678eced6b1e8e4135a30bf32df60
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
3 /* Monkey HTTP Daemon
4 * ------------------
5 * Copyright (C) 2001-2003, Eduardo Silva P.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <pthread.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <signal.h>
26 #include <arpa/inet.h>
27 #include <netinet/in.h>
28 #include <unistd.h>
29 #include <sys/types.h>
30 #include <sys/wait.h>
32 #include "monkey.h"
33 #include "signals.h"
34 #include "utils.h"
35 #include "logfile.h"
36 #include "chars.h"
37 #include "clock.h"
39 /* (by Daniel R. Ome) */
40 void mk_signal_handler(int signo)
43 switch( signo ) {
44 case SIGUSR2:
45 printf("%s => Monkey reconfiguration \n",
46 log_current_time.data); /* Not ready */
47 break;
49 case SIGINT:
50 mk_logger_remove_pid();
51 printf("\n\n%s => Interrupt from keyboard\n\n",
52 log_current_time.data);
53 exit(0);
54 case SIGHUP:
55 printf("%s => Hangup\n",
56 log_current_time.data);
57 mk_signal_term();
58 break;
60 case SIGBUS:
61 printf("%s => Invalid memory reference\n",
62 log_current_time.data);
63 abort();
64 break;
66 case SIGPIPE:
67 printf("\n sigpipe");
68 fflush(stdout);
69 break;
71 case SIGSEGV:
72 printf("%s => Invalid memory reference\n",
73 log_current_time.data);
74 break;
76 case SIGTERM:
77 printf("%s => Termination signal\n",
78 log_current_time.data);
79 mk_signal_term();
80 break;
83 pthread_exit(NULL);
86 void mk_signal_init()
88 signal(SIGHUP , (void *) mk_signal_handler);
89 signal(SIGINT , (void *) mk_signal_handler);
90 signal(SIGPIPE, (void *) mk_signal_handler);
91 signal(SIGBUS, (void *) mk_signal_handler);
92 signal(SIGSEGV, (void *) mk_signal_handler);
93 signal(SIGTERM, (void *) mk_signal_handler);
94 signal(SIGUSR2, (void *) mk_signal_handler);
97 void mk_signal_term()
99 signal(SIGHUP , (void *) SIG_DFL);
100 signal(SIGINT , (void *) SIG_DFL);
101 signal(SIGPIPE, (void *) SIG_DFL);
102 signal(SIGBUS, (void *) SIG_DFL);
103 signal(SIGSEGV, (void *) SIG_DFL);
104 signal(SIGTERM, (void *) SIG_DFL);
105 signal(SIGUSR2, (void *) SIG_DFL);
108 void mk_signal_thread_sigpipe_safe()
110 sigset_t set, old;
112 sigemptyset(&set);
113 sigaddset(&set, SIGPIPE);
114 pthread_sigmask(SIG_BLOCK, &set, &old);