1
0
mirror of https://github.com/opencontainers/runc.git synced 2025-04-18 19:44:09 +03:00

int/linux: add/use Recvfrom

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2025-03-25 14:55:33 -07:00
parent e655abc0da
commit 491326cdeb
2 changed files with 15 additions and 13 deletions

View File

@ -53,6 +53,18 @@ func Openat(dirfd int, path string, mode int, perm uint32) (fd int, err error) {
return fd, nil
}
// Recvfrom wraps [unix.Recvfrom].
func Recvfrom(fd int, p []byte, flags int) (n int, from unix.Sockaddr, err error) {
err = retryOnEINTR(func() error {
n, from, err = unix.Recvfrom(fd, p, flags)
return err
})
if err != nil {
return 0, nil, os.NewSyscallError("recvfrom", err)
}
return n, from, err
}
// Sendmsg wraps [unix.Sendmsg].
func Sendmsg(fd int, p, oob []byte, to unix.Sockaddr, flags int) error {
err := retryOnEINTR(func() error {

View File

@ -6,6 +6,7 @@ import (
"os"
"sync/atomic"
"github.com/opencontainers/runc/internal/linux"
"golang.org/x/sys/unix"
)
@ -42,20 +43,9 @@ func (s *syncSocket) WritePacket(b []byte) (int, error) {
}
func (s *syncSocket) ReadPacket() ([]byte, error) {
var (
size int
err error
)
for {
size, _, err = unix.Recvfrom(int(s.f.Fd()), nil, unix.MSG_TRUNC|unix.MSG_PEEK)
if err != unix.EINTR { //nolint:errorlint // unix errors are bare
break
}
}
size, _, err := linux.Recvfrom(int(s.f.Fd()), nil, unix.MSG_TRUNC|unix.MSG_PEEK)
if err != nil {
return nil, fmt.Errorf("fetch packet length from socket: %w", os.NewSyscallError("recvfrom", err))
return nil, fmt.Errorf("fetch packet length from socket: %w", err)
}
// We will only get a zero size if the socket has been closed from the
// other end (otherwise recvfrom(2) will block until a packet is ready). In