Skip to content

Commit 3228f61

Browse files
authored
Merge pull request #14 from Songmu/sigcont
send SIGCONT after sending termination signal just to make sure
2 parents 1d775d2 + 9b7bd23 commit 3228f61

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

timeout_unix.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ func (tio *Timeout) getCmd() *exec.Cmd {
1919
}
2020

2121
func (tio *Timeout) terminate() error {
22-
syssig, ok := tio.signal().(syscall.Signal)
22+
sig := tio.signal()
23+
syssig, ok := sig.(syscall.Signal)
2324
if !ok || tio.Foreground {
24-
return tio.Cmd.Process.Signal(tio.signal())
25+
return tio.Cmd.Process.Signal(sig)
2526
}
26-
return syscall.Kill(-tio.Cmd.Process.Pid, syssig)
27+
err := syscall.Kill(-tio.Cmd.Process.Pid, syssig)
28+
if err != nil {
29+
return err
30+
}
31+
if syssig != syscall.SIGKILL && syssig != syscall.SIGCONT {
32+
return syscall.Kill(-tio.Cmd.Process.Pid, syscall.SIGCONT)
33+
}
34+
return nil
2735
}
2836

2937
func (tio *Timeout) killall() error {

timeout_unix_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// +build !windows
2+
3+
package timeout
4+
5+
import (
6+
"os/exec"
7+
"syscall"
8+
"testing"
9+
"time"
10+
)
11+
12+
func TestRunSimple_withStop(t *testing.T) {
13+
tio := &Timeout{
14+
Duration: 2 * time.Second,
15+
KillAfter: 1 * time.Second,
16+
Cmd: exec.Command(shellcmd, shellflag, "sleep 10"),
17+
}
18+
ch, err := tio.RunCommand()
19+
if err != nil {
20+
t.Errorf("err should be nil but: %s", err)
21+
}
22+
tio.Cmd.Process.Signal(syscall.SIGSTOP)
23+
st := <-ch
24+
25+
expect := 128 + 15
26+
if st.Code != expect {
27+
t.Errorf("exit code invalid. out: %d, expect: %d", st.Code, expect)
28+
}
29+
}

0 commit comments

Comments
 (0)