mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
paths: fall back to XDG_DATA_HOME for non-root users' state dir
So peerapi has a default state directory, mostly for netstack mode testing. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
3a1eae5b6b
commit
33bc69cf1f
@ -7,6 +7,7 @@
|
|||||||
package paths
|
package paths
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
@ -45,8 +46,17 @@ func stateFileUnix() string {
|
|||||||
try = filepath.Dir(try)
|
try = filepath.Dir(try)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: try some $HOME/.tailscale or XDG path? But will it
|
if os.Getuid() == 0 {
|
||||||
// even work usefully enough as non-root? Probably not. Maybe
|
|
||||||
// best to require it be explicit in that case.
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For non-root users, fall back to $XDG_DATA_HOME/tailscale/*.
|
||||||
|
return filepath.Join(xdgDataHome(), "tailscale", "tailscaled.state")
|
||||||
|
}
|
||||||
|
|
||||||
|
func xdgDataHome() string {
|
||||||
|
if e := os.Getenv("XDG_DATA_HOME"); e != "" {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
return filepath.Join(os.Getenv("HOME"), ".local/share")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user