forked from ossec/ossec-hids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sig_op.c
68 lines (51 loc) · 1.32 KB
/
sig_op.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright (C) 2009 Trend Micro Inc.
* All right reserved.
*
* This program is a free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License (version 2) as published by the FSF - Free Software
* Foundation
*/
/* Functions to handle signal manipulation */
#ifndef WIN32
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include "sig_op.h"
#include "file_op.h"
#include "debug_op.h"
#include "error_messages/error_messages.h"
static const char *pidfile = NULL;
void HandleSIG(int sig)
{
merror(SIGNAL_RECV, pidfile, sig, strsignal(sig));
DeletePID(pidfile);
exit(1);
}
/* To avoid client-server communication problems */
void HandleSIGPIPE(__attribute__((unused)) int sig)
{
return;
}
void StartSIG(const char *process_name)
{
pidfile = process_name;
signal(SIGHUP, SIG_IGN);
signal(SIGINT, HandleSIG);
signal(SIGQUIT, HandleSIG);
signal(SIGTERM, HandleSIG);
signal(SIGALRM, HandleSIG);
signal(SIGPIPE, HandleSIGPIPE);
}
void StartSIG2(const char *process_name, void (*func)(int))
{
pidfile = process_name;
signal(SIGHUP, SIG_IGN);
signal(SIGINT, func);
signal(SIGQUIT, func);
signal(SIGTERM, func);
signal(SIGALRM, func);
signal(SIGPIPE, HandleSIGPIPE);
}
#endif /* !WIN32 */