From 31a627f670fc24302d8cbd74f5696d7639c87585 Mon Sep 17 00:00:00 2001 From: Mikhail Osipov Date: Tue, 8 Mar 2022 15:27:14 +0300 Subject: add socket name option --- pkg/config/config.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'pkg') diff --git a/pkg/config/config.go b/pkg/config/config.go index 5d2759e..2aa5bc2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -11,8 +11,14 @@ const TimeMsFormat = "2006-01-02/15:04:05.000" const IoTimeout = 5 * time.Second -func GetSystemSocketPath() string { - return "/run/tunnel/socket" +const defaultName = "default" + +func GetSysSocketPath(name string) string { + const path = "/run/tunnel/" + if name == "" { + name = defaultName + } + return path + name } func getuid() int { @@ -31,11 +37,14 @@ func runAsRoot() bool { return uid == 0 } -func GetSocketPath() string { +func GetSocketPath(name string) string { if uid := getuid(); uid == 0 { - return GetSystemSocketPath() + return GetSysSocketPath(name) } else { - return fmt.Sprintf("/run/user/%d/tunnel/socket", uid) + if name == "" { + name = defaultName + } + return fmt.Sprintf("/run/user/%d/tunnel/%s", uid, name) } } -- cgit v1.2.3-70-g09d2