]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsync(): be prepared to see EINTR
authorJunio C Hamano <gitster@pobox.com>
Fri, 4 Jun 2021 01:36:11 +0000 (10:36 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sat, 5 Jun 2021 13:13:40 +0000 (22:13 +0900)
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 <randall.becker@nexbridge.ca>
Helped-by: Jeff King <peff@peff.net>
Helped-by: Taylor Blau <me@ttaylorr.com>
[jc: the above two did most of the work---I just tied the loose end]
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
write-or-die.c

index eab8c8d0b9aab55c8435b9f451efd81e715131f8..d33e68f6abb30aed23d53909c1b855ad352a7baa 100644 (file)
@@ -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);
        }
 }