From ea961a70c3729da474d7069f065f2967840a291c Mon Sep 17 00:00:00 2001 From: volkmnv Date: Fri, 24 Oct 2025 07:00:43 +0000 Subject: [PATCH] fix: windows compilation (#1101) Original pull request: https://code.forgejo.org/forgejo/runner/pulls/987 Fixes https://code.forgejo.org/forgejo/runner/issues/1032 - bug fixes - [PR](https://code.forgejo.org/forgejo/runner/pulls/1101): fix: windows compilation Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1101 Reviewed-by: earl-warren Co-authored-by: volkmnv Co-committed-by: volkmnv --- act/artifactcache/handler.go | 3 +-- act/artifactcache/utils.go | 9 +++++++++ act/artifactcache/utils_windows.go | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 act/artifactcache/utils.go create mode 100644 act/artifactcache/utils_windows.go diff --git a/act/artifactcache/handler.go b/act/artifactcache/handler.go index 29ff61e3..cbc58d8f 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/utils.go b/act/artifactcache/utils.go new file mode 100644 index 00000000..37274a4e --- /dev/null +++ b/act/artifactcache/utils.go @@ -0,0 +1,9 @@ +//go:build !windows + +package artifactcache + +import "syscall" + +func suicide() error { + return syscall.Kill(syscall.Getpid(), syscall.SIGTERM) +} diff --git a/act/artifactcache/utils_windows.go b/act/artifactcache/utils_windows.go new file mode 100644 index 00000000..90b0f112 --- /dev/null +++ b/act/artifactcache/utils_windows.go @@ -0,0 +1,14 @@ +//go:build windows + +package artifactcache + +import "syscall" + +func suicide() error { + handle, err := syscall.GetCurrentProcess() + if err != nil { + return err + } + + return syscall.TerminateProcess(handle, uint32(syscall.SIGTERM)) +}