]> Cypherpunks repositories - gostls13.git/commitdiff
os: drop the Wait function and the options to Process.Wait
authorRob Pike <r@golang.org>
Mon, 20 Feb 2012 04:36:08 +0000 (15:36 +1100)
committerRob Pike <r@golang.org>
Mon, 20 Feb 2012 04:36:08 +0000 (15:36 +1100)
They are portability problems and the options are almost always zero in practice anyway.

R=golang-dev, dsymonds, r, bradfitz
CC=golang-dev
https://golang.org/cl/5688046

12 files changed:
doc/go1.html
doc/go1.tmpl
src/cmd/cgo/util.go
src/cmd/fix/oswait.go [new file with mode: 0644]
src/cmd/fix/oswait_test.go [new file with mode: 0644]
src/cmd/godoc/main.go
src/pkg/os/exec/exec.go
src/pkg/os/exec_plan9.go
src/pkg/os/exec_posix.go
src/pkg/os/exec_unix.go
src/pkg/os/exec_windows.go
src/pkg/os/os_test.go

index 04726069cd5cee3b18ab97346a53f1ef96e55722..f7a33c4038c43e8bf210e2e12815ebb972cecb6d 100644 (file)
@@ -8,7 +8,7 @@
 
 
 <!-- Center the tables, and disable the 1995-era 3D borders -->
-<style>
+<style type="text/css">
 table { margin-left: auto; margin-right: auto; border-style: none; }
 hr { border-style: none; border-top: 1px solid black; }
 </style>
@@ -1460,9 +1460,20 @@ use <a href="/pkg/os/#Environ"><code>os.Environ</code></a> or
 <a href="/pkg/syscall/#Getenv"><code>syscall.Getenv</code></a>.
 </p>
 
+
+<p>
+The <a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a> method has
+dropped its option argument and the associated constants are gone
+from the package.
+Also, the function <code>Wait</code> is gone; only the method of
+the <code>Process</code> type persists.
+</p>
+
 <p>
 <em>Updating</em>:
-Affected code will be caught by the compiler and must be updated by hand.
+Gofix will rewrite calls to <code>os.Wait</code> with an explicit zero
+argument, dropping the argument.
+All other changes will be caught by the compiler and must be updated by hand.
 </p>
 
 <h4 id="os_fileinfo">The os.FileInfo type</h4>
@@ -1915,7 +1926,7 @@ so that exported function definitions can use types defined there.
 This has the effect of compiling the preamble multiple times, so a
 package using <code>//export</code> must not put function definitions
 or variable initializations in the C preamble.
-</p
+</p>
 
 <h2 id="releases">Packaged releases</h2>
 
index 57957beabaf04adf6a8f52ca7888e749984d16d6..f9744123258b5635a4267e9113f6087f6e12482f 100644 (file)
@@ -4,7 +4,7 @@
 {{donotedit}}
 
 <!-- Center the tables, and disable the 1995-era 3D borders -->
-<style>
+<style type="text/css">
 table { margin-left: auto; margin-right: auto; border-style: none; }
 hr { border-style: none; border-top: 1px solid black; }
 </style>
@@ -1363,9 +1363,20 @@ use <a href="/pkg/os/#Environ"><code>os.Environ</code></a> or
 <a href="/pkg/syscall/#Getenv"><code>syscall.Getenv</code></a>.
 </p>
 
+
+<p>
+The <a href="/pkg/os/#Process.Wait"><code>Process.Wait</code></a> method has
+dropped its option argument and the associated constants are gone
+from the package.
+Also, the function <code>Wait</code> is gone; only the method of
+the <code>Process</code> type persists.
+</p>
+
 <p>
 <em>Updating</em>:
-Affected code will be caught by the compiler and must be updated by hand.
+Gofix will rewrite calls to <code>os.Wait</code> with an explicit zero
+argument, dropping the argument.
+All other changes will be caught by the compiler and must be updated by hand.
 </p>
 
 <h4 id="os_fileinfo">The os.FileInfo type</h4>
@@ -1787,7 +1798,7 @@ so that exported function definitions can use types defined there.
 This has the effect of compiling the preamble multiple times, so a
 package using <code>//export</code> must not put function definitions
 or variable initializations in the C preamble.
-</p
+</p>
 
 <h2 id="releases">Packaged releases</h2>
 
index d6b6a7abb61b714f99ed65f0412b618cdb975ae1..155c65904f2d0fb0e1d28f81758d7b696d4f20d9 100644 (file)
@@ -56,7 +56,7 @@ func run(stdin []byte, argv []string) (stdout, stderr []byte, ok bool) {
        <-c
        <-c
 
-       w, err := p.Wait(0)
+       w, err := p.Wait()
        if err != nil {
                fatalf("%s", err)
        }
diff --git a/src/cmd/fix/oswait.go b/src/cmd/fix/oswait.go
new file mode 100644 (file)
index 0000000..fdc23f8
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+       "go/ast"
+)
+
+func init() {
+       register(oswaitFix)
+}
+
+var oswaitFix = fix{
+       "oswait",
+       "2012-02-20",
+       oswait,
+       `Delete options from os.Wait. If the option is the literal 0, rewrite the call.
+
+http://codereview.appspot.com/5688046
+`,
+}
+
+func oswait(f *ast.File) bool {
+       if !imports(f, "os") {
+               return false
+       }
+
+       fixed := false
+
+       walk(f, func(n interface{}) {
+               call, ok := n.(*ast.CallExpr)
+               if !ok {
+                       return
+               }
+               if !isPkgDot(call.Fun, "os", "Wait") {
+                       return
+               }
+               args := call.Args
+               const warning = "call to Process.Wait must be fixed manually"
+               if len(args) != 1 {
+                       // Shouldn't happen, but check.
+                       warn(call.Pos(), warning)
+                       return
+               }
+               if basicLit, ok := args[0].(*ast.BasicLit); !ok || basicLit.Value != "0" {
+                       warn(call.Pos(), warning)
+                       return
+               }
+               call.Args = nil
+               fixed = true
+       })
+
+       return fixed
+}
diff --git a/src/cmd/fix/oswait_test.go b/src/cmd/fix/oswait_test.go
new file mode 100644 (file)
index 0000000..baff017
--- /dev/null
@@ -0,0 +1,41 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func init() {
+       addTestCases(oswaitTests, oswait)
+}
+
+var oswaitTests = []testCase{
+       {
+               Name: "oswait.0",
+               In: `package main
+
+import (
+       "os"
+)
+
+func f() {
+       os.Wait()
+       os.Wait(0)
+       os.Wait(1)
+       os.Wait(A | B)
+}
+`,
+               Out: `package main
+
+import (
+       "os"
+)
+
+func f() {
+       os.Wait()
+       os.Wait()
+       os.Wait(1)
+       os.Wait(A | B)
+}
+`,
+       },
+}
index 96b729978f76ac371766dfdfb8b0375fc5474044..80cf61877827391be5ca00d830d2028691db2f77 100644 (file)
@@ -103,7 +103,7 @@ func exec(rw http.ResponseWriter, args []string) (status int) {
 
        var buf bytes.Buffer
        io.Copy(&buf, r)
-       wait, err := p.Wait(0)
+       wait, err := p.Wait()
        if err != nil {
                os.Stderr.Write(buf.Bytes())
                log.Printf("os.Wait(%d, 0): %v", p.Pid, err)
index fe254672169c66e890e20979009f11a724733e83..248d97d458890ffd27b9415d7e3b3f01fab9e0aa 100644 (file)
@@ -291,7 +291,7 @@ func (c *Cmd) Wait() error {
                return errors.New("exec: Wait was already called")
        }
        c.finished = true
-       msg, err := c.Process.Wait(0)
+       msg, err := c.Process.Wait()
        c.Waitmsg = msg
 
        var copyError error
index c57c4dc6d6aedd00f9f0266fab47ae8c9480ebfc..92126c1dd82f2b6cfbb00fc674860ef611ca08de 100644 (file)
@@ -70,9 +70,8 @@ type Waitmsg struct {
 }
 
 // Wait waits for the Process to exit or stop, and then returns a
-// Waitmsg describing its status and an error, if any. The options
-// (WNOHANG etc.) affect the behavior of the Wait call.
-func (p *Process) Wait(options int) (w *Waitmsg, err error) {
+// Waitmsg describing its status and an error, if any.
+func (p *Process) Wait() (w *Waitmsg, err error) {
        var waitmsg syscall.Waitmsg
 
        if p.Pid == -1 {
@@ -95,20 +94,6 @@ func (p *Process) Wait(options int) (w *Waitmsg, err error) {
        return &Waitmsg{waitmsg}, nil
 }
 
-// Wait waits for process pid to exit or stop, and then returns a
-// Waitmsg describing its status and an error, if any. The options
-// (WNOHANG etc.) affect the behavior of the Wait call.
-// Wait is equivalent to calling FindProcess and then Wait
-// and Release on the result.
-func Wait(pid int, options int) (w *Waitmsg, err error) {
-       p, e := FindProcess(pid)
-       if e != nil {
-               return nil, e
-       }
-       defer p.Release()
-       return p.Wait(options)
-}
-
 // Release releases any resources associated with the Process.
 func (p *Process) Release() error {
        // NOOP for Plan 9.
index 33a689eb045ba8f73b7855a951819bc9b63bc34c..03c7f0e82ff26039ac5340097f5d9f23e3b5723f 100644 (file)
@@ -56,20 +56,6 @@ type Waitmsg struct {
        Rusage             *syscall.Rusage // System-dependent resource usage info.
 }
 
-// Wait waits for process pid to exit or stop, and then returns a
-// Waitmsg describing its status and an error, if any. The options
-// (WNOHANG etc.) affect the behavior of the Wait call.
-// Wait is equivalent to calling FindProcess and then Wait
-// and Release on the result.
-func Wait(pid int, options int) (w *Waitmsg, err error) {
-       p, e := FindProcess(pid)
-       if e != nil {
-               return nil, e
-       }
-       defer p.Release()
-       return p.Wait(options)
-}
-
 // Convert i to decimal string.
 func itod(i int) string {
        if i == 0 {
index a5c22812a2f556784630affb5aa614b14c8f4787..b9880ff796db93b7510018f2b936fa3878835409 100644 (file)
@@ -12,43 +12,23 @@ import (
        "syscall"
 )
 
-// Options for Wait.
-const (
-       WNOHANG   = syscall.WNOHANG   // Don't wait if no process has exited.
-       WSTOPPED  = syscall.WSTOPPED  // If set, status of stopped subprocesses is also reported.
-       WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED.
-       WRUSAGE   = 1 << 20           // Record resource usage.
-)
-
-// WRUSAGE must not be too high a bit, to avoid clashing with Linux's
-// WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of
-// the options
-
 // Wait waits for the Process to exit or stop, and then returns a
-// Waitmsg describing its status and an error, if any. The options
-// (WNOHANG etc.) affect the behavior of the Wait call.
-func (p *Process) Wait(options int) (w *Waitmsg, err error) {
+// Waitmsg describing its status and an error, if any.
+func (p *Process) Wait() (w *Waitmsg, err error) {
        if p.Pid == -1 {
                return nil, syscall.EINVAL
        }
        var status syscall.WaitStatus
-       var rusage *syscall.Rusage
-       if options&WRUSAGE != 0 {
-               rusage = new(syscall.Rusage)
-               options ^= WRUSAGE
-       }
-       pid1, e := syscall.Wait4(p.Pid, &status, options, rusage)
+       pid1, e := syscall.Wait4(p.Pid, &status, 0, nil)
        if e != nil {
                return nil, NewSyscallError("wait", e)
        }
-       // With WNOHANG pid is 0 if child has not exited.
-       if pid1 != 0 && options&WSTOPPED == 0 {
+       if pid1 != 0 {
                p.done = true
        }
        w = new(Waitmsg)
        w.Pid = pid1
        w.WaitStatus = status
-       w.Rusage = rusage
        return w, nil
 }
 
index 2a7affa2843ad632c6806deaba033124e6b612d3..7d46c89d83c1f7194f2ee6df4177a0afa6c88947 100644 (file)
@@ -13,7 +13,7 @@ import (
 
 // Wait waits for the Process to exit or stop, and then returns a
 // Waitmsg describing its status and an error, if any.
-func (p *Process) Wait(options int) (w *Waitmsg, err error) {
+func (p *Process) Wait() (w *Waitmsg, err error) {
        s, e := syscall.WaitForSingleObject(syscall.Handle(p.handle), syscall.INFINITE)
        switch s {
        case syscall.WAIT_OBJECT_0:
index e02d7a43a3e678277eb68f9662738c92e1409c76..976d64bdd6b336ba393bef7480383b9cd0f2047e 100644 (file)
@@ -541,7 +541,7 @@ func exec(t *testing.T, dir, cmd string, args []string, expect string) {
                t.Errorf("exec %q returned %q wanted %q",
                        strings.Join(append([]string{cmd}, args...), " "), output, expect)
        }
-       p.Wait(0)
+       p.Wait()
 }
 
 func TestStartProcess(t *testing.T) {
@@ -853,7 +853,7 @@ func run(t *testing.T, cmd []string) string {
 
        var b bytes.Buffer
        io.Copy(&b, r)
-       _, err = p.Wait(0)
+       _, err = p.Wait()
        if err != nil {
                t.Fatalf("run hostname Wait: %v", err)
        }