Change the FSF address and update LICENSE with the new address and some texts
[MonkeyD.git] / src / signals.c
blob88f70b54989db7843f3b5fb7d7ec0cf0780a5d61
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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", log_current_time.data); /* Not ready */
46 break;
48 case SIGINT:
49 mk_logger_remove_pid();
50 printf("\n\n%s => Interrupt from keyboard\n\n",
51 log_current_time.data);
52 exit(0);
53 case SIGHUP:
54 printf("%s => Hangup\n", log_current_time.data);
55 mk_signal_term();
56 break;
58 case SIGBUS:
59 printf("%s => Invalid memory reference\n", log_current_time.data);
60 abort();
61 break;
63 case SIGPIPE:
64 printf("\n sigpipe");
65 fflush(stdout);
66 break;
68 case SIGSEGV:
69 printf("%s => Invalid memory reference\n", log_current_time.data);
70 break;
72 case SIGTERM:
73 printf("%s => Termination signal\n", log_current_time.data);
74 mk_signal_term();
75 break;
78 pthread_exit(NULL);
81 void mk_signal_init()
83 signal(SIGHUP, (void *) mk_signal_handler);
84 signal(SIGINT, (void *) mk_signal_handler);
85 signal(SIGPIPE, (void *) mk_signal_handler);
86 signal(SIGBUS, (void *) mk_signal_handler);
87 signal(SIGSEGV, (void *) mk_signal_handler);
88 signal(SIGTERM, (void *) mk_signal_handler);
89 signal(SIGUSR2, (void *) mk_signal_handler);
92 void mk_signal_term()
94 signal(SIGHUP, (void *) SIG_DFL);
95 signal(SIGINT, (void *) SIG_DFL);
96 signal(SIGPIPE, (void *) SIG_DFL);
97 signal(SIGBUS, (void *) SIG_DFL);
98 signal(SIGSEGV, (void *) SIG_DFL);
99 signal(SIGTERM, (void *) SIG_DFL);
100 signal(SIGUSR2, (void *) SIG_DFL);
103 void mk_signal_thread_sigpipe_safe()
105 sigset_t set, old;
107 sigemptyset(&set);
108 sigaddset(&set, SIGPIPE);
109 pthread_sigmask(SIG_BLOCK, &set, &old);