Skip to content

Commit 7d2161f

Browse files
committed
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 <[email protected]>
1 parent b64bb16 commit 7d2161f

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

utils_linux.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,8 @@ func setupIO(process *libcontainer.Process, container *libcontainer.Container, c
121121
if err != nil {
122122
return nil, err
123123
}
124-
uc, ok := conn.(*net.UnixConn)
125-
if !ok {
126-
return nil, errors.New("casting to UnixConn failed")
127-
}
128-
t.postStart = append(t.postStart, uc)
129-
socket, err := uc.File()
124+
t.postStart = append(t.postStart, conn)
125+
socket, err := conn.(*net.UnixConn).File()
130126
if err != nil {
131127
return nil, err
132128
}
@@ -432,13 +428,7 @@ func setupPidfdSocket(process *libcontainer.Process, sockpath string) (_clean fu
432428
return nil, fmt.Errorf("failed to dail %s: %w", sockpath, err)
433429
}
434430

435-
uc, ok := conn.(*net.UnixConn)
436-
if !ok {
437-
conn.Close()
438-
return nil, errors.New("failed to cast to UnixConn")
439-
}
440-
441-
socket, err := uc.File()
431+
socket, err := conn.(*net.UnixConn).File()
442432
if err != nil {
443433
conn.Close()
444434
return nil, fmt.Errorf("failed to dup socket: %w", err)

0 commit comments

Comments
 (0)