Skip to content

Commit ce6c619

Browse files
committed
Merge branch 'signals' into go118
2 parents 1ab64b3 + 84963ec commit ce6c619

File tree

6 files changed

+98
-6
lines changed

6 files changed

+98
-6
lines changed

src/os/exec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ func (p *Process) Wait() (*ProcessState, error) {
4949
func (p *Process) Kill() error {
5050
return ErrNotImplemented
5151
}
52+
53+
func (p *Process) Signal(sig Signal) error {
54+
return ErrNotImplemented
55+
}

src/os/exec_posix.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package os
6+
7+
//go:build aix || darwin || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris || windows
8+
// +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris windows
9+
10+
import (
11+
"syscall"
12+
)
13+
14+
// The only signal values guaranteed to be present in the os package on all
15+
// systems are os.Interrupt (send the process an interrupt) and os.Kill (force
16+
// the process to exit). On Windows, sending os.Interrupt to a process with
17+
// os.Process.Signal is not implemented; it will return an error instead of
18+
// sending a signal.
19+
var (
20+
Interrupt Signal = syscall.SIGINT
21+
Kill Signal = syscall.SIGKILL
22+
)

src/syscall/syscall_libc_darwin.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package syscall
55

66
import (
7+
"internal/itoa"
78
"unsafe"
89
)
910

@@ -82,6 +83,20 @@ const (
8283
SIGTERM Signal = 0xf
8384
)
8485

86+
func (s Signal) Signal() {}
87+
88+
func (s Signal) String() string {
89+
if 0 <= s && int(s) < len(signals) {
90+
str := signals[s]
91+
if str != "" {
92+
return str
93+
}
94+
}
95+
return "signal " + itoa.Itoa(int(s))
96+
}
97+
98+
var signals = [...]string{}
99+
85100
const (
86101
Stdin = 0
87102
Stdout = 1

src/syscall/syscall_libc_nintendoswitch.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
package syscall
55

6+
import (
7+
"internal/itoa"
8+
)
9+
610
// A Signal is a number describing a process signal.
711
// It implements the os.Signal interface.
812
type Signal int
@@ -17,6 +21,20 @@ const (
1721
SIGTERM
1822
)
1923

24+
func (s Signal) Signal() {}
25+
26+
func (s Signal) String() string {
27+
if 0 <= s && int(s) < len(signals) {
28+
str := signals[s]
29+
if str != "" {
30+
return str
31+
}
32+
}
33+
return "signal " + itoa.Itoa(int(s))
34+
}
35+
36+
var signals = [...]string{}
37+
2038
// File system
2139

2240
const (

src/syscall/syscall_libc_wasi.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package syscall
55

66
import (
7+
"internal/itoa"
78
"unsafe"
89
)
910

@@ -12,14 +13,28 @@ import (
1213
type Signal int
1314

1415
const (
15-
SIGCHLD = 16
16-
SIGINT = 2
17-
SIGKILL = 9
18-
SIGTRAP = 5
19-
SIGQUIT = 3
20-
SIGTERM = 15
16+
SIGCHLD Signal = 16
17+
SIGINT Signal = 2
18+
SIGKILL Signal = 9
19+
SIGTRAP Signal = 5
20+
SIGQUIT Signal = 3
21+
SIGTERM Signal = 15
2122
)
2223

24+
func (s Signal) Signal() {}
25+
26+
func (s Signal) String() string {
27+
if 0 <= s && int(s) < len(signals) {
28+
str := signals[s]
29+
if str != "" {
30+
return str
31+
}
32+
}
33+
return "signal " + itoa.Itoa(int(s))
34+
}
35+
36+
var signals = [...]string{}
37+
2338
const (
2439
Stdin = 0
2540
Stdout = 1

src/syscall/syscall_nonhosted.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
package syscall
55

6+
import (
7+
"internal/itoa"
8+
)
9+
610
// Most code here has been copied from the Go sources:
711
// https://github.com/golang/go/blob/go1.12/src/syscall/syscall_js.go
812
// It has the following copyright note:
@@ -25,6 +29,20 @@ const (
2529
SIGTERM
2630
)
2731

32+
func (s Signal) Signal() {}
33+
34+
func (s Signal) String() string {
35+
if 0 <= s && int(s) < len(signals) {
36+
str := signals[s]
37+
if str != "" {
38+
return str
39+
}
40+
}
41+
return "signal " + itoa.Itoa(int(s))
42+
}
43+
44+
var signals = [...]string{}
45+
2846
// File system
2947

3048
const (

0 commit comments

Comments
 (0)