From 7aba72baaae64792707076724307f6bdc7fec44f Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 29 Feb 2012 15:53:57 -0500 Subject: [PATCH] os: diagnose chdir error during StartProcess R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5711044 --- src/pkg/os/exec_posix.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pkg/os/exec_posix.go b/src/pkg/os/exec_posix.go index 4a75cb67fb..a686f44606 100644 --- a/src/pkg/os/exec_posix.go +++ b/src/pkg/os/exec_posix.go @@ -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, -- 2.50.0