-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: signal SIGINT/SIGTERM in windows correctly
emissary tries to send a signal but `os/Process.Kill` only supports sending SIGKILL and returns an error for all other cases. Using code found in hcsshim this changes signal handling in emissary for windows by translating SIGINT and SIGTERM to their appropriate windows signal and sending it to the process. Signed-off-by: Michael Weibel <michael@helio.exchange>
- Loading branch information
Showing
3 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//go:build windows | ||
|
||
package os_specific | ||
|
||
import ( | ||
"bytes" | ||
"os/exec" | ||
"sync" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestKill(t *testing.T) { | ||
shell := "pwsh.exe" | ||
cmd := exec.Command(shell, "-c", `echo "running"; while(1) { sleep 600000 }`) | ||
var stdout bytes.Buffer | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stdout | ||
|
||
_, err := StartCommand(cmd) | ||
require.NoError(t, err) | ||
|
||
var wg sync.WaitGroup | ||
go func() { | ||
wg.Add(1) | ||
defer wg.Done() | ||
|
||
err = cmd.Wait() | ||
// we'll get an exit code | ||
assert.Error(t, err) | ||
}() | ||
|
||
// Wait for echo to have run before calling Kill | ||
time.Sleep(500 * time.Millisecond) | ||
|
||
err = Kill(cmd.Process.Pid, syscall.SIGTERM) | ||
require.NoError(t, err) | ||
|
||
wg.Wait() | ||
|
||
expected := "running\r\n" | ||
assert.Equal(t, expected, stdout.String()) | ||
} |