diff --git a/signald-cli/cmd/root.go b/signald-cli/cmd/root.go index 1b8048c..0ace430 100644 --- a/signald-cli/cmd/root.go +++ b/signald-cli/cmd/root.go @@ -33,8 +33,8 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.signald-cli.yaml)") - RootCmd.PersistentFlags().StringVarP(&socketPath, "socket", "s", "/var/run/signald/signald.socket", "the path to the signald socket file") - s = &signald.Signald{} + RootCmd.PersistentFlags().StringVarP(&socketPath, "socket", "s", "/var/run/signald/signald.sock", "the path to the signald socket file") + s = &signald.Signald{SocketPath: socketPath,} s.Connect() } diff --git a/signald/signald.go b/signald/signald.go index 6ba6d31..705665e 100644 --- a/signald/signald.go +++ b/signald/signald.go @@ -2,14 +2,14 @@ package signald import ( "encoding/json" - "net" "log" + "net" ) - // Signald is a connection to a signald instance. type Signald struct { - socket net.Conn + socket net.Conn + SocketPath string } func crash(err error) { @@ -20,7 +20,10 @@ func crash(err error) { // Connect connects to the signad socket func (s *Signald) Connect() { - socket, err := net.Dial("unix", "/var/run/signald/signald.sock") + if s.SocketPath == "" { + s.SocketPath = "/var/run/signald/signald.sock" + } + socket, err := net.Dial("unix", s.SocketPath) crash(err) s.socket = socket log.Print("Connected to signald socket ", socket.RemoteAddr().String())