From 803fdf410bb57d34ef09357ec4924646978c20b5 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 11 Oct 2020 01:31:09 +0200 Subject: syscallcompat: Openat: retry on EINTR Towards fixing https://github.com/rfjakob/gocryptfs/issues/507 --- internal/syscallcompat/sys_common.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'internal/syscallcompat') diff --git a/internal/syscallcompat/sys_common.go b/internal/syscallcompat/sys_common.go index d5e3251..c50c940 100644 --- a/internal/syscallcompat/sys_common.go +++ b/internal/syscallcompat/sys_common.go @@ -44,7 +44,7 @@ func Faccessat(dirfd int, path string, mode uint32) error { return unix.Faccessat(dirfd, path, mode, 0) } -// Openat wraps the Openat syscall. +// Openat wraps the Openat syscall, retrying on EINTR. func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) { if flags&syscall.O_CREAT != 0 { // O_CREAT should be used with O_EXCL. O_NOFOLLOW has no effect with O_EXCL. @@ -59,7 +59,14 @@ func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) flags |= syscall.O_NOFOLLOW } } - return unix.Openat(dirfd, path, flags, mode) + // Like ignoringEINTR() in the Go stdlib: + // https://github.com/golang/go/blob/d2a80f3fb5b44450e0b304ac5a718f99c053d82a/src/os/file_posix.go#L243 + for { + fd, err = unix.Openat(dirfd, path, flags, mode) + if err != unix.EINTR { + return fd, err + } + } } // Renameat wraps the Renameat syscall. -- cgit v1.2.3