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

[RFC PATCH] wrapper: Introduce xclose to restart close on EINTR

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
May 20, 2011, 08:30 UTC
Message-ID
<1305880223-7542-3-git-send-email-artagnon@gmail.com>
In-Reply-To
<1305880223-7542-1-git-send-email-artagnon@gmail.com>
Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-compat-util.h |    1 +
 wrapper.c         |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 40498b3..6e06ad4 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -428,6 +428,7 @@ extern void *xcalloc(size_t nmemb, size_t size);
 extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
 extern ssize_t xread(int fd, void *buf, size_t len);
 extern ssize_t xwrite(int fd, const void *buf, size_t len);
+extern int xclose(int fd);
 extern int xdup(int fd);
 extern FILE *xfdopen(int fd, const char *mode);
 extern int xmkstemp(char *template);
diff --git a/wrapper.c b/wrapper.c
index 2829000..717e989 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -141,6 +141,21 @@ ssize_t xwrite(int fd, const void *buf, size_t len)
 	}
 }
 
+/*
+ * xclose() is the same a close(), but it automatically restarts close()
+ * operations with a recoverable error (EINTR).
+ */
+int xclose(int fd)
+{
+	int ret;
+	while (1) {
+		ret = close(fd);
+		if ((ret < 0) && errno == EINTR)
+			continue;
+		return ret;
+	}
+}
+
 ssize_t read_in_full(int fd, void *buf, size_t count)
 {
 	char *p = buf;
-- 
1.7.5.GIT
Previous: Jonathan NiederNext: Jonathan Nieder
Message 8 of 11 in “Better error-handling around revert”
  1. Ramkumar RamachandraMay 20, 2011
  2. Ramkumar RamachandraMay 20, 2011
  3. Christian CouderMay 21, 2011
  4. cache-tree: Teach write_cache_as_tree to discard_cacheRamkumar Ramachandra, May 20, 2011
  5. revert: Use assert to catch inherent program bugsRamkumar Ramachandra, May 20, 2011
  6. Junio C HamanoMay 20, 2011
  7. Jonathan NiederMay 20, 2011
  8. wrapper: Introduce xclose to restart close on EINTRRamkumar Ramachandra, May 20, 2011
  9. Jonathan NiederMay 20, 2011
  10. Junio C HamanoMay 20, 2011
  11. Jonathan NiederMay 20, 2011

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.