Imported Upstream version 2.5.1
[ossec-hids.git] / src / shared / sig_op.c
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11
12
13 /* Functions to handle signal manipulation
14  */
15
16 #ifndef WIN32
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <signal.h>
21
22 #include "sig_op.h"
23 #include "file_op.h"
24 #include "debug_op.h"
25
26 #include "error_messages/error_messages.h"
27
28 char *pidfile = NULL;
29
30 void HandleSIG()
31 {
32     merror(SIGNAL_RECV, pidfile);
33     
34     DeletePID(pidfile);
35     
36     exit(1);
37 }
38
39
40 /* To avoid client-server communication problems */
41 void HandleSIGPIPE()
42 {
43     return;
44 }
45
46 void StartSIG(char *process_name)
47 {
48     /* Signal Manipulation
49        go to HandleSIG() */
50     pidfile = process_name;
51
52     signal(SIGHUP, SIG_IGN);    
53     signal(SIGINT, HandleSIG);
54     signal(SIGQUIT, HandleSIG);
55     signal(SIGTERM, HandleSIG);
56     signal(SIGALRM, HandleSIG);
57     signal(SIGPIPE, HandleSIGPIPE);
58 }
59
60 void StartSIG2(char *process_name, void (*func)(int))
61 {
62     pidfile = process_name;
63
64     signal(SIGHUP, SIG_IGN);
65     signal(SIGINT, func);
66     signal(SIGQUIT, func);
67     signal(SIGTERM, func);
68     signal(SIGALRM, func);
69     signal(SIGPIPE, HandleSIGPIPE);
70 }
71
72 #endif
73 /* EOF */