windows: use/accept platform-specific signal for stopping agent (#26780)

On Windows, the `os.Process.Signal` method returns an error when sending
`os.Interrupt` (SIGINT) because it isn't implemented. This causes test servers
in the `testutil` packages to break on Windows. Use the platform specific
syscalls to generate the SIGINT instead.

The agent's signal handler also did not correctly handle the Ctrl-C because we
were masking os.Interrupt instead of SIGINT.

Fixes: https://github.com/hashicorp/nomad/issues/26775

Co-authored-by: Chris Roberts <croberts@hashicorp.com>
This commit is contained in:
Tim Gross
2025-09-17 11:32:20 -04:00
committed by GitHub
parent fca783c566
commit 4e75e99f1a
8 changed files with 127 additions and 13 deletions

View File

@@ -1081,7 +1081,7 @@ func (c *Command) handleSignals() int {
signalCh := make(chan os.Signal, 4)
defer signal.Stop(signalCh)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGPIPE)
signal.Notify(signalCh, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGPIPE)
// Signal readiness only once signal handlers are setup
sdSock, err := openNotify()
@@ -1120,7 +1120,7 @@ func (c *Command) handleSignals() int {
}
return c.terminateGracefully(signalCh, sdSock)
case os.Interrupt:
case syscall.SIGINT:
if !c.agent.GetConfig().LeaveOnInt {
return 1
}