if socket path is empty, try socket in $XDG_RUNTIME_DIR first
This commit is contained in:
parent
f6e6cf4a14
commit
2a9e942b78
2 changed files with 29 additions and 5 deletions
|
@ -36,9 +36,7 @@ var Path string
|
|||
|
||||
// Config is the variable the configuration gets loaded into
|
||||
// values shown here are used as defaults
|
||||
var Config = Configuration{
|
||||
SocketPath: "/var/run/signald/signald.sock",
|
||||
}
|
||||
var Config = Configuration{}
|
||||
|
||||
func Load() error {
|
||||
f, err := os.Open(Path)
|
||||
|
|
|
@ -31,8 +31,14 @@ import (
|
|||
"gitlab.com/signald/signald-go/signald/client-protocol/v0"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultSocketPrefix = "/var/run"
|
||||
socketSuffix = "/signald/signald.sock"
|
||||
)
|
||||
|
||||
var (
|
||||
debugSignaldIO, _ = strconv.ParseBool(os.Getenv("DEBUG_SIGNALD_IO"))
|
||||
xdgRuntimeDir = os.Getenv("XDG_RUNTIME_DIR")
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -59,9 +65,29 @@ type UnexpectedError struct {
|
|||
|
||||
// Connect connects to the signad socket
|
||||
func (s *Signald) Connect() error {
|
||||
if s.SocketPath == "" {
|
||||
s.SocketPath = "/var/run/signald/signald.sock"
|
||||
if s.SocketPath != "" {
|
||||
return s.connect()
|
||||
}
|
||||
|
||||
s.SocketPath = xdgRuntimeDir + socketSuffix
|
||||
err := s.connect()
|
||||
if err != nil {
|
||||
_, ok := err.(net.Error)
|
||||
if ok {
|
||||
s.SocketPath = defaultSocketPrefix + socketSuffix
|
||||
err = s.connect()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Signald) connect() error {
|
||||
socket, err := net.Dial("unix", s.SocketPath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue