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

[PATCH 11/14] lock_repo_for_gc(): compute the path to "gc.pid" only once

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jun 8, 2015, 09:07 UTC
Message-ID
<532e3a4e4beea4e94f22ac4b11aafa6095763e0b.1433751986.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1433751986.git.mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/gc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index 6e18d35..4dc21b2 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -200,6 +200,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
 	uintmax_t pid;
 	FILE *fp;
 	int fd;
+	char *pidfile_path;
 
 	if (pidfile)
 		/* already locked */
@@ -208,12 +209,13 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
 	if (gethostname(my_host, sizeof(my_host)))
 		strcpy(my_host, "unknown");
 
-	fd = hold_lock_file_for_update(&lock, git_path("gc.pid"),
+	pidfile_path = git_pathdup("gc.pid");
+	fd = hold_lock_file_for_update(&lock, pidfile_path,
 				       LOCK_DIE_ON_ERROR);
 	if (!force) {
 		static char locking_host[128];
 		int should_exit;
-		fp = fopen(git_path("gc.pid"), "r");
+		fp = fopen(pidfile_path, "r");
 		memset(locking_host, 0, sizeof(locking_host));
 		should_exit =
 			fp != NULL &&
@@ -237,6 +239,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
 			if (fd >= 0)
 				rollback_lock_file(&lock);
 			*ret_pid = pid;
+			free(pidfile_path);
 			return locking_host;
 		}
 	}
@@ -247,7 +250,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
 	strbuf_release(&sb);
 	commit_lock_file(&lock);
 
-	pidfile = git_pathdup("gc.pid");
+	pidfile = pidfile_path;
 	sigchain_push_common(remove_pidfile_on_signal);
 	atexit(remove_pidfile);
 
-- 
2.1.4
Previous: Michael HaggertyNext: Michael Haggerty
Message 22 of 26 in “Introduce a tempfile module”
  1. 00/14 Introduce a tempfile moduleMichael Haggerty, Jun 8, 2015
  2. 01/14 Move lockfile API documentation to lockfile.hMichael Haggerty, Jun 8, 2015
  3. 02/14 tempfile: a new module for handling temporary filesMichael Haggerty, Jun 8, 2015
  4. Junio C HamanoJun 10, 2015
  5. Michael HaggertyJun 10, 2015
  6. Junio C HamanoJun 10, 2015
  7. 03/14 lockfile: remove some redundant functionsMichael Haggerty, Jun 8, 2015
  8. Junio C HamanoJun 10, 2015
  9. Johannes SixtJun 10, 2015
  10. 04/14 commit_lock_file(): use get_locked_file_path()Michael Haggerty, Jun 8, 2015
  11. 05/14 register_tempfile_object(): new function, extracted from create_tempfile()Michael Haggerty, Jun 8, 2015
  12. 06/14 tempfile: add several functions for creating temporary filesMichael Haggerty, Jun 8, 2015
  13. Junio C HamanoJun 10, 2015
  14. Michael HaggertyAug 10, 2015
  15. 07/14 register_tempfile(): new function to handle an existing temporary fileMichael Haggerty, Jun 8, 2015
  16. Junio C HamanoJun 10, 2015
  17. Michael HaggertyAug 10, 2015
  18. 08/14 write_shared_index(): use tempfile moduleMichael Haggerty, Jun 8, 2015
  19. Junio C HamanoJun 10, 2015
  20. 09/14 setup_temporary_shallow(): use tempfile moduleMichael Haggerty, Jun 8, 2015
  21. 10/14 diff: use tempfile moduleMichael Haggerty, Jun 8, 2015
  22. 11/14 lock_repo_for_gc(): compute the path to "gc.pid" only onceMichael Haggerty, Jun 8, 2015
  23. 12/14 gc: use tempfile module to handle gc.pid fileMichael Haggerty, Jun 8, 2015
  24. 13/14 credential-cache--daemon: delete socket from main()Michael Haggerty, Jun 8, 2015
  25. 14/14 credential-cache--daemon: use tempfile moduleMichael Haggerty, Jun 8, 2015
  26. Junio C HamanoJun 10, 2015

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.