From cd6030ec8f9977fb5e151d719ddd8986f8b60584 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 11:22:49 +0100 Subject: [PATCH] Add support for UNIX domain admin sockets and specifying URIs in AdminListen --- src/yggdrasil/admin.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index bd5eb0c..e02bf9e 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -229,13 +229,26 @@ func (a *admin) start() error { // listen is run by start and manages API connections. func (a *admin) listen() { - l, err := net.Listen("tcp", a.listenaddr) + var l net.Listener + u, err := url.Parse(a.listenaddr) + if err == nil { + switch strings.ToLower(u.Scheme) { + case "unix": + l, err = net.Listen("unix", a.listenaddr[7:]) + case "tcp": + l, err = net.Listen("tcp", u.Host) + default: + err = errors.New("protocol not supported") + } + } else { + l, err = net.Listen("tcp", a.listenaddr) + } if err != nil { a.core.log.Printf("Admin socket failed to listen: %v", err) os.Exit(1) } + a.core.log.Printf("%s admin socket listening on %s", strings.ToUpper(l.Addr().Network()), l.Addr().String()) defer l.Close() - a.core.log.Printf("Admin socket listening on %s", l.Addr().String()) for { conn, err := l.Accept() if err == nil {