git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/3] wrapper: handle EINTR in `git_fsync()`

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 10, 2021, 11:40 UTC
Message-ID
<0c8e98295e91b656a89e1db53bfe02e7c7fc8432.1636544377.git.ps@pks.im>
In-Reply-To
<cover.1636544377.git.ps@pks.im>

While we already have a wrapper around `git_fsync()`, this wrapper doesn't handle looping around `EINTR`. Convert it to do so such that callers don't have to remember doing this everywhere.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 wrapper.c      | 9 ++++++++-
 write-or-die.c | 6 ++----
 2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/wrapper.c b/wrapper.c
index ece3d2ca10..e20df4f3a6 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -546,7 +546,7 @@ int xmkstemp_mode(char *filename_template, int mode)
 	return fd;
 }
 
-int git_fsync(int fd, enum fsync_action action)
+static int git_fsync_once(int fd, enum fsync_action action)
 {
 	switch (action) {
 	case FSYNC_WRITEOUT_ONLY:
@@ -591,7 +591,14 @@ int git_fsync(int fd, enum fsync_action action)
 	default:
 		BUG("unexpected git_fsync(%d) call", action);
 	}
+}
 
+int git_fsync(int fd, enum fsync_action action)
+{
+	while (git_fsync_once(fd, action) < 0)
+		if (errno != EINTR)
+			return -1;
+	return 0;
 }
 
 static int warn_if_unremovable(const char *op, const char *file, int rc)
diff --git a/write-or-die.c b/write-or-die.c
index cc8291d979..e61220aa2d 100644
--- a/write-or-die.c
+++ b/write-or-die.c
@@ -57,10 +57,8 @@ void fprintf_or_die(FILE *f, const char *fmt, ...)
 
 void fsync_or_die(int fd, const char *msg)
 {
-	while (git_fsync(fd, FSYNC_HARDWARE_FLUSH) < 0) {
-		if (errno != EINTR)
-			die_errno("fsync error on '%s'", msg);
-	}
+	if (git_fsync(fd, FSYNC_HARDWARE_FLUSH) < 0)
+		die_errno("fsync error on '%s'", msg);
 }
 
 void write_or_die(int fd, const void *buf, size_t count)
-- 
2.33.1
Previous: Patrick SteinhardtNext: Johannes Schindelin
Message 19 of 34 in “refs: sync loose refs to disk before committing them”
  1. refs: sync loose refs to disk before committing themPatrick Steinhardt, Nov 4, 2021
  2. Ævar Arnfjörð BjarmasonNov 4, 2021
  3. Patrick SteinhardtNov 4, 2021
  4. Junio C HamanoNov 4, 2021
  5. Neeraj SinghNov 4, 2021
  6. Junio C HamanoNov 5, 2021
  7. Jeff KingNov 5, 2021
  8. Ævar Arnfjörð BjarmasonNov 5, 2021
  9. Jeff KingNov 5, 2021
  10. Jeff KingNov 5, 2021
  11. Jeff KingNov 5, 2021
  12. Johannes SchindelinNov 5, 2021
  13. Patrick SteinhardtNov 5, 2021
  14. Jeff KingNov 5, 2021
  15. Patrick SteinhardtNov 9, 2021
  16. Jeff KingNov 10, 2021
  17. Patrick SteinhardtNov 10, 2021
  18. 0/3 refs: sync loose refs to disk before committing themPatrick Steinhardt, Nov 10, 2021
  19. 1/3 wrapper: handle EINTR in `git_fsync()`Patrick Steinhardt, Nov 10, 2021
  20. Johannes SchindelinNov 10, 2021
  21. Ævar Arnfjörð BjarmasonNov 10, 2021
  22. 2/3 wrapper: provide function to sync directoriesPatrick Steinhardt, Nov 10, 2021
  23. Ævar Arnfjörð BjarmasonNov 10, 2021
  24. 3/3 refs: add configuration to enable flushing of refsPatrick Steinhardt, Nov 10, 2021
  25. Ævar Arnfjörð BjarmasonNov 10, 2021
  26. Neeraj SinghNov 10, 2021
  27. Ævar Arnfjörð BjarmasonNov 10, 2021
  28. Neeraj SinghNov 11, 2021
  29. Patrick SteinhardtNov 11, 2021
  30. Patrick SteinhardtNov 11, 2021
  31. Neeraj SinghNov 11, 2021
  32. Johannes SchindelinNov 10, 2021
  33. Jeff KingNov 10, 2021
  34. Patrick SteinhardtNov 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.