Author: strogiyotec [almas337519@gmail.com]
Hash: adf5d8c4c9c506008eb4f6b78d272729b3ac76fe
Timestamp: Fri, 04 Sep 2020 23:11:55 +0000 (4 years ago)

+14 -0 +/-1 browse
delete socket file after accidental crash
1diff --git a/server.go b/server.go
2index c57ed82..7bb44a9 100644
3--- a/server.go
4+++ b/server.go
5 @@ -2,7 +2,10 @@ package main
6
7 import (
8 "encoding/json"
9+ "errors"
10+ "fmt"
11 "net"
12+ "os"
13 )
14
15 // Server listens on a Unix domain socket
16 @@ -39,6 +42,17 @@ func (s *Server) Stop() {
17 }
18
19 func NewServer(runner *TaskRunner, config *Config) (*Server, error) {
20+ //check if socket file exists
21+ if _, err := os.Stat(config.SocketPath); os.IsExist(err) {
22+ _, err := net.Dial("unix", config.SocketPath)
23+ //if error then sock file was saved after crash
24+ if err != nil {
25+ os.Remove(config.SocketPath)
26+ } else {
27+ // another instance of pomo is running
28+ return nil, errors.New(fmt.Sprintf("Socket %s is already in use", config.SocketPath))
29+ }
30+ }
31 listener, err := net.Listen("unix", config.SocketPath)
32 if err != nil {
33 return nil, err