From 6be93d49f63d7dbb2dedf525204ad10ce3fd5453 Mon Sep 17 00:00:00 2001 From: will butler Date: Thu, 3 Oct 2019 10:27:37 -0700 Subject: [PATCH] dumps session on SIGUSR1 --- core/dump_nix.go | 23 +++++++++++++++++++++++ core/dump_windows.go | 7 +++++++ main.go | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 core/dump_nix.go create mode 100644 core/dump_windows.go diff --git a/core/dump_nix.go b/core/dump_nix.go new file mode 100644 index 0000000..ef08c7b --- /dev/null +++ b/core/dump_nix.go @@ -0,0 +1,23 @@ +// +build linux darwin + +package core + +import ( + "os" + "os/signal" + "syscall" +) + +func DumpSessionOnSig(sess *Session) { + sigChan := make(chan os.Signal, 1) + signal.Notify(sigChan, syscall.SIGUSR1) + for range sigChan { + sess.Lock() + err := sess.SaveToFile("aquatone_session.json") + if err != nil { + sess.Out.Error("Failed to write session file") + sess.Out.Debug("Err: %s", err.Error()) + } + sess.Unlock() + } +} \ No newline at end of file diff --git a/core/dump_windows.go b/core/dump_windows.go new file mode 100644 index 0000000..73f2086 --- /dev/null +++ b/core/dump_windows.go @@ -0,0 +1,7 @@ +// +build windows + +package core + +func DumpSessionOnSig(sess *Session) { + // not supported +} \ No newline at end of file diff --git a/main.go b/main.go index 649aaf0..29503e7 100644 --- a/main.go +++ b/main.go @@ -112,6 +112,8 @@ func main() { os.Exit(0) } + go core.DumpSessionOnSig(sess) + agents.NewTCPPortScanner().Register(sess) agents.NewURLPublisher().Register(sess) agents.NewURLRequester().Register(sess)