diff options
author | Jakob Unterwurzacher | 2016-12-10 14:54:06 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-12-10 14:54:06 +0100 |
commit | 6af725ff099e78fab2920f060c127415aa3b1893 (patch) | |
tree | f376bb15a52b9711e9f7072490e902d441d3df18 /internal | |
parent | e1833fa26a2a42e61aeff6f6e350714133dee378 (diff) |
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.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/ctlsock/ctlsock_serve.go | 13 |
1 files changed, 4 insertions, 9 deletions
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() { |