summaryrefslogtreecommitdiff
path: root/vendor/github.com/godbus/dbus/v5/homedir.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/godbus/dbus/v5/homedir.go')
-rw-r--r--vendor/github.com/godbus/dbus/v5/homedir.go29
1 files changed, 13 insertions, 16 deletions
diff --git a/vendor/github.com/godbus/dbus/v5/homedir.go b/vendor/github.com/godbus/dbus/v5/homedir.go
index 0b745f931..c44d9b5fc 100644
--- a/vendor/github.com/godbus/dbus/v5/homedir.go
+++ b/vendor/github.com/godbus/dbus/v5/homedir.go
@@ -2,27 +2,24 @@ package dbus
import (
"os"
- "sync"
-)
-
-var (
- homeDir string
- homeDirLock sync.Mutex
+ "os/user"
)
+// Get returns the home directory of the current user, which is usually the
+// value of HOME environment variable. In case it is not set or empty, os/user
+// package is used.
+//
+// If linking statically with cgo enabled against glibc, make sure the
+// osusergo build tag is used.
+//
+// If needing to do nss lookups, do not disable cgo or set osusergo.
func getHomeDir() string {
- homeDirLock.Lock()
- defer homeDirLock.Unlock()
-
+ homeDir := os.Getenv("HOME")
if homeDir != "" {
return homeDir
}
-
- homeDir = os.Getenv("HOME")
- if homeDir != "" {
- return homeDir
+ if u, err := user.Current(); err == nil {
+ return u.HomeDir
}
-
- homeDir = lookupHomeDir()
- return homeDir
+ return "/"
}