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

Re: [PATCH v2 13/16] lock_repo_for_gc(): compute the path to "gc.pid" only once

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 11, 2015, 20:06 UTC
Message-ID
<xmqq4mk5r3nf.fsf@gitster.dls.corp.google.com>
In-Reply-To
<e34adde5b2cc3adbcd011ee06aeab93b3459a883.1439198011.git.mhagger@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 25 quoted lines
> 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 36fe333..c41354b 100644
> --- a/builtin/gc.c
> +++ b/builtin/gc.c
> @@ -199,6 +199,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 */
> @@ -207,12 +208,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);

Looks correct; somehow this reminded me of the other topic from Peff to reduce use of git_path() ;-)

> -	pidfile = git_pathdup("gc.pid");
> +	pidfile = pidfile_path;
>  	sigchain_push_common(remove_pidfile_on_signal);
>  	atexit(remove_pidfile);

I wonder if you can reduce the atexit() here by registering this as a tempfile to be cleared?

Previous: Michael HaggertyNext: Junio C Hamano
Message 23 of 29 in “Introduce a tempfile module”
  1. 00/16 Introduce a tempfile moduleMichael Haggerty, Aug 10, 2015
  2. 01/16 Move lockfile documentation to lockfile.h and lockfile.cMichael Haggerty, Aug 10, 2015
  3. Junio C HamanoAug 11, 2015
  4. 02/16 create_bundle(): duplicate file descriptor to avoid closing it twiceMichael Haggerty, Aug 10, 2015
  5. 03/16 lockfile: add accessors get_lock_file_fd() and get_lock_file_fp()Michael Haggerty, Aug 10, 2015
  6. Junio C HamanoAug 11, 2015
  7. 04/16 lockfile: add accessor get_lock_file_path()Michael Haggerty, Aug 10, 2015
  8. Junio C HamanoAug 11, 2015
  9. 05/16 commit_lock_file(): use get_locked_file_path()Michael Haggerty, Aug 10, 2015
  10. 06/16 tempfile: a new module for handling temporary filesMichael Haggerty, Aug 10, 2015
  11. 07/16 prepare_tempfile_object(): new function, extracted from create_tempfile()Michael Haggerty, Aug 10, 2015
  12. Junio C HamanoAug 11, 2015
  13. 08/16 tempfile: add several functions for creating temporary filesMichael Haggerty, Aug 10, 2015
  14. 09/16 register_tempfile(): new function to handle an existing temporary fileMichael Haggerty, Aug 10, 2015
  15. 10/16 write_shared_index(): use tempfile moduleMichael Haggerty, Aug 10, 2015
  16. 11/16 setup_temporary_shallow(): use tempfile moduleMichael Haggerty, Aug 10, 2015
  17. 12/16 diff: use tempfile moduleMichael Haggerty, Aug 10, 2015
  18. Junio C HamanoAug 11, 2015
  19. Michael HaggertyAug 12, 2015
  20. Junio C HamanoAug 12, 2015
  21. 12/16 diff: use tempfile moduleMichael Haggerty, Aug 12, 2015
  22. 13/16 lock_repo_for_gc(): compute the path to "gc.pid" only onceMichael Haggerty, Aug 10, 2015
  23. Junio C HamanoAug 11, 2015
  24. Junio C HamanoAug 11, 2015
  25. 14/16 gc: use tempfile module to handle gc.pid fileMichael Haggerty, Aug 10, 2015
  26. 15/16 credential-cache--daemon: delete socket from main()Michael Haggerty, Aug 10, 2015
  27. 16/16 credential-cache--daemon: use tempfile moduleMichael Haggerty, Aug 10, 2015
  28. Junio C HamanoAug 11, 2015
  29. Michael HaggertyAug 12, 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.