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