From 87835a601ca766430dc712865e9a4aa0fa901b28 Mon Sep 17 00:00:00 2001 From: Morgan Fainberg Date: Wed, 13 Mar 2024 15:45:56 -0700 Subject: [PATCH] Improve pidfile location for non-root Improve pidfile location for non-root users. Use XDG_RUNTIME_PATH if set. --- cmd/root/root.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/root/root.go b/cmd/root/root.go index 909c677..2cfe136 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -85,7 +85,9 @@ func defaultPidFilePath() string { // If we're on OS X, use the user's home directory // Otherwise, use /run path := "/run/pget.pid" - if runtime.GOOS == "darwin" { + if xdgPath, ok := os.LookupEnv("XDG_RUNTIME_DIR"); ok { + path = xdgPath + "/pget.pid" + } else if runtime.GOOS == "darwin" { path = os.Getenv("HOME") + "/.pget.pid" } return path