From a0c56d2a04cc956e024cd478531a9909824e42ce Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Fri, 13 Jun 2025 18:20:18 +0200 Subject: only use SIGUSR1 on unix platforms --- hydra.go | 10 +--------- os_nonunix.go | 7 +++++++ os_unix.go | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 os_nonunix.go create mode 100644 os_unix.go diff --git a/hydra.go b/hydra.go index 2d5d9e3..c38e732 100644 --- a/hydra.go +++ b/hydra.go @@ -5,7 +5,6 @@ import ( "github.com/yuin/gopher-lua" "os" "os/signal" - "runtime/pprof" "syscall" "time" ) @@ -73,14 +72,7 @@ func main() { signalChannel = make(chan os.Signal, 1) signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) - go func() { - ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGUSR1) - for { - <-ch - pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) - } - }() + backtrace_listen() l := lua.NewState() defer l.Close() diff --git a/os_nonunix.go b/os_nonunix.go new file mode 100644 index 0000000..c5a7133 --- /dev/null +++ b/os_nonunix.go @@ -0,0 +1,7 @@ +//go:build !linux && !openbsd && !freebsd && !netbsd && !dragonfly && !solaris && !darwin && !aix + +package main + +func backtrace_listen() { + +} diff --git a/os_unix.go b/os_unix.go new file mode 100644 index 0000000..5afe392 --- /dev/null +++ b/os_unix.go @@ -0,0 +1,21 @@ +//go:build linux || openbsd || freebsd || netbsd || dragonfly || solaris || darwin || aix + +package main + +import ( + "os" + "os/signal" + "runtime/pprof" + "syscall" +) + +func backtrace_listen() { + go func() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGUSR1) + for { + <-ch + pprof.Lookup("goroutine").WriteTo(os.Stdout, 1) + } + }() +} -- cgit v1.2.3