libpod: Move openUnixSocket to oci_conmon_attach_linux.go

This function depends on linux-specific functionality in /proc/fd to
allow connecting to local domain sockets with pathnames too long for
sockaddr_un.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
This commit is contained in:
Doug Rabson 2022-08-17 11:18:15 +01:00
parent d43fac20f3
commit cb4158889e
2 changed files with 17 additions and 9 deletions

View File

@ -29,15 +29,6 @@ const (
AttachPipeStderr = 3 AttachPipeStderr = 3
) )
func openUnixSocket(path string) (*net.UnixConn, error) {
fd, err := unix.Open(path, unix.O_PATH, 0)
if err != nil {
return nil, err
}
defer unix.Close(fd)
return net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: fmt.Sprintf("/proc/self/fd/%d", fd), Net: "unixpacket"})
}
// Attach to the given container. // Attach to the given container.
// Does not check if state is appropriate. // Does not check if state is appropriate.
// started is only required if startContainer is true. // started is only required if startContainer is true.

View File

@ -0,0 +1,17 @@
package libpod
import (
"fmt"
"net"
"golang.org/x/sys/unix"
)
func openUnixSocket(path string) (*net.UnixConn, error) {
fd, err := unix.Open(path, unix.O_PATH, 0)
if err != nil {
return nil, err
}
defer unix.Close(fd)
return net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: fmt.Sprintf("/proc/self/fd/%d", fd), Net: "unixpacket"})
}