summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-14 12:46:06 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-14 13:05:37 +0200
commit2dfd4e7d8c5f5540690dfbbac50aa6f020b2cbbc (patch)
treee5498c527cd77d7cc4f0bdcac1843b3e8d5d3025
parent355e9bd619c8ec8bdd0f2934739a87a15ceb6920 (diff)
Cleanup socket file
-rw-r--r--uapi_darwin.go6
-rw-r--r--uapi_linux.go10
2 files changed, 12 insertions, 4 deletions
diff --git a/uapi_darwin.go b/uapi_darwin.go
index 0f6d904..a5f2c3b 100644
--- a/uapi_darwin.go
+++ b/uapi_darwin.go
@@ -57,7 +57,7 @@ func (l *UAPIListener) Close() error {
}
func (l *UAPIListener) Addr() net.Addr {
- return nil
+ return l.listener.Addr()
}
func UAPIListen(name string, file *os.File) (net.Listener, error) {
@@ -75,6 +75,10 @@ func UAPIListen(name string, file *os.File) (net.Listener, error) {
connErr: make(chan error, 1),
}
+ if unixListener, ok := listener.(*net.UnixListener); ok {
+ unixListener.SetUnlinkOnClose(true)
+ }
+
socketPath := path.Join(
socketDirectory,
fmt.Sprintf(socketName, name),
diff --git a/uapi_linux.go b/uapi_linux.go
index 67024e9..45be0f5 100644
--- a/uapi_linux.go
+++ b/uapi_linux.go
@@ -46,8 +46,8 @@ func (l *UAPIListener) Accept() (net.Conn, error) {
func (l *UAPIListener) Close() error {
err1 := unix.Close(l.inotifyFd)
- err2 := l.listener.Close()
- err3 := l.inotifyRWCancel.Cancel()
+ err2 := l.inotifyRWCancel.Cancel()
+ err3 := l.listener.Close()
if err1 != nil {
return err1
}
@@ -58,7 +58,7 @@ func (l *UAPIListener) Close() error {
}
func (l *UAPIListener) Addr() net.Addr {
- return nil
+ return l.listener.Addr()
}
func UAPIListen(name string, file *os.File) (net.Listener, error) {
@@ -70,6 +70,10 @@ func UAPIListen(name string, file *os.File) (net.Listener, error) {
return nil, err
}
+ if unixListener, ok := listener.(*net.UnixListener); ok {
+ unixListener.SetUnlinkOnClose(true)
+ }
+
uapi := &UAPIListener{
listener: listener,
connNew: make(chan net.Conn, 1),