aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalph Seichter <aerc@seichter.de>2024-10-08 16:53:58 +0200
committerRobin Jarry <robin@jarry.cc>2024-10-12 00:14:29 +0200
commit6ea2b786d4eb715e580f73e210a322aac10adc9f (patch)
tree36a137cf035349f0e64f11bd90a6f6d139d9683a
parent0d9f2002d5671139d1c0d0be17435c9d324a45d4 (diff)
downloadaerc-6ea2b786d4eb715e580f73e210a322aac10adc9f.tar.gz
xdg: determine user runtime directory in a robust manner
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 <aerc@seichter.de> Reviewed-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--lib/xdg/xdg.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/xdg/xdg.go b/lib/xdg/xdg.go
index c1eaab03..6060c2bc 100644
--- a/lib/xdg/xdg.go
+++ b/lib/xdg/xdg.go
@@ -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