Skip to content

Commit 4e7aeff

Browse files
mauriciovasquezbernalrata
authored andcommitted
libcontainer/utils: introduce SendFds
SendFds is a helper function for sending a set of file descriptors and a message over a unix domain socket. Signed-off-by: Mauricio Vásquez <[email protected]>
1 parent c55530b commit 4e7aeff

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libcontainer/utils/cmsg.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func SendFd(socket *os.File, name string, fd uintptr) error {
8686
if len(name) >= MaxNameLen {
8787
return fmt.Errorf("sendfd: filename too long: %s", name)
8888
}
89-
oob := unix.UnixRights(int(fd))
90-
return unix.Sendmsg(int(socket.Fd()), []byte(name), oob, nil, 0)
89+
return SendFds(socket, []byte(name), int(fd))
90+
}
91+
92+
// SendFds sends a list of files descriptor and msg over the given AF_UNIX socket.
93+
func SendFds(socket *os.File, msg []byte, fds ...int) error {
94+
oob := unix.UnixRights(fds...)
95+
return unix.Sendmsg(int(socket.Fd()), msg, oob, nil, 0)
9196
}

0 commit comments

Comments
 (0)