From: Jeff King <peff@peff.net>
To: John Cai <johncai86@gmail.com>
Cc: John Cai via GitGitGadget <gitgitgadget@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] tmp-objdir: do not opendir() when handling a signal
Date: Tue, 27 Sep 2022 15:03:14 -0400 [thread overview]
Message-ID: <YzNI8tEpREMLNUpg@coredump.intra.peff.net> (raw)
In-Reply-To: <1B4D6262-532A-401E-B1A2-709BEECA4B67@gmail.com>
On Tue, Sep 27, 2022 at 09:50:43AM -0400, John Cai wrote:
> > diff --git a/tmp-objdir.c b/tmp-objdir.c
> > index a8be92bca1..10549e95db 100644
> > --- a/tmp-objdir.c
> > +++ b/tmp-objdir.c
> > @@ -169,7 +169,6 @@ struct tmp_objdir *tmp_objdir_create(const char *prefix)
> > the_tmp_objdir = t;
> > if (!installed_handlers) {
> > atexit(remove_tmp_objdir);
> > - sigchain_push_common(remove_tmp_objdir_on_signal);
> > installed_handlers++;
> > }
>
> This makes sense and is a clean solution. I guess the only case where we would
> benefit in calling into remove_tmp_objdir_on_signal() is if the temp dir exists
> but is empty. I'm not sure how often this would happen to make it worth it?
> Probably not...
It's more or less never, as the first thing we do after creating it is
call tmp_objdir_setup(), which creates the pack subdirectory. We _could_
try removing them both manually, like:
diff --git a/tmp-objdir.c b/tmp-objdir.c
index adf6033549..509eb58363 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -49,7 +49,17 @@ 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)
+ err = remove_dir_recursively(&t->path, 0);
+ else {
+ size_t orig_len = t->path.len;
+
+ strbuf_addstr(&t->path, "/pack");
+ rmdir(t->path.buf);
+ strbuf_setlen(&t->path, orig_len);
+
+ rmdir(t->path.buf);
+ }
/*
* When we are cleaning up due to a signal, we won't bother
but even that would rarely do anything useful. As soon as the child
index-pack receives even a single byte, we'll have an actual pack
tmpfile with an unknown name, which will cause rmdir() to fail (ditto
for unpack-objects, though it would probably write as soon as we've
received a whole single object).
If we can't enumerate the list of objects via readdir() or similar, I
think there's really not much we can do.
-Peff
next prev parent reply other threads:[~2022-09-27 19:03 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
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 [this message]
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=YzNI8tEpREMLNUpg@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johncai86@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 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).