setupIO: simplify getting net.UnixConn

The typecast can't fail, so it doesn't make sense checking for errors
here.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-07-28 16:55:52 -07:00
parent b64bb16b10
commit 7d2161f807

View File

@@ -121,12 +121,8 @@ func setupIO(process *libcontainer.Process, container *libcontainer.Container, c
if err != nil {
return nil, err
}
uc, ok := conn.(*net.UnixConn)
if !ok {
return nil, errors.New("casting to UnixConn failed")
}
t.postStart = append(t.postStart, uc)
socket, err := uc.File()
t.postStart = append(t.postStart, conn)
socket, err := conn.(*net.UnixConn).File()
if err != nil {
return nil, err
}
@@ -432,13 +428,7 @@ func setupPidfdSocket(process *libcontainer.Process, sockpath string) (_clean fu
return nil, fmt.Errorf("failed to dail %s: %w", sockpath, err)
}
uc, ok := conn.(*net.UnixConn)
if !ok {
conn.Close()
return nil, errors.New("failed to cast to UnixConn")
}
socket, err := uc.File()
socket, err := conn.(*net.UnixConn).File()
if err != nil {
conn.Close()
return nil, fmt.Errorf("failed to dup socket: %w", err)