From cccdfd22436ede80b37311e73a5c8339054a7ff1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 4 Jun 2021 10:36:11 +0900 Subject: [PATCH] fsync(): be prepared to see EINTR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some platforms, like NonStop do not automatically restart fsync() when interrupted by a signal, even when that signal is setup with SA_RESTART. This can lead to test breakage, e.g., where "--progress" is used, thus SIGALRM is sent often, and can interrupt an fsync() syscall. Make sure we deal with such a case by retrying the syscall ourselves. Luckily, we call fsync() fron a single wrapper, fsync_or_die(), so the fix is fairly isolated. Reported-by: Randall S. Becker Helped-by: Jeff King Helped-by: Taylor Blau [jc: the above two did most of the work---I just tied the loose end] Helped-by: René Scharfe Signed-off-by: Junio C Hamano --- write-or-die.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/write-or-die.c b/write-or-die.c index eab8c8d0b9a..d33e68f6abb 100644 --- a/write-or-die.c +++ b/write-or-die.c @@ -57,8 +57,9 @@ void fprintf_or_die(FILE *f, const char *fmt, ...) void fsync_or_die(int fd, const char *msg) { - if (fsync(fd) < 0) { - die_errno("fsync error on '%s'", msg); + while (fsync(fd) < 0) { + if (errno != EINTR) + die_errno("fsync error on '%s'", msg); } }