As macOS does not support the abstract socket namespace, use a temporary socket in $TMPDIR to connect with the plugin. Ensure this socket is cleaned up even in the case of crash/ungraceful termination by removing it after the first connection is accepted. Co-authored-by: Laura Brehm <laurabrehm@hey.com> Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
20 lines
355 B
Go
20 lines
355 B
Go
package socket
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
"syscall"
|
|
)
|
|
|
|
func listen(socketname string) (*net.UnixListener, error) {
|
|
return net.ListenUnix("unix", &net.UnixAddr{
|
|
Name: filepath.Join(os.TempDir(), socketname),
|
|
Net: "unix",
|
|
})
|
|
}
|
|
|
|
func onAccept(conn *net.UnixConn, listener *net.UnixListener) {
|
|
syscall.Unlink(listener.Addr().String())
|
|
}
|