From: Taylor Blau <me@ttaylorr.com>
To: John Cai via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, John Cai <johncai86@gmail.com>,
Jeff King <peff@peff.net>
Subject: Re: [PATCH] tmp-objdir: do not opendir() when handling a signal
Date: Mon, 26 Sep 2022 20:18:47 -0400 [thread overview]
Message-ID: <YzJBZ9QJWIv0hpXb@nand.local> (raw)
In-Reply-To: <pull.1348.git.git.1664236383785.gitgitgadget@gmail.com>
[+cc Peff as the author of tmp-objdir]
On Mon, Sep 26, 2022 at 11:53:03PM +0000, John Cai via GitGitGadget wrote:
> One place we call tmp_objdir_create() is in git-receive-pack, where
> we create a temporary quarantine directory "incoming". Incoming
> objects will be written to this directory before they get moved to
> the object directory.
Right, calling opendir() will allocate memory, so we'll get stuck in a
deadlock if the signal arrives while libc's allocator lock is held. So
we can't safely call opendir() there.
It does make me a little uneasy leaving the quarantine directory around
via this path. So I wonder if we should be optimistically opening up the
DIR handle? Calling unlink() in a signal is perfectly fine, so I'd think
as long as we have an open DIR handle we could call readdir_r(), but I
don't think we've discussed it before.
> @@ -3261,7 +3261,10 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
> }
>
> flag &= ~REMOVE_DIR_KEEP_TOPLEVEL;
> - dir = opendir(path->buf);
> +
> + if ((flag & REMOVE_DIR_SIGNAL) == 0)
Comparing to the zero value is discouraged. Consider:
if (!(flag & REMOVE_DIR_SIGNAL))
instead.
> @@ -498,6 +498,9 @@ int get_sparse_checkout_patterns(struct pattern_list *pl);
> /* Remove the_original_cwd too */
> #define REMOVE_DIR_PURGE_ORIGINAL_CWD 0x08
>
> +/* Indicates a signal is being handled */
> +#define REMOVE_DIR_SIGNAL 0x16
> +
Perhaps REMOVE_DIR_IN_SIGNAL would be slightly more descriptive.
> @@ -49,7 +50,11 @@ static int tmp_objdir_destroy_1(struct tmp_objdir *t, int on_signal)
> * have pre-grown t->path sufficiently so that this
> * doesn't happen in practice.
> */
> - err = remove_dir_recursively(&t->path, 0);
> +
> + if (on_signal)
> + flags = flags | REMOVE_DIR_SIGNAL;
I'm nitpicking, but you could just write "flags |= REMOVE_DIR_SIGNAL",
or even:
err = remove_dir_recursively(&t->path,
on_signal ? REMOVE_DIR_SIGNAL : 0);
Thanks,
Taylor
next prev parent reply other threads:[~2022-09-27 0:18 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-26 23:53 [PATCH] tmp-objdir: do not opendir() when handling a signal John Cai via GitGitGadget
2022-09-27 0:18 ` Taylor Blau [this message]
2022-09-27 11:48 ` Jeff King
2022-09-27 1:39 ` Junio C Hamano
2022-09-27 9:18 ` Phillip Wood
2022-09-27 11:44 ` Jeff King
2022-09-27 13:50 ` John Cai
2022-09-27 19:03 ` Jeff King
2022-09-27 16:50 ` Junio C Hamano
2022-09-27 19:19 ` [PATCH v2] tmp-objdir: skip clean up " John Cai via GitGitGadget
2022-09-27 19:38 ` Jeff King
2022-09-27 20:00 ` Jeff King
2022-09-28 14:55 ` [PATCH v3] " John Cai via GitGitGadget
2022-09-28 15:38 ` Ævar Arnfjörð Bjarmason
2022-09-30 20:47 ` [PATCH v4] " John Cai via GitGitGadget
2022-10-03 8:52 ` Jeff King
2022-10-20 11:58 ` Another possible instance of async-signal-safe opendir path callstack? (Was: [PATCH] tmp-objdir: do not opendir() when handling a signal) Jan Pokorný
2022-10-20 18:21 ` Jeff King
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=YzJBZ9QJWIv0hpXb@nand.local \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johncai86@gmail.com \
--cc=peff@peff.net \
/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 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 NNTP newsgroup(s).