diff options
Diffstat (limited to 'pkg/config/config.go')
| -rw-r--r-- | pkg/config/config.go | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index fb09ad0..5483192 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -1,12 +1,33 @@ package config -import "time" - -const SockType = "unixpacket" -const SockPath = "/tmp/tunnel.sock" +import ( + "errors" + "fmt" + "os" + "time" +) const TimeFormat = "2006-01-02/15:04:05" const BufSize = 1024 const IoTimeout = 5 * time.Second + +var errNegativeUid = errors.New("negative uid") + +func GetSystemSocketPath() (string, error) { + return "/run/tunnel/socket", nil +} + +func GetSocketPath() (string, error) { + uid := os.Getuid() + + switch uid { + case -1: + return "", errNegativeUid + case 0: + return GetSystemSocketPath() + } + + return fmt.Sprintf("/run/user/%d/tunnel/socket", uid), nil +} |
