libs/lucid-http: use SERVER_ADDR as fallback
[project/luci.git] / libs / lucittpd / src / lib / signal.c
1 /*
2  *   This program is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License as published by
4  *   the Free Software Foundation; either version 2 of the License, or
5  *   (at your option) any later version.
6  *
7  *   This program is distributed in the hope that it will be useful,
8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *   GNU General Public License for more details.
11  *
12  *   You should have received a copy of the GNU General Public License
13  *   along with this program; if not, write to the Free Software
14  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15  *
16  *   Provided by fon.com
17  *   Copyright (C) 2008 John Crispin <blogic@openwrt.org> 
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <signal.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
26
27 #include <lib/log.h>
28
29 void handler_INT(int signo)
30 {
31         log_printf("away we go\n");
32         exit(0);
33 }
34
35 void handler_CHLD(int signo)
36 {
37         while(waitpid(-1, NULL, WNOHANG) > 0);
38 }
39
40 void setup_signals(void)
41 {
42         struct sigaction s1, s2, s3;
43         s1.sa_handler = handler_INT;
44         s1.sa_flags = 0;
45         sigaction(SIGINT, &s1, NULL);
46         s2.sa_handler = handler_INT;
47         s2.sa_flags = 0;
48         sigaction(SIGTERM, &s2, NULL);
49         s3.sa_handler = handler_CHLD;
50         s3.sa_flags = SA_RESTART;
51         sigaction(SIGCHLD, &s3, NULL);
52 }