Introduce and use internal/linux

This package is to provide unix.* wrappers to ensure that:
 - they retry on EINTR;
 - a "rich" error is returned on failure.

 A first such wrapper, Sendmsg, is introduced.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-03-25 14:24:20 -07:00
parent e5895f1100
commit 8cc1eb379b
4 changed files with 39 additions and 9 deletions
+2 -6
View File
@@ -21,6 +21,7 @@ import (
"os"
"runtime"
"github.com/opencontainers/runc/internal/linux"
"golang.org/x/sys/unix"
)
@@ -126,10 +127,5 @@ func SendFile(socket *os.File, file *os.File) error {
// SendRawFd sends a specific file descriptor over the given AF_UNIX socket.
func SendRawFd(socket *os.File, msg string, fd uintptr) error {
oob := unix.UnixRights(int(fd))
for {
err := unix.Sendmsg(int(socket.Fd()), []byte(msg), oob, nil, 0)
if err != unix.EINTR {
return os.NewSyscallError("sendmsg", err)
}
}
return linux.Sendmsg(int(socket.Fd()), []byte(msg), oob, nil, 0)
}