You've already forked runc
mirror of
https://github.com/opencontainers/runc.git
synced 2026-10-23 19:49:01 +03:00
Use net.DialUnix instead of net.Dial
Using net.Dial makes the DNS resolver from the net package (including vendor/golang.org/x/net/dns/dnsmessage) reachable for the linker, since net.Dial can be used with a host name. All the runc callers only ever connect to a unix socket, so use net.DialUnix, which does not do any name resolution. As a bonus, there is no need for a type assertion to call File(). On its own, this change does not make runc binary smaller, since godbus/dbus also uses net.Dial in its tcp transports. Once godbus gets a way to disable those (see https://github.com/godbus/dbus/pull/444), the two changes together make runc binary about 380 KB (3.7%) smaller. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -1117,13 +1117,13 @@ func pidGetFd(pid, srcFd int) (*os.File, error) {
|
||||
}
|
||||
|
||||
func sendContainerProcessState(listenerPath string, state *specs.ContainerProcessState, file *os.File) error {
|
||||
conn, err := net.Dial("unix", listenerPath)
|
||||
conn, err := net.DialUnix("unix", nil, &net.UnixAddr{Name: listenerPath, Net: "unix"})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect with seccomp agent specified in the seccomp profile: %w", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
socket, err := conn.(*net.UnixConn).File()
|
||||
socket, err := conn.File()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot get seccomp socket: %w", err)
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func setupIO(process *libcontainer.Process, container *libcontainer.Container, c
|
||||
}()
|
||||
} else {
|
||||
// the caller of runc will handle receiving the console master
|
||||
conn, err := net.Dial("unix", sockpath)
|
||||
conn, err := net.DialUnix("unix", nil, &net.UnixAddr{Name: sockpath, Net: "unix"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -129,7 +129,7 @@ func setupIO(process *libcontainer.Process, container *libcontainer.Container, c
|
||||
}
|
||||
}()
|
||||
t.postStart = append(t.postStart, conn)
|
||||
socket, err := conn.(*net.UnixConn).File()
|
||||
socket, err := conn.File()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -441,12 +441,12 @@ func setupPidfdSocket(process *libcontainer.Process, sockpath string) (_clean fu
|
||||
return nil, fmt.Errorf("--pidfd-socket requires >= v5.3 kernel")
|
||||
}
|
||||
|
||||
conn, err := net.Dial("unix", sockpath)
|
||||
conn, err := net.DialUnix("unix", nil, &net.UnixAddr{Name: sockpath, Net: "unix"})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dail %s: %w", sockpath, err)
|
||||
}
|
||||
|
||||
socket, err := conn.(*net.UnixConn).File()
|
||||
socket, err := conn.File()
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("failed to dup socket: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user