Skip to content

Commit b26eb69

Browse files
authored
fix: set XDG_CONFIG_DIRS and XDG_DATA_DIRS defaults in tryGetPamEnvVars (#3121)
## Summary - Fixes #2970: WaveTerm does not inherit `XDG_CONFIG_DIRS` (and `XDG_DATA_DIRS`) when snap or other environments strip these variables and PAM env files do not define them - In `tryGetPamEnvVars()`, after the existing `XDG_RUNTIME_DIR` fallback, adds identical fallback logic for `XDG_CONFIG_DIRS` (default: `/etc/xdg`) and `XDG_DATA_DIRS` (default: `/usr/local/share:/usr/share`) per the XDG Base Directory Specification - No behavior change when these vars are already set by PAM env files ## Root Cause Snap confinement strips several XDG environment variables. `tryGetPamEnvVars()` already handles `XDG_RUNTIME_DIR` with a sensible default, but `XDG_CONFIG_DIRS` and `XDG_DATA_DIRS` were left unhandled, causing child shells to receive empty/unset values. ## Test plan - [ ] `gofmt -l ./pkg/shellexec/` — no output (clean) - [ ] `go build ./...` — succeeds - [ ] On Linux with snap, verify that child shells receive `XDG_CONFIG_DIRS=/etc/xdg` and `XDG_DATA_DIRS=/usr/local/share:/usr/share` when the variables are not set by the desktop environment Signed-off-by: majiayu000 <1835304752@qq.com>
1 parent 24de0c1 commit b26eb69

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/shellexec/shellexec.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,5 +760,11 @@ func tryGetPamEnvVars() map[string]string {
760760
if runtime_dir, ok := envVars["XDG_RUNTIME_DIR"]; !ok || runtime_dir == "" {
761761
envVars["XDG_RUNTIME_DIR"] = "/run/user/" + fmt.Sprint(os.Getuid())
762762
}
763+
if configDirs, ok := envVars["XDG_CONFIG_DIRS"]; !ok || configDirs == "" {
764+
envVars["XDG_CONFIG_DIRS"] = "/etc/xdg"
765+
}
766+
if dataDirs, ok := envVars["XDG_DATA_DIRS"]; !ok || dataDirs == "" {
767+
envVars["XDG_DATA_DIRS"] = "/usr/local/share:/usr/share"
768+
}
763769
return envVars
764770
}

0 commit comments

Comments
 (0)