add windows support (#867)
* add windows support * add windows support * add windows support Co-authored-by: 78552423@qq.com <chenyz0812>
This commit is contained in:
parent
f8482601a8
commit
f009c43878
|
@ -0,0 +1,33 @@
|
||||||
|
// +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris plan9
|
||||||
|
|
||||||
|
// Unix environment variables.
|
||||||
|
|
||||||
|
package sys
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WrapTimeout(cmd *exec.Cmd, timeout time.Duration) (error, bool) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
done := make(chan error)
|
||||||
|
go func() {
|
||||||
|
done <- cmd.Wait()
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-time.After(timeout):
|
||||||
|
go func() {
|
||||||
|
<-done // allow goroutine to exit
|
||||||
|
}()
|
||||||
|
|
||||||
|
// IMPORTANT: cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} is necessary before cmd.Start()
|
||||||
|
err = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||||
|
return err, true
|
||||||
|
case err = <-done:
|
||||||
|
return err, false
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Windows environment variables.
|
||||||
|
|
||||||
|
package sys
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WrapTimeout(cmd *exec.Cmd, timeout time.Duration) (error, bool) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
done := make(chan error)
|
||||||
|
go func() {
|
||||||
|
done <- cmd.Wait()
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-time.After(timeout):
|
||||||
|
go func() {
|
||||||
|
<-done // allow goroutine to exit
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = cmd.Process.Signal(syscall.SIGKILL)
|
||||||
|
return err, true
|
||||||
|
case err = <-done:
|
||||||
|
return err, false
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,9 +16,9 @@ import (
|
||||||
"github.com/toolkits/pkg/file"
|
"github.com/toolkits/pkg/file"
|
||||||
"github.com/toolkits/pkg/logger"
|
"github.com/toolkits/pkg/logger"
|
||||||
"github.com/toolkits/pkg/runner"
|
"github.com/toolkits/pkg/runner"
|
||||||
"github.com/toolkits/pkg/sys"
|
|
||||||
|
|
||||||
"github.com/didi/nightingale/v5/src/models"
|
"github.com/didi/nightingale/v5/src/models"
|
||||||
|
"github.com/didi/nightingale/v5/src/pkg/sys"
|
||||||
"github.com/didi/nightingale/v5/src/server/config"
|
"github.com/didi/nightingale/v5/src/server/config"
|
||||||
"github.com/didi/nightingale/v5/src/server/memsto"
|
"github.com/didi/nightingale/v5/src/server/memsto"
|
||||||
"github.com/didi/nightingale/v5/src/storage"
|
"github.com/didi/nightingale/v5/src/storage"
|
||||||
|
|
Loading…
Reference in New Issue