Fix race condition in config.Getenv
The envDeps map may be accessed concurrently by multiple modules in GenerateBuildActions, wrap the accesses in a mutex. Change-Id: I18abf2687997c045a99b987908623f7d8c2ea344
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The configuration file name
|
// The configuration file name
|
||||||
@@ -44,6 +45,8 @@ type config struct {
|
|||||||
FileConfigurableOptions
|
FileConfigurableOptions
|
||||||
|
|
||||||
srcDir string // the path of the root source directory
|
srcDir string // the path of the root source directory
|
||||||
|
|
||||||
|
envLock sync.Mutex
|
||||||
envDeps map[string]string
|
envDeps map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,10 +169,12 @@ func (c *config) CpPreserveSymlinksFlags() string {
|
|||||||
func (c *config) Getenv(key string) string {
|
func (c *config) Getenv(key string) string {
|
||||||
var val string
|
var val string
|
||||||
var exists bool
|
var exists bool
|
||||||
|
c.envLock.Lock()
|
||||||
if val, exists = c.envDeps[key]; !exists {
|
if val, exists = c.envDeps[key]; !exists {
|
||||||
val = os.Getenv(key)
|
val = os.Getenv(key)
|
||||||
c.envDeps[key] = val
|
c.envDeps[key] = val
|
||||||
}
|
}
|
||||||
|
c.envLock.Unlock()
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user