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

[PATCH 2/3] dump_marks(): reimplement using fdopen_lock_file()

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Oct 1, 2014, 11:14 UTC
Message-ID
<1412162089-3233-3-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1412162089-3233-1-git-send-email-mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 fast-import.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index deadc33..fee7906 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1794,20 +1794,18 @@ static void dump_marks_helper(FILE *f,
 static void dump_marks(void)
 {
 	static struct lock_file mark_lock;
-	int mark_fd;
 	FILE *f;
 
 	if (!export_marks_file)
 		return;
 
-	mark_fd = hold_lock_file_for_update(&mark_lock, export_marks_file, 0);
-	if (mark_fd < 0) {
+	if (hold_lock_file_for_update(&mark_lock, export_marks_file, 0) < 0) {
 		failure |= error("Unable to write marks file %s: %s",
 			export_marks_file, strerror(errno));
 		return;
 	}
 
-	f = fdopen(mark_fd, "w");
+	f = fdopen_lock_file(&mark_lock, "w");
 	if (!f) {
 		int saved_errno = errno;
 		rollback_lock_file(&mark_lock);
@@ -1816,22 +1814,7 @@ static void dump_marks(void)
 		return;
 	}
 
-	/*
-	 * Since the lock file was fdopen()'ed, it should not be close()'ed.
-	 * Assign -1 to the lock file descriptor so that commit_lock_file()
-	 * won't try to close() it.
-	 */
-	mark_lock.fd = -1;
-
 	dump_marks_helper(f, 0, marks);
-	if (ferror(f) || fclose(f)) {
-		int saved_errno = errno;
-		rollback_lock_file(&mark_lock);
-		failure |= error("Unable to write marks file %s: %s",
-			export_marks_file, strerror(saved_errno));
-		return;
-	}
-
 	if (commit_lock_file(&mark_lock)) {
 		failure |= error("Unable to commit marks file %s: %s",
 			export_marks_file, strerror(errno));
-- 
2.1.0
Previous: Michael HaggertyNext: Michael Haggerty
Message 7 of 9 in “Support stdio access to lockfiles”
  1. 0/3 Support stdio access to lockfilesMichael Haggerty, Oct 1, 2014
  2. 1/3 fdopen_lock_file(): access a lockfile using stdioMichael Haggerty, Oct 1, 2014
  3. Jeff KingOct 1, 2014
  4. Junio C HamanoOct 1, 2014
  5. Torsten BögershausenOct 2, 2014
  6. Michael HaggertyOct 12, 2014
  7. 2/3 dump_marks(): reimplement using fdopen_lock_file()Michael Haggerty, Oct 1, 2014
  8. 3/3 commit_packed_refs(): reimplement using fdopen_lock_file()Michael Haggerty, Oct 1, 2014
  9. Jeff KingOct 1, 2014

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.