add removal of existing sockets

The kept socket after crashes or unclean exits can lead to a unexpected
behaviour. This commit just removes dangling sockets if they exist.
Since the "does not exist" error is the best case scenario error
handling was deemed unnecessary.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Moritz Poldrack 2022-02-25 16:03:43 +01:00 committed by Robin Jarry
parent 37477794b2
commit bd65ce1010
1 changed files with 3 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"log"
"net"
"net/url"
"os"
"path"
"strings"
"sync/atomic"
@ -23,6 +24,8 @@ type AercServer struct {
func StartServer(logger *log.Logger) (*AercServer, error) {
sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
// remove the socket if it already exists
os.Remove(sockpath)
l, err := net.Listen("unix", sockpath)
if err != nil {
return nil, err