Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
d53385fd
Commit
d53385fd
authored
Jul 11, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os: don't permit Process.Signal after a successful Wait
R=dsymonds, rsc CC=golang-dev
https://golang.org/cl/4689043
parent
d1f4e0d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
2 deletions
+20
-2
src/pkg/os/exec.go
src/pkg/os/exec.go
+2
-1
src/pkg/os/exec_unix.go
src/pkg/os/exec_unix.go
+6
-0
src/pkg/os/exec_windows.go
src/pkg/os/exec_windows.go
+4
-0
src/pkg/os/os_test.go
src/pkg/os/os_test.go
+8
-1
No files found.
src/pkg/os/exec.go
View file @
d53385fd
...
...
@@ -13,10 +13,11 @@ import (
type
Process
struct
{
Pid
int
handle
int
done
bool
// process has been successfuly waited on
}
func
newProcess
(
pid
,
handle
int
)
*
Process
{
p
:=
&
Process
{
pid
,
handle
}
p
:=
&
Process
{
Pid
:
pid
,
handle
:
handle
}
runtime
.
SetFinalizer
(
p
,
(
*
Process
)
.
Release
)
return
p
}
...
...
src/pkg/os/exec_unix.go
View file @
d53385fd
...
...
@@ -38,6 +38,9 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
if
e
!=
0
{
return
nil
,
NewSyscallError
(
"wait"
,
e
)
}
if
options
&
WSTOPPED
==
0
{
p
.
done
=
true
}
w
=
new
(
Waitmsg
)
w
.
Pid
=
pid1
w
.
WaitStatus
=
status
...
...
@@ -47,6 +50,9 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
// Signal sends a signal to the Process.
func
(
p
*
Process
)
Signal
(
sig
Signal
)
Error
{
if
p
.
done
{
return
NewError
(
"os: process already finished"
)
}
if
e
:=
syscall
.
Kill
(
p
.
Pid
,
int
(
sig
.
(
UnixSignal
)));
e
!=
0
{
return
Errno
(
e
)
}
...
...
src/pkg/os/exec_windows.go
View file @
d53385fd
...
...
@@ -24,11 +24,15 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
if
e
!=
0
{
return
nil
,
NewSyscallError
(
"GetExitCodeProcess"
,
e
)
}
p
.
done
=
true
return
&
Waitmsg
{
p
.
Pid
,
syscall
.
WaitStatus
{
s
,
ec
},
new
(
syscall
.
Rusage
)},
nil
}
// Signal sends a signal to the Process.
func
(
p
*
Process
)
Signal
(
sig
Signal
)
Error
{
if
p
.
done
{
return
NewError
(
"os: process already finished"
)
}
switch
sig
.
(
UnixSignal
)
{
case
SIGKILL
:
e
:=
syscall
.
TerminateProcess
(
syscall
.
Handle
(
p
.
handle
),
1
)
...
...
src/pkg/os/os_test.go
View file @
d53385fd
...
...
@@ -895,7 +895,14 @@ func run(t *testing.T, cmd []string) string {
var
b
bytes
.
Buffer
io
.
Copy
(
&
b
,
r
)
p
.
Wait
(
0
)
_
,
err
=
p
.
Wait
(
0
)
if
err
!=
nil
{
t
.
Fatalf
(
"run hostname Wait: %v"
,
err
)
}
err
=
p
.
Kill
()
if
err
==
nil
{
t
.
Errorf
(
"expected an error from Kill running 'hostname'"
)
}
output
:=
b
.
String
()
if
n
:=
len
(
output
);
n
>
0
&&
output
[
n
-
1
]
==
'\n'
{
output
=
output
[
0
:
n
-
1
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment