From bd65ce1010a78eec38ba9c70d9fc23f85cd087a1 Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Fri, 25 Feb 2022 16:03:43 +0100 Subject: [PATCH] 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 Acked-by: Robin Jarry --- lib/socket.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/socket.go b/lib/socket.go index cdf0f73..119ffda 100644 --- a/lib/socket.go +++ b/lib/socket.go @@ -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