fix(linux): fall back to /run/user/<uid> when XDG_RUNTIME_DIR is unset
A daemon autostarted from an environment without XDG_RUNTIME_DIR (e.g. an agent running under a systemd system service) could not reach the PipeWire/PulseAudio socket: oto dialed the relative path "pulse/native" and ALSA reported "Host is down". `talk say` then showed the desktop notification (godbus has its own /run/user fallback) but played no audio. talk now sets XDG_RUNTIME_DIR to /run/user/<uid> at startup when it is empty and that directory exists and belongs to the current user; a spawned daemon inherits it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f26905ef9a
commit
02d66a141e
3 files changed
+42
No files matched your search
@@ -36,5 +36,6 @@ func buildVersion() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
ensureRuntimeDir()
|
||||||
os.Exit(run(os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
|
os.Exit(run(os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ensureRuntimeDir fills in XDG_RUNTIME_DIR when it is missing.
|
||||||
|
//
|
||||||
|
// Processes started from a systemd system service, cron or a sudo/su shell
|
||||||
|
// often lack it, while the user's session (PipeWire/PulseAudio socket,
|
||||||
|
// D-Bus) still lives in /run/user/<uid>. Without it oto dials the relative
|
||||||
|
// path "pulse/native" and the pipewire ALSA plugin reports "Host is down",
|
||||||
|
// so the daemon shows the desktop notification (godbus has its own
|
||||||
|
// /run/user fallback) but plays nothing. The directory is only used when it
|
||||||
|
// exists and belongs to the current user. The spawned daemon inherits the
|
||||||
|
// value via os.Environ().
|
||||||
|
func ensureRuntimeDir() {
|
||||||
|
if os.Getenv("XDG_RUNTIME_DIR") != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uid := os.Getuid()
|
||||||
|
dir := fmt.Sprintf("/run/user/%d", uid)
|
||||||
|
fi, err := os.Stat(dir)
|
||||||
|
if err != nil || !fi.IsDir() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if st, ok := fi.Sys().(*syscall.Stat_t); !ok || int(st.Uid) != uid {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_ = os.Setenv("XDG_RUNTIME_DIR", dir)
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
// ensureRuntimeDir is a no-op outside Linux (see runtimedir_linux.go).
|
||||||
|
func ensureRuntimeDir() {}
|
||||||
Reference in new issue
Block a user