From 6af725ff099e78fab2920f060c127415aa3b1893 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 10 Dec 2016 14:54:06 +0100 Subject: ctlsock: exit early if socket cannot be created; delete on exit Both are achieved by opening the socket from main and passing it to the ctlsock package instead of passing the path. --- internal/ctlsock/ctlsock_serve.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'internal/ctlsock/ctlsock_serve.go') diff --git a/internal/ctlsock/ctlsock_serve.go b/internal/ctlsock/ctlsock_serve.go index 63515c0..45b1e5b 100644 --- a/internal/ctlsock/ctlsock_serve.go +++ b/internal/ctlsock/ctlsock_serve.go @@ -46,19 +46,14 @@ type ctlSockHandler struct { socket *net.UnixListener } -// CreateAndServe creates an unix socket at "path" and serves incoming -// connections in a new goroutine. -func CreateAndServe(path string, fs Interface) error { - sock, err := net.Listen("unix", path) - if err != nil { - return err - } +// Serve serves incoming connections on "sock". This call blocks so you +// probably want to run it in a new goroutine. +func Serve(sock net.Listener, fs Interface) { handler := ctlSockHandler{ fs: fs, socket: sock.(*net.UnixListener), } - go handler.acceptLoop() - return nil + handler.acceptLoop() } func (ch *ctlSockHandler) acceptLoop() { -- cgit v1.2.3