From: Vadim Kochan <[email protected]>

Fixed case when rfmon mac80211 created device remains
after trafgen failed (for ex. - incorrect cfg file),
so just delete it when panic occured.

Also made panic handlers invoking per process and only once.

Signed-off-by: Vadim Kochan <[email protected]>
---
 die.c     | 27 ++++++++++++++++++---------
 trafgen.c |  6 ++++++
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/die.c b/die.c
index 4c0014d..523107e 100644
--- a/die.c
+++ b/die.c
@@ -4,28 +4,37 @@
 
 #include "xmalloc.h"
 
-struct panic_func {
+struct panic_handler {
        void *arg;
+       pid_t pid;
+       bool is_enabled;
        void (*on_panic)(void *arg);
-       struct panic_func *next;
+       struct panic_handler *next;
 };
 
-static struct panic_func *panic_funcs;
+static struct panic_handler *panic_handlers;
 
 void panic_func_add(void (*on_panic)(void *arg), void *arg)
 {
-       struct panic_func *handler = xmallocz(sizeof(*handler));
+       struct panic_handler *handler = xmallocz(sizeof(*handler));
 
        handler->arg            = arg;
+       handler->pid            = getpid();
+       handler->is_enabled     = true;
        handler->on_panic       = on_panic;
-       handler->next           = panic_funcs;
-       panic_funcs             = handler;
+       handler->next           = panic_handlers;
+       panic_handlers          = handler;
 };
 
 void call_on_panic_funcs(void)
 {
-       struct panic_func *it;
+       struct panic_handler *it;
+       pid_t pid = getpid();
 
-       for (it = panic_funcs; it; it = it->next)
-               it->on_panic(it->arg);
+       for (it = panic_handlers; it; it = it->next) {
+               if (it->pid == pid && it->is_enabled) {
+                       it->is_enabled = false;
+                       it->on_panic(it->arg);
+               }
+       }
 }
diff --git a/trafgen.c b/trafgen.c
index deef1f2..4a9fde5 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -852,6 +852,11 @@ static unsigned int generate_srand_seed(void)
        return _seed;
 }
 
+static void on_panic_del_rfmon(void *arg)
+{
+       leave_rfmon_mac80211(arg);
+}
+
 int main(int argc, char **argv)
 {
        bool slow = false, invoke_cpp = false, reseed = true, cpustats = true;
@@ -1067,6 +1072,7 @@ int main(int argc, char **argv)
                xfree(ctx.device);
 
                enter_rfmon_mac80211(ctx.device_trans, &ctx.device);
+               panic_func_add(on_panic_del_rfmon, ctx.device);
                sleep(0);
        }
 
-- 
2.3.1

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to