fix: windows compilation (#1101)

Original pull request: https://code.forgejo.org/forgejo/runner/pulls/987
Fixes https://code.forgejo.org/forgejo/runner/issues/1032

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- bug fixes
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/1101): <!--number 1101 --><!--line 0 --><!--description Zml4OiB3aW5kb3dzIGNvbXBpbGF0aW9u-->fix: windows compilation<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1101
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Co-authored-by: volkmnv <volkmnv@noreply.code.forgejo.org>
Co-committed-by: volkmnv <volkmnv@noreply.code.forgejo.org>
This commit is contained in:
volkmnv 2025-10-24 07:00:43 +00:00 committed by earl-warren
parent 8a98a8a512
commit ea961a70c3
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
3 changed files with 24 additions and 2 deletions

View file

@ -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)
}
}

View file

@ -0,0 +1,9 @@
//go:build !windows
package artifactcache
import "syscall"
func suicide() error {
return syscall.Kill(syscall.Getpid(), syscall.SIGTERM)
}

View file

@ -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))
}