summaryrefslogtreecommitdiff
path: root/sig.c
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-06-04 11:38:17 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-06-04 11:38:17 +0200
commit57968a8ab19b45b5d128656f6bed2581aee2ef22 (patch)
tree48e9c560f6f9ffab29debf2cffaaad1acd331c55 /sig.c
parentab9d73629872a474d9194177fa4c9c8cdabe9a44 (diff)
sig: add signal handling functions
Add an extra file for signal handling functions. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'sig.c')
-rw-r--r--sig.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/sig.c b/sig.c
new file mode 100644
index 0000000..2b5ab5e
--- /dev/null
+++ b/sig.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <signal.h>
+
+#include "sig.h"
+
+void register_signal(int signal, void (*handler)(int))
+{
+ sigset_t block_mask;
+ struct sigaction saction;
+
+ sigfillset(&block_mask);
+
+ saction.sa_handler = handler;
+ saction.sa_mask = block_mask;
+ saction.sa_flags = SA_RESTART;
+
+ sigaction(signal, &saction, NULL);
+}
+
+void register_signal_f(int signal, void (*handler)(int), int flags)
+{
+ sigset_t block_mask;
+ struct sigaction saction;
+
+ sigfillset(&block_mask);
+
+ saction.sa_handler = handler;
+ saction.sa_mask = block_mask;
+ saction.sa_flags = flags;
+
+ sigaction(signal, &saction, NULL);
+}