fix socket path issues
This commit is contained in:
@ -23,12 +23,10 @@ type Response struct {
|
||||
Actions ReadableMap
|
||||
}
|
||||
|
||||
func SocketPath() string {
|
||||
return fmt.Sprintf("/run/user/%v/reaction.sock", os.Getuid())
|
||||
}
|
||||
const SocketPath = "/run/reaction/reaction.sock"
|
||||
|
||||
func SendAndRetrieve(data Request) Response {
|
||||
conn, err := net.Dial("unix", SocketPath())
|
||||
conn, err := net.Dial("unix", SocketPath)
|
||||
if err != nil {
|
||||
log.Fatalln("Error opening connection top daemon:", err)
|
||||
}
|
||||
|
18
app/pipe.go
18
app/pipe.go
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
@ -110,18 +111,21 @@ func (r ReadableMap) ToString() string {
|
||||
// Socket-related, server-related functions
|
||||
|
||||
func createOpenSocket() net.Listener {
|
||||
socketPath := SocketPath()
|
||||
_, err := os.Stat(socketPath)
|
||||
err := os.MkdirAll(path.Dir(SocketPath), 0755)
|
||||
if err != nil {
|
||||
log.Fatalln("FATAL Failed to create socket directory")
|
||||
}
|
||||
_, err = os.Stat(SocketPath)
|
||||
if err == nil {
|
||||
log.Println("WARN socket", socketPath, "already exists: Is the daemon already running? Deleting.")
|
||||
err = os.Remove(socketPath)
|
||||
log.Println("WARN socket", SocketPath, "already exists: Is the daemon already running? Deleting.")
|
||||
err = os.Remove(SocketPath)
|
||||
if err != nil {
|
||||
log.Println("FATAL Failed to remove socket:", err)
|
||||
log.Fatalln("FATAL Failed to remove socket:", err)
|
||||
}
|
||||
}
|
||||
ln, err := net.Listen("unix", socketPath)
|
||||
ln, err := net.Listen("unix", SocketPath)
|
||||
if err != nil {
|
||||
log.Println("FATAL Failed to create socket:", err)
|
||||
log.Fatalln("FATAL Failed to create socket:", err)
|
||||
}
|
||||
return ln
|
||||
}
|
||||
|
@ -235,7 +235,10 @@ func quit() {
|
||||
// wait for them to complete
|
||||
wgActions.Wait()
|
||||
// delete pipe
|
||||
os.Remove(SocketPath())
|
||||
err := os.Remove(SocketPath)
|
||||
if err != nil {
|
||||
log.Println("Failed to remove socket:", err)
|
||||
}
|
||||
|
||||
os.Exit(3)
|
||||
}
|
||||
|
Reference in New Issue
Block a user