From: Duy Nguyen <pclouds@gmail.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Matthieu Moy <Matthieu.Moy@imag.fr>,
Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] gc: remove gc.pid file at end of execution
Date: Sat, 28 Sep 2013 10:42:41 +0700 [thread overview]
Message-ID: <CACsJy8Ax1YypAnVb0FAQPsvvZixq0aJHP=ahfMaXn26KTaN1VA@mail.gmail.com> (raw)
In-Reply-To: <20130928003319.GR9464@google.com>
On Sat, Sep 28, 2013 at 7:33 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Matthieu Moy wrote:
>
>> This file isn't really harmful, but isn't useful either, and can create
>> minor annoyance for the user:
>
> Would something like the following make sense, to ensure the gc.pid file is
> always removed on normal exit?
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
>
> diff --git c/builtin/gc.c i/builtin/gc.c
> index 6e0d81a..fbbc144 100644
> --- c/builtin/gc.c
> +++ i/builtin/gc.c
> @@ -14,6 +14,7 @@
> #include "cache.h"
> #include "parse-options.h"
> #include "run-command.h"
> +#include "sigchain.h"
> #include "argv-array.h"
>
> #define FAILED_RUN "failed to run %s"
> @@ -167,6 +168,21 @@ static int need_to_gc(void)
> return 1;
> }
>
> +static char *pidfile;
> +
> +static void remove_pidfile(void)
> +{
> + if (pidfile)
> + unlink(pidfile);
> +}
> +
> +static void remove_pidfile_on_signal(int signo)
> +{
> + remove_pidfile();
> + sigchain_pop(signo);
> + raise(signo);
> +}
> +
> /* return NULL on success, else hostname running the gc */
> static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
> {
> @@ -179,13 +195,19 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
> FILE *fp;
> int fd, should_exit;
>
> + if (pidfile)
> + /* already locked */
> + return NULL;
> +
> if (gethostname(my_host, sizeof(my_host)))
> strcpy(my_host, "unknown");
>
> - fd = hold_lock_file_for_update(&lock, git_path("gc.pid"),
> + pidfile = git_pathdup("gc.pid");
> +
> + fd = hold_lock_file_for_update(&lock, pidfile,
> LOCK_DIE_ON_ERROR);
> if (!force) {
> - fp = fopen(git_path("gc.pid"), "r");
> + fp = fopen(pidfile, "r");
> memset(locking_host, 0, sizeof(locking_host));
> should_exit =
> fp != NULL &&
> @@ -208,6 +230,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
> if (should_exit) {
> if (fd >= 0)
> rollback_lock_file(&lock);
> + pidfile = NULL;
> *ret_pid = pid;
> return locking_host;
> }
> @@ -219,6 +242,9 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
> strbuf_release(&sb);
It may be a bit simpler to delay setting pidfile until we get here.
lock.filename still contains gc.pid until commit_lock_file is called.
> commit_lock_file(&lock);
>
> + sigchain_push_common(remove_pidfile_on_signal);
> + atexit(remove_pidfile);
> +
> return NULL;
> }
--
Duy
next prev parent reply other threads:[~2013-09-28 3:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-26 9:18 [PATCH] gc: remove gc.pid file at end of execution Matthieu Moy
2013-09-28 0:33 ` Jonathan Nieder
2013-09-28 3:42 ` Duy Nguyen [this message]
2013-10-16 21:38 ` Junio C Hamano
2013-10-16 23:11 ` [PATCH v2] " Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACsJy8Ax1YypAnVb0FAQPsvvZixq0aJHP=ahfMaXn26KTaN1VA@mail.gmail.com' \
--to=pclouds@gmail.com \
--cc=Matthieu.Moy@imag.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).