All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Turner <novalis@novalis.org>
To: "Martin Ågren" <martin.agren@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH 2/5] refs.c: do not die if locking fails in `write_pseudoref()`
Date: Sun, 06 May 2018 11:48:51 -0400	[thread overview]
Message-ID: <1525621731.16035.11.camel@novalis.org> (raw)
In-Reply-To: <20180506141031.30204-3-martin.agren@gmail.com>

Re making the lock static, I wonder about the following case:
          
      if (read_ref(pseudoref, &actual_old_oid))
                        
die("could not read ref '%s'", pseudoref);

I think this calls exit(), and then atexit tries to clean up the lock
files.  But since lock is no longer static, the stack may have been
destroyed (I don't actually know whether this is true, so maybe someone
else does).

On Sun, 2018-05-06 at 16:10 +0200, Martin Ågren wrote:
> If we could not take the lock, we add an error to the `strbuf err`
> and
> return. However, this code is dead. The reason is that we take the
> lock
> using `LOCK_DIE_ON_ERROR`. Drop the flag to allow our more gentle
> error-handling to actually kick in.
> 
> We could instead just drop the dead code and die here. But everything
> is
> prepared for gently propagating the error, so let's do that instead.
> 
> There is similar dead code in `delete_pseudoref()`, but let's save
> that
> for the next patch.
> 
> While at it, make the lock non-static.
> 
> Signed-off-by: Martin Ågren <martin.agren@gmail.com>
> ---
>  refs.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/refs.c b/refs.c
> index 8b7a77fe5e..8c50b8b139 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -644,7 +644,7 @@ static int write_pseudoref(const char *pseudoref,
> const struct object_id *oid,
>  {
>  	const char *filename;
>  	int fd;
> -	static struct lock_file lock;
> +	struct lock_file lock = LOCK_INIT;
>  	struct strbuf buf = STRBUF_INIT;
>  	int ret = -1;
>  
> @@ -654,8 +654,7 @@ static int write_pseudoref(const char *pseudoref,
> const struct object_id *oid,
>  	strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
>  
>  	filename = git_path("%s", pseudoref);
> -	fd = hold_lock_file_for_update_timeout(&lock, filename,
> -					       LOCK_DIE_ON_ERROR,
> +	fd = hold_lock_file_for_update_timeout(&lock, filename, 0,
>  					       get_files_ref_lock_ti
> meout_ms());
>  	if (fd < 0) {
>  		strbuf_addf(err, "could not open '%s' for writing:
> %s",

  reply	other threads:[~2018-05-06 15:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-06 14:10 [PATCH 2/5] refs.c: do not die if locking fails in `write_pseudoref()` Martin Ågren
2018-05-06 15:48 ` David Turner [this message]
2018-05-06 15:56   ` Martin Ågren
2018-05-07 11:12     ` David Turner
2018-05-08 18:08       ` Jeff King
2018-05-07 18:48 ` Stefan Beller

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1525621731.16035.11.camel@novalis.org \
    --to=novalis@novalis.org \
    --cc=git@vger.kernel.org \
    --cc=martin.agren@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.