Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions cli-plugins/socket/socket.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package socket

import (
"crypto/rand"
"encoding/hex"
"errors"
"io"
"net"
"os"

"github.com/docker/distribution/uuid"
)

// EnvKey represents the well-known environment variable used to pass the plugin being
Expand All @@ -17,7 +17,7 @@ const EnvKey = "DOCKER_CLI_PLUGIN_SOCKET"
// and update the conn pointer, and returns the listener for the socket (which the caller
// is responsible for closing when it's no longer needed).
func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) {
listener, err := listen("docker_cli_" + uuid.Generate().String())
listener, err := listen("docker_cli_" + randomID())
if err != nil {
return nil, err
}
Expand All @@ -27,6 +27,14 @@ func SetupConn(conn **net.UnixConn) (*net.UnixListener, error) {
return listener, nil
}

func randomID() string {
b := make([]byte, 16)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to 16 bytes; which is the same as the UUID (output is slightly shorter as it doesn't add hyphen in between;

before: 332becff-7147-44cc-ac72-8ab20eac060e
after:  68298c4c32a19c2b1cc636649c465d84

if _, err := rand.Read(b); err != nil {
panic(err) // This shouldn't happen
}
return hex.EncodeToString(b)
}

func accept(listener *net.UnixListener, conn **net.UnixConn) {
go func() {
for {
Expand Down