Skip to content

Commit fd6c529

Browse files
n
Change-Id: Iaf48768865f63b9d828a2bf46478e72da65891c7
1 parent 78e0ae5 commit fd6c529

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

src/os/exec/exec.go

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -642,27 +642,31 @@ func (c *Cmd) Start() error {
642642
}
643643
return c.Err
644644
}
645-
lp := c.cacheLookExtensions
646-
if lp == "" && runtime.GOOS == "windows" {
647-
// If c.Path is relative, we had to wait until now
648-
// to resolve it in case c.Dir was changed.
649-
// (If it is absolute, we already resolved its extension in Command
650-
// and shouldn't need to do so again.)
651-
//
652-
// Unfortunately, we cannot write the result back to c.Path because programs
653-
// may assume that they can call Start concurrently with reading the path.
654-
// (It is safe and non-racy to do so on Unix platforms, and users might not
655-
// test with the race detector on all platforms;
656-
// see https://go.dev/issue/62596.)
657-
//
658-
// So we will pass the fully resolved path to os.StartProcess, but leave
659-
// c.Path as is: missing a bit of logging information seems less harmful
660-
// than triggering a surprising data race, and if the user really cares
661-
// about that bit of logging they can always use LookPath to resolve it.
662-
var err error
663-
lp, err = lookExtensions(c.Path, c.Dir)
664-
if err != nil {
665-
return err
645+
lp := c.Path
646+
if runtime.GOOS == "windows" {
647+
if lp == "" {
648+
// If c.Path is relative, we had to wait until now
649+
// to resolve it in case c.Dir was changed.
650+
// (If it is absolute, we already resolved its extension in Command
651+
// and shouldn't need to do so again.)
652+
//
653+
// Unfortunately, we cannot write the result back to c.Path because programs
654+
// may assume that they can call Start concurrently with reading the path.
655+
// (It is safe and non-racy to do so on Unix platforms, and users might not
656+
// test with the race detector on all platforms;
657+
// see https://go.dev/issue/62596.)
658+
//
659+
// So we will pass the fully resolved path to os.StartProcess, but leave
660+
// c.Path as is: missing a bit of logging information seems less harmful
661+
// than triggering a surprising data race, and if the user really cares
662+
// about that bit of logging they can always use LookPath to resolve it.
663+
var err error
664+
lp, err = lookExtensions(c.Path, c.Dir)
665+
if err != nil {
666+
return err
667+
}
668+
} else {
669+
lp = c.cacheLookExtensions
666670
}
667671
}
668672
if c.Cancel != nil && c.ctx == nil {

0 commit comments

Comments
 (0)