]>
git.ipfire.org Git - people/ms/suricata.git/blob - src/util-signal.c
1 /* Copyright (C) 2007-2012 Open Information Security Foundation
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
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.
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * \author Anoop Saldanha <anoopsaldanha@gmail.com>
24 #include "suricata-common.h"
26 #include "util-debug.h"
27 #include "util-signal.h"
29 int UtilSignalBlock(int signum
)
33 if (sigemptyset(&x
) < 0)
35 if (sigaddset(&x
, signum
) < 0)
37 /* don't use sigprocmask(), as it's undefined for
38 * multithreaded programs. Use phtread_sigmask().
40 if (pthread_sigmask(SIG_BLOCK
, &x
, NULL
) != 0)
46 int UtilSignalUnblock(int signum
)
50 if (sigemptyset(&x
) < 0)
52 if (sigaddset(&x
, signum
) < 0)
54 if (pthread_sigmask(SIG_UNBLOCK
, &x
, NULL
) != 0)
60 void UtilSignalHandlerSetup(int sig
, void (*handler
)(int))
65 struct sigaction action
;
66 memset(&action
, 0x00, sizeof(struct sigaction
));
68 action
.sa_handler
= handler
;
69 sigemptyset(&(action
.sa_mask
));
70 sigaddset(&(action
.sa_mask
),sig
);
72 sigaction(sig
, &action
, 0);
79 int UtilSignalIsHandler(int sig
, void (*handler
)(int))
81 struct sigaction action
;
82 memset(&action
, 0x00, sizeof(struct sigaction
));
84 sigaction(sig
, NULL
, &action
);
86 return (action
.sa_handler
== handler
);