mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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 <mauricio@kinvolk.io>
This commit is contained in:
committed by
Rodrigo Campos
parent
c55530bedc
commit
4e7aeff610
@@ -86,6 +86,11 @@ func SendFd(socket *os.File, name string, fd uintptr) error {
|
|||||||
if len(name) >= MaxNameLen {
|
if len(name) >= MaxNameLen {
|
||||||
return fmt.Errorf("sendfd: filename too long: %s", name)
|
return fmt.Errorf("sendfd: filename too long: %s", name)
|
||||||
}
|
}
|
||||||
oob := unix.UnixRights(int(fd))
|
return SendFds(socket, []byte(name), int(fd))
|
||||||
return unix.Sendmsg(int(socket.Fd()), []byte(name), oob, nil, 0)
|
}
|
||||||
|
|
||||||
|
// SendFds sends a list of files descriptor and msg over the given AF_UNIX socket.
|
||||||
|
func SendFds(socket *os.File, msg []byte, fds ...int) error {
|
||||||
|
oob := unix.UnixRights(fds...)
|
||||||
|
return unix.Sendmsg(int(socket.Fd()), msg, oob, nil, 0)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user