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

Re: [PATCH v5] lockfile: add PID file for debugging stale locks

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 21, 2026, 18:55 UTC
Message-ID
<xmqqcy32u769.fsf@gitster.g>
In-Reply-To
<20260121163924.GA576236@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
> The second half is still valid, I think, but at that point it is the
> only path that uses the close() in the out-path, so we might as well
> drop the out-path one.

True. A fix-up may look like this. I've got rid of the assignments to "fd" that are not used.

The changes to first two files simply revert unnecessary changes.
 builtin/commit.c | 3 ++-
 builtin/gc.c     | 6 ++++--
 lockfile.c       | 6 +-----
 3 files changed, 7 insertions(+), 8 deletions(-)
diff --git c/builtin/commit.c w/builtin/commit.c
index 4378256fa5..0243f17d53 100644
--- c/builtin/commit.c
+++ w/builtin/commit.c
@@ -539,7 +539,8 @@ static const char *prepare_index(const char **argv, const char *prefix,
 
 	path = repo_git_path(the_repository, "next-index-%"PRIuMAX,
 			     (uintmax_t) getpid());
-	hold_lock_file_for_update(&false_lock, path, LOCK_DIE_ON_ERROR);
+	hold_lock_file_for_update(&false_lock, path,
+				  LOCK_DIE_ON_ERROR);
 
 	create_base_index(current_head);
 	add_remove_files(&partial);
diff --git c/builtin/gc.c w/builtin/gc.c
index 1dcc8dd550..92c6e7b954 100644
--- c/builtin/gc.c
+++ w/builtin/gc.c
@@ -748,7 +748,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
 		xsnprintf(my_host, sizeof(my_host), "unknown");
 
 	pidfile_path = repo_git_path(the_repository, "gc.pid");
-	fd = hold_lock_file_for_update(&lock, pidfile_path, LOCK_DIE_ON_ERROR);
+	fd = hold_lock_file_for_update(&lock, pidfile_path,
+				       LOCK_DIE_ON_ERROR);
 	if (!force) {
 		static char locking_host[HOST_NAME_MAX + 1];
 		static char *scan_fmt;
@@ -1015,7 +1016,8 @@ int cmd_gc(int argc,
 
 	if (daemonized) {
 		char *path = repo_git_path(the_repository, "gc.log");
-		hold_lock_file_for_update(&log_lock, path, LOCK_DIE_ON_ERROR);
+		hold_lock_file_for_update(&log_lock, path,
+					  LOCK_DIE_ON_ERROR);
 		dup2(get_lock_file_fd(&log_lock), 2);
 		atexit(process_log_file_at_exit);
 		free(path);
diff --git c/lockfile.c w/lockfile.c
index 6d03c60d50..13e2ad1307 100644
--- c/lockfile.c
+++ w/lockfile.c
@@ -110,7 +110,7 @@ static struct tempfile *create_lock_pid_file(const char *pid_path, int mode)
 {
 	struct strbuf content = STRBUF_INIT;
 	struct tempfile *pid_tempfile = NULL;
-	int fd = -1;
+	int fd;
 
 	if (!lockfile_pid_enabled)
 		goto out;
@@ -123,18 +123,14 @@ static struct tempfile *create_lock_pid_file(const char *pid_path, int mode)
 	if (write_in_full(fd, content.buf, content.len) < 0) {
 		warning_errno(_("could not write lock pid file '%s'"), pid_path);
 		close(fd);
-		fd = -1;
 		unlink(pid_path);
 		goto out;
 	}
 
 	close(fd);
-	fd = -1;
 	pid_tempfile = register_tempfile(pid_path);
 
 out:
-	if (fd >= 0)
-		close(fd);
 	strbuf_release(&content);
 	return pid_tempfile;
 }
Previous: Jeff KingNext: Jeff King
Message 30 of 36 in “lockfile: add PID file for debugging stale locks”
  1. lockfile: add PID file for debugging stale locksPaulo Casaretto via GitGitGadget, Dec 2, 2025
  2. D. Ben KnobleDec 2, 2025
  3. Torsten BögershausenDec 3, 2025
  4. Jeff KingDec 3, 2025
  5. Junio C HamanoDec 3, 2025
  6. Jeff KingDec 3, 2025
  7. Taylor BlauDec 3, 2025
  8. Patrick SteinhardtDec 5, 2025
  9. Jeff KingDec 5, 2025
  10. Taylor BlauDec 3, 2025
  11. lockfile: add PID file for debugging stale locksPaulo Casaretto via GitGitGadget, Dec 17, 2025
  12. Junio C HamanoDec 18, 2025
  13. Junio C HamanoDec 18, 2025
  14. Junio C HamanoDec 18, 2025
  15. Ben KnobleDec 18, 2025
  16. Patrick SteinhardtDec 18, 2025
  17. lockfile: add PID file for debugging stale locksPaulo Casaretto via GitGitGadget, Dec 24, 2025
  18. Junio C HamanoDec 25, 2025
  19. Jeff KingDec 27, 2025
  20. Patrick SteinhardtJan 5, 2026
  21. lockfile: add PID file for debugging stale locksPaulo Casaretto via GitGitGadget, Jan 7, 2026
  22. Junio C HamanoJan 8, 2026
  23. D. Ben KnobleJan 8, 2026
  24. lockfile: add PID file for debugging stale locksPaulo Casaretto via GitGitGadget, Jan 20, 2026
  25. Junio C HamanoJan 20, 2026
  26. Jeff KingJan 21, 2026
  27. Eric SunshineJan 21, 2026
  28. Johannes SixtJan 21, 2026
  29. Jeff KingJan 21, 2026
  30. Junio C HamanoJan 21, 2026
  31. Jeff KingJan 21, 2026
  32. Junio C HamanoJan 21, 2026
  33. lockfile: add PID file for debugging stale locksPaulo Casaretto via GitGitGadget, Jan 22, 2026
  34. Junio C HamanoJan 22, 2026
  35. Patrick SteinhardtFeb 6, 2026
  36. Junio C HamanoFeb 6, 2026

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.