Skip to content

Commit

Permalink
xdg: determine user runtime directory in a robust manner
Browse files Browse the repository at this point in the history
Instead of relying on systemd-style /run/user/NNN directories, which are
unavailable on platforms like OpenRC Gentoo Linux, create either the per
user /tmp/aerc-NNN directory, or fall back to using /tmp as a last
resort.

Changelog-fixed: Failure to create IPC socket on Gentoo.
Signed-off-by: Ralph Seichter <[email protected]>
Reviewed-by: Jason Cox <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
Ralph Seichter authored and rjarry committed Oct 11, 2024
1 parent 0d9f200 commit 6ea2b78
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/xdg/xdg.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,20 @@ func DataPath(paths ...string) string {

// ugly: there's no other way to allow mocking a function in go...
var userRuntimePath = func() string {
return filepath.Join("/run/user", strconv.Itoa(os.Getuid()))
uid := strconv.Itoa(os.Getuid())
path := filepath.Join("/run/user", uid)
fi, err := os.Stat(path)
if err != nil || !fi.Mode().IsDir() {
// OpenRC does not create /run/user. TMUX and Neovim
// create /tmp/$program-$uid instead. Mimic that.
path = filepath.Join(os.TempDir(), "aerc-"+uid)
err = os.MkdirAll(path, 0o700)
if err != nil {
// Fallback to /tmp if all else fails.
path = os.TempDir()
}
}
return path
}

// Return a path relative to the user runtime dir
Expand Down

0 comments on commit 6ea2b78

Please sign in to comment.