]> Cypherpunks repositories - gostls13.git/commitdiff
os: diagnose chdir error during StartProcess
authorRuss Cox <rsc@golang.org>
Wed, 29 Feb 2012 20:53:57 +0000 (15:53 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 29 Feb 2012 20:53:57 +0000 (15:53 -0500)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5711044

src/pkg/os/exec_posix.go

index 4a75cb67fb5ef35cecd357aebb2144630405546b..a686f44606e02bb50f336b88091fe835d0adf2fa 100644 (file)
@@ -18,6 +18,16 @@ import (
 //
 // If there is an error, it will be of type *PathError.
 func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
+       // Double-check existence of the directory we want
+       // to chdir into.  We can make the error clearer this way.
+       if attr != nil && attr.Dir != "" {
+               if _, err := Stat(attr.Dir); err != nil {
+                       pe := err.(*PathError)
+                       pe.Op = "chdir"
+                       return nil, pe
+               }
+       }
+
        sysattr := &syscall.ProcAttr{
                Dir: attr.Dir,
                Env: attr.Env,