Skip to content

Commit a7cd2fe

Browse files
authored
fix(go.d): prefer env-provided dirs over build-time defaults (#21345)
1 parent 20a5119 commit a7cd2fe

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/go/pkg/pluginconfig/pluginconfig.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"github.com/netdata/netdata/go/plugins/pkg/cli"
2020
"github.com/netdata/netdata/go/plugins/pkg/executable"
2121
"github.com/netdata/netdata/go/plugins/pkg/multipath"
22+
23+
"github.com/mattn/go-isatty"
2224
)
2325

2426
var (
@@ -130,11 +132,11 @@ func (d *directories) initUserRoots(opts *cli.Option, env envData, execDir strin
130132
roots = append(roots, p)
131133
}
132134

133-
// 2) NETDATA_USER_CONFIG_DIR
134-
if buildinfo.UserConfigDir != "" {
135-
roots = append(roots, safePathClean(buildinfo.UserConfigDir))
136-
} else if dir := safePathClean(env.userDir); dir != "" {
135+
// 2) NETDATA_USER_CONFIG_DIR (env has priority over buildinfo)
136+
if dir := safePathClean(env.userDir); dir != "" {
137137
roots = append(roots, dir)
138+
} else if buildinfo.UserConfigDir != "" {
139+
roots = append(roots, safePathClean(buildinfo.UserConfigDir))
138140
}
139141

140142
if len(roots) != 0 {
@@ -164,14 +166,15 @@ func (d *directories) initUserRoots(opts *cli.Option, env envData, execDir strin
164166

165167
// Build step 2: initialize single "stock" root: env, common locations, build-relative fallback.
166168
func (d *directories) initStockRoot(env envData, execDir string) {
167-
if buildinfo.StockConfigDir != "" {
168-
d.stockConfigDir = safePathClean(buildinfo.StockConfigDir)
169-
return
170-
}
169+
// env.stockDir has priority
171170
if stock := safePathClean(env.stockDir); stock != "" {
172171
d.stockConfigDir = stock
173172
return
174173
}
174+
if buildinfo.StockConfigDir != "" {
175+
d.stockConfigDir = safePathClean(buildinfo.StockConfigDir)
176+
return
177+
}
175178

176179
relDir := safePathClean(filepath.Join(execDir, "..", "..", "..", "..", "usr", "lib", "netdata", "conf.d"))
177180
if isDirExists(relDir) {
@@ -254,19 +257,28 @@ func (d *directories) validate() error {
254257
return nil
255258
}
256259

260+
var isTerm = isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsTerminal(os.Stdout.Fd())
261+
257262
func readEnvFromOS(execDir string) envData {
258263
e := envData{
259264
cygwinBase: os.Getenv("NETDATA_CYGWIN_BASE_PATH"),
260265
userDir: os.Getenv("NETDATA_USER_CONFIG_DIR"),
261266
stockDir: os.Getenv("NETDATA_STOCK_CONFIG_DIR"),
262-
varLibDir: os.Getenv("NETDATA_LIB_DIR"),
263267
watchPath: os.Getenv("NETDATA_PLUGINS_GOD_WATCH_PATH"),
268+
varLibDir: os.Getenv("NETDATA_LIB_DIR"),
264269
logLevel: os.Getenv("NETDATA_LOG_LEVEL"),
265270
}
266271
e.userDir = handleDirOnWin(e.cygwinBase, safePathClean(e.userDir), execDir)
267272
e.stockDir = handleDirOnWin(e.cygwinBase, safePathClean(e.stockDir), execDir)
268273
e.varLibDir = handleDirOnWin(e.cygwinBase, safePathClean(e.varLibDir), execDir)
269274
e.watchPath = handleDirOnWin(e.cygwinBase, safePathClean(e.watchPath), execDir)
275+
276+
if isTerm {
277+
e.userDir = ""
278+
e.stockDir = ""
279+
e.watchPath = ""
280+
}
281+
270282
return e
271283
}
272284

0 commit comments

Comments
 (0)