Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1530)

Delta Between Two Patch Sets: src/pkg/os/exec_windows.go

Issue 4029053: code review 4029053: os: implement new Process api (Closed)
Left Patch Set: Created 13 years, 1 month ago
Right Patch Set: diff -r 75ebb1ad8e98 https://go.googlecode.com/hg/ Created 13 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/os/exec_unix.go ('k') | src/pkg/os/os_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package os 5 package os
6 6
7 import "syscall" 7 import (
8 » "runtime"
9 » "syscall"
10 )
8 11
9 func (p *Process) Wait(options int) (w *Waitmsg, err Error) { 12 func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
10 s, e := syscall.WaitForSingleObject(int32(p.handle), syscall.INFINITE) 13 s, e := syscall.WaitForSingleObject(int32(p.handle), syscall.INFINITE)
11 switch s { 14 switch s {
12 case syscall.WAIT_OBJECT_0: 15 case syscall.WAIT_OBJECT_0:
13 break 16 break
14 case syscall.WAIT_FAILED: 17 case syscall.WAIT_FAILED:
15 return nil, NewSyscallError("WaitForSingleObject", e) 18 return nil, NewSyscallError("WaitForSingleObject", e)
16 default: 19 default:
17 return nil, ErrorString("os: unexpected result from WaitForSingl eObject") 20 return nil, ErrorString("os: unexpected result from WaitForSingl eObject")
18 } 21 }
19 var ec uint32 22 var ec uint32
20 if ok, e := syscall.GetExitCodeProcess(uint32(p.handle), &ec); !ok { 23 if ok, e := syscall.GetExitCodeProcess(uint32(p.handle), &ec); !ok {
21 return nil, NewSyscallError("GetExitCodeProcess", e) 24 return nil, NewSyscallError("GetExitCodeProcess", e)
22 } 25 }
23 return &Waitmsg{p.Pid, syscall.WaitStatus{s, ec}, new(syscall.Rusage)}, nil 26 return &Waitmsg{p.Pid, syscall.WaitStatus{s, ec}, new(syscall.Rusage)}, nil
24 } 27 }
25 28
26 func (p *Process) Close() Error { 29 func (p *Process) Release() Error {
27 » if p.handle <= 0 { 30 » if p.handle == -1 {
28 » » return ErrorString("os: invalid use of Process.Close") 31 » » return EINVAL
29 } 32 }
30 if ok, e := syscall.CloseHandle(int32(p.handle)); !ok { 33 if ok, e := syscall.CloseHandle(int32(p.handle)); !ok {
31 return NewSyscallError("CloseHandle", e) 34 return NewSyscallError("CloseHandle", e)
32 } 35 }
33 » p.handle = 0 36 » p.handle = -1
37 » // no need for a finalizer anymore
38 » runtime.SetFinalizer(p, nil)
34 return nil 39 return nil
35 } 40 }
36 41
37 func FindProcess(pid int) (p *Process, err Error) { 42 func FindProcess(pid int) (p *Process, err Error) {
38 const da = syscall.STANDARD_RIGHTS_READ | 43 const da = syscall.STANDARD_RIGHTS_READ |
39 syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE 44 syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE
40 h, e := syscall.OpenProcess(da, false, uint32(pid)) 45 h, e := syscall.OpenProcess(da, false, uint32(pid))
41 if e != 0 { 46 if e != 0 {
42 return nil, NewSyscallError("OpenProcess", e) 47 return nil, NewSyscallError("OpenProcess", e)
43 } 48 }
44 » return &Process{pid, int(h)}, nil 49 » return newProcess(pid, int(h)), nil
45 } 50 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b