From 216129b6b6971a6eea97e11a7f7af855cd5faf9c Mon Sep 17 00:00:00 2001 From: Ansis Date: Thu, 11 Sep 2025 17:56:11 +0200 Subject: [PATCH] Moved suicide code out to platform specific files --- act/artifactcache/handler.go | 3 +-- act/artifactcache/handler_linux.go | 7 +++++++ act/artifactcache/handler_windows.go | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 act/artifactcache/handler_linux.go create mode 100644 act/artifactcache/handler_windows.go diff --git a/act/artifactcache/handler.go b/act/artifactcache/handler.go index 0b574397..a4be8800 100644 --- a/act/artifactcache/handler.go +++ b/act/artifactcache/handler.go @@ -9,7 +9,6 @@ import ( "net/http" "strconv" "strings" - "syscall" "time" "github.com/julienschmidt/httprouter" @@ -25,7 +24,7 @@ const ( var fatal = func(logger logrus.FieldLogger, err error) { logger.Errorf("unrecoverable error in the cache: %v", err) - if err := syscall.Kill(syscall.Getpid(), syscall.SIGTERM); err != nil { + if err := suicide(); err != nil { logger.Errorf("unrecoverable error in the cache: failed to send the TERM signal to shutdown the daemon %v", err) } } diff --git a/act/artifactcache/handler_linux.go b/act/artifactcache/handler_linux.go new file mode 100644 index 00000000..a6c5534d --- /dev/null +++ b/act/artifactcache/handler_linux.go @@ -0,0 +1,7 @@ +package artifactcache + +import "syscall" + +func suicide() error { + return syscall.Kill(syscall.Getpid(), syscall.SIGTERM) +} diff --git a/act/artifactcache/handler_windows.go b/act/artifactcache/handler_windows.go new file mode 100644 index 00000000..29b250a9 --- /dev/null +++ b/act/artifactcache/handler_windows.go @@ -0,0 +1,13 @@ +package artifactcache + +import "syscall" + +func suicide() error { + handle, err := syscall.GetCurrentProcess() + + if err != nil { + return err + } + + return syscall.TerminateProcess(handle, uint32(syscall.SIGTERM)) +}