File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ const EnvKey = "DOCKER_CLI_PLUGIN_SOCKET"
1919// NewPluginServer creates a plugin server that listens on a new Unix domain
2020// socket. h is called for each new connection to the socket in a goroutine.
2121func NewPluginServer (h func (net.Conn )) (* PluginServer , error ) {
22- l , err := listen ("docker_cli_" + randomID ())
22+ l , err := net .ListenUnix ("unix" , & net.UnixAddr {
23+ Name : socketName ("docker_cli_" + randomID ()),
24+ Net : "unix" ,
25+ })
2326 if err != nil {
2427 return nil , err
2528 }
@@ -85,9 +88,6 @@ func (pl *PluginServer) Addr() net.Addr {
8588//
8689// The error value is that of the underlying [net.Listner.Close] call.
8790func (pl * PluginServer ) Close () error {
88- // Remove the listener socket, if it exists on the filesystem.
89- unlink (pl .l )
90-
9191 // Close connections first to ensure the connections get io.EOF instead
9292 // of a connection reset.
9393 pl .closeAllConns ()
Original file line number Diff line number Diff line change 22
33package socket
44
5- import (
6- "net"
7- )
8-
9- func listen (socketname string ) (* net.UnixListener , error ) {
10- // Create an abstract socket -- this socket can be opened by name, but is
11- // not present in the filesystem.
12- return net .ListenUnix ("unix" , & net.UnixAddr {
13- Name : "@" + socketname ,
14- Net : "unix" ,
15- })
16- }
17-
18- func unlink (listener * net.UnixListener ) {
19- // Do nothing; the socket is not present in the filesystem.
5+ func socketName (basename string ) string {
6+ // Address of an abstract socket -- this socket can be opened by name,
7+ // but is not present in the filesystem.
8+ return "@" + basename
209}
Original file line number Diff line number Diff line change 33package socket
44
55import (
6- "net"
76 "os"
87 "path/filepath"
9- "syscall"
108)
119
12- func listen (socketname string ) (* net.UnixListener , error ) {
13- // Because abstract sockets are unavailable, we create a socket in the
14- // system temporary directory instead.
15- return net .ListenUnix ("unix" , & net.UnixAddr {
16- Name : filepath .Join (os .TempDir (), socketname ),
17- Net : "unix" ,
18- })
19- }
20-
21- func unlink (listener * net.UnixListener ) {
22- // unlink(2) is best effort here; if it fails, we may 'leak' a socket
23- // into the filesystem, but this is unlikely and overall harmless.
24- _ = syscall .Unlink (listener .Addr ().String ())
10+ func socketName (basename string ) string {
11+ // Because abstract sockets are unavailable, use a socket path in the
12+ // system temporary directory.
13+ return filepath .Join (os .TempDir (), basename )
2514}
You can’t perform that action at this time.
0 commit comments