aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
authorBryan Mills <bcmills@google.com>2022-04-04 14:45:45 +0000
committerBryan Mills <bcmills@google.com>2022-04-04 15:12:26 +0000
commitf86f9a3038eb6db513a0ea36bc2af7a13b005e99 (patch)
treefa4ca2cbb3d7bd12b9bb2915febdabe488c60b9f /src/os
parent1af60b2f4990bffdd1b050ffd11e978578d1e38f (diff)
downloadgo-f86f9a3038eb6db513a0ea36bc2af7a13b005e99.tar.xz
Revert "os: add handling of os.Interrupt for windows"
This reverts CL 367495. Reason for revert: broke `x/tools` tests on Windows. Change-Id: Iab6b33259181c9520cf8db1e5b6edfeba763f974 Reviewed-on: https://go-review.googlesource.com/c/go/+/397997 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/os')
-rw-r--r--src/os/exec/exec_windows_test.go18
-rw-r--r--src/os/exec_posix.go4
-rw-r--r--src/os/exec_windows.go21
-rw-r--r--src/os/signal/signal_windows_test.go17
4 files changed, 26 insertions, 34 deletions
diff --git a/src/os/exec/exec_windows_test.go b/src/os/exec/exec_windows_test.go
index 503867f9c8..8e31e47190 100644
--- a/src/os/exec/exec_windows_test.go
+++ b/src/os/exec/exec_windows_test.go
@@ -7,7 +7,6 @@
package exec_test
import (
- "internal/testenv"
"io"
"os"
"os/exec"
@@ -55,20 +54,3 @@ func TestNoInheritHandles(t *testing.T) {
t.Fatalf("got exit code %d; want 88", exitError.ExitCode())
}
}
-
-func TestErrProcessDone(t *testing.T) {
- testenv.MustHaveGoBuild(t)
- // On Windows, ProcAttr cannot be empty
- p, err := os.StartProcess(testenv.GoToolPath(t), []string{""},
- &os.ProcAttr{Dir: "", Env: nil, Files: []*os.File{os.Stdin, os.Stdout, os.Stderr}, Sys: nil})
- if err != nil {
- t.Errorf("starting test process: %v", err)
- }
- _, err = p.Wait()
- if err != nil {
- t.Errorf("Wait: %v", err)
- }
- if got := p.Signal(os.Kill); got != os.ErrProcessDone {
- t.Fatalf("got %v want %v", got, os.ErrProcessDone)
- }
-}
diff --git a/src/os/exec_posix.go b/src/os/exec_posix.go
index 3dc18a84bd..e1e7d53a27 100644
--- a/src/os/exec_posix.go
+++ b/src/os/exec_posix.go
@@ -15,7 +15,9 @@ import (
// The only signal values guaranteed to be present in the os package on all
// systems are os.Interrupt (send the process an interrupt) and os.Kill (force
-// the process to exit).
+// the process to exit). On Windows, sending os.Interrupt to a process with
+// os.Process.Signal is not implemented; it will return an error instead of
+// sending a signal.
var (
Interrupt Signal = syscall.SIGINT
Kill Signal = syscall.SIGKILL
diff --git a/src/os/exec_windows.go b/src/os/exec_windows.go
index bc232e0a00..239bed198f 100644
--- a/src/os/exec_windows.go
+++ b/src/os/exec_windows.go
@@ -47,14 +47,13 @@ func (p *Process) wait() (ps *ProcessState, err error) {
func (p *Process) signal(sig Signal) error {
handle := atomic.LoadUintptr(&p.handle)
+ if handle == uintptr(syscall.InvalidHandle) {
+ return syscall.EINVAL
+ }
if p.done() {
return ErrProcessDone
}
- s, ok := sig.(syscall.Signal)
- if !ok {
- return syscall.EWINDOWS
- }
- if s == syscall.SIGKILL {
+ if sig == Kill {
var terminationHandle syscall.Handle
e := syscall.DuplicateHandle(^syscall.Handle(0), syscall.Handle(handle), ^syscall.Handle(0), &terminationHandle, syscall.PROCESS_TERMINATE, false, 0)
if e != nil {
@@ -62,17 +61,11 @@ func (p *Process) signal(sig Signal) error {
}
runtime.KeepAlive(p)
defer syscall.CloseHandle(terminationHandle)
- e = syscall.TerminateProcess(terminationHandle, 1)
+ e = syscall.TerminateProcess(syscall.Handle(terminationHandle), 1)
return NewSyscallError("TerminateProcess", e)
}
- if s == syscall.SIGINT {
- e := windows.GenerateConsoleCtrlEvent(syscall.CTRL_BREAK_EVENT, uint32(p.Pid))
- if e != nil {
- return NewSyscallError("GenerateConsoleCtrlEvent", e)
- }
- return nil
- }
- return syscall.EWINDOWS
+ // TODO(rsc): Handle Interrupt too?
+ return syscall.Errno(syscall.EWINDOWS)
}
func (p *Process) release() error {
diff --git a/src/os/signal/signal_windows_test.go b/src/os/signal/signal_windows_test.go
index 89c072ca6e..9b14551572 100644
--- a/src/os/signal/signal_windows_test.go
+++ b/src/os/signal/signal_windows_test.go
@@ -15,6 +15,21 @@ import (
"time"
)
+func sendCtrlBreak(t *testing.T, pid int) {
+ d, e := syscall.LoadDLL("kernel32.dll")
+ if e != nil {
+ t.Fatalf("LoadDLL: %v\n", e)
+ }
+ p, e := d.FindProc("GenerateConsoleCtrlEvent")
+ if e != nil {
+ t.Fatalf("FindProc: %v\n", e)
+ }
+ r, _, e := p.Call(syscall.CTRL_BREAK_EVENT, uintptr(pid))
+ if r == 0 {
+ t.Fatalf("GenerateConsoleCtrlEvent: %v\n", e)
+ }
+}
+
func TestCtrlBreak(t *testing.T) {
// create source file
const source = `
@@ -75,7 +90,7 @@ func main() {
}
go func() {
time.Sleep(1 * time.Second)
- cmd.Process.Signal(os.Interrupt)
+ sendCtrlBreak(t, cmd.Process.Pid)
}()
err = cmd.Wait()
if err != nil {