aboutsummaryrefslogtreecommitdiff
path: root/run-command.c
diff options
context:
space:
mode:
authorEtienne Buira <etienne.buira@gmail.com>2014-10-18 14:31:15 +0200
committerJunio C Hamano <gitster@pobox.com>2014-10-19 15:38:30 -0700
commit0f4b6db3baeff8de53769b38f439408abd5a42f7 (patch)
treed39a29a7792df19e576e67c8cee9f68d4f54e2ea /run-command.c
parent0c45d258ec35c1ef51523dd45e4518bd8a09258c (diff)
downloadgit-0f4b6db3baeff8de53769b38f439408abd5a42f7.tar.gz
git-0f4b6db3baeff8de53769b38f439408abd5a42f7.tar.xz
Handle atexit list internaly for unthreaded builds
Wrap atexit()s calls on unthreaded builds to handle callback list internally. This is needed because on unthreaded builds, asyncs inherits parent's atexit() list, that gets run as soon as the async exit()s (and again at the end of async's parent process). That led to remove temporary files too early. Also remove a by-atexit-callback guard against this kind of issue in clone.c, as this patch makes it redundant. Fixes test 5537 (temporary shallow file vanished before unpack-objects could open it) BTW remove an unused variable in shallow.c. Helped-by: Duy Nguyen <pclouds@gmail.com> Helped-by: Andreas Schwab <schwab@linux-m68k.org> Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Etienne Buira <etienne.buira@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'run-command.c')
-rw-r--r--run-command.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/run-command.c b/run-command.c
index 761f0fde4..41d94c111 100644
--- a/run-command.c
+++ b/run-command.c
@@ -620,6 +620,45 @@ static int async_die_is_recursing(void)
return ret != NULL;
}
+#else
+
+static struct {
+ void (**handlers)(void);
+ size_t nr;
+ size_t alloc;
+} git_atexit_hdlrs;
+
+static int git_atexit_installed;
+
+static void git_atexit_dispatch()
+{
+ size_t i;
+
+ for (i=git_atexit_hdlrs.nr ; i ; i--)
+ git_atexit_hdlrs.handlers[i-1]();
+}
+
+static void git_atexit_clear()
+{
+ free(git_atexit_hdlrs.handlers);
+ memset(&git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
+ git_atexit_installed = 0;
+}
+
+#undef atexit
+int git_atexit(void (*handler)(void))
+{
+ ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, git_atexit_hdlrs.alloc);
+ git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
+ if (!git_atexit_installed) {
+ if (atexit(&git_atexit_dispatch))
+ return -1;
+ git_atexit_installed = 1;
+ }
+ return 0;
+}
+#define atexit git_atexit
+
#endif
int start_async(struct async *async)
@@ -678,6 +717,7 @@ int start_async(struct async *async)
close(fdin[1]);
if (need_out)
close(fdout[0]);
+ git_atexit_clear();
exit(!!async->proc(proc_in, proc_out, async->data));
}