summaryrefslogtreecommitdiff
path: root/die.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-04-20 12:43:08 +0300
committerTobias Klauser <tklauser@distanz.ch>2015-04-21 16:44:15 +0200
commitdce80974dcd2114ebb4a3ed3060d4d636cbb9d1d (patch)
tree9fc6c6bf864695f06b98dbb3ef4c18d1105604b2 /die.c
parent9278bb65e810156ed1074e693fce14e7ecf145e8 (diff)
netsniff-ng: Delete rfmon mac80211 device in case of panic
netsniff-ng does not delete created rfmon device in case of panic (for example - bad pcap filter expression), so added ability to add callback func when panic will be happen and delete rfmon device. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'die.c')
-rw-r--r--die.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/die.c b/die.c
new file mode 100644
index 0000000..4c0014d
--- /dev/null
+++ b/die.c
@@ -0,0 +1,31 @@
+/*
+ * Subject to the GPL, version 2.
+ */
+
+#include "xmalloc.h"
+
+struct panic_func {
+ void *arg;
+ void (*on_panic)(void *arg);
+ struct panic_func *next;
+};
+
+static struct panic_func *panic_funcs;
+
+void panic_func_add(void (*on_panic)(void *arg), void *arg)
+{
+ struct panic_func *handler = xmallocz(sizeof(*handler));
+
+ handler->arg = arg;
+ handler->on_panic = on_panic;
+ handler->next = panic_funcs;
+ panic_funcs = handler;
+};
+
+void call_on_panic_funcs(void)
+{
+ struct panic_func *it;
+
+ for (it = panic_funcs; it; it = it->next)
+ it->on_panic(it->arg);
+}