Fix Android native Git child exit handling so committed levels validate and Git calls avoid SIGSEGV status 139

This commit is contained in:
Joe Tretter
2026-06-25 14:56:35 -05:00
parent 60dd3c82f7
commit 2db8fdd328
6 changed files with 66 additions and 8 deletions

View File

@@ -0,0 +1,49 @@
diff --git a/common-main.c b/common-main.c
index 0000000000..0000000000 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,6 +1,27 @@
#include "git-compat-util.h"
#include "common-init.h"
+#ifdef GITHUG_EMBEDDED_MAIN
+void githug_exit(int code)
+{
+ code &= 0xff;
+ fflush(stdout);
+ fflush(stderr);
+ _exit(code);
+}
+
+int githug_git_main(int argc, const char **argv)
+{
+ int result;
+
+ init_git(argv);
+ result = cmd_main(argc, argv);
+
+ /* Match Git's real main(), but return instead of calling libc exit(). */
+ return common_exit(__FILE__, __LINE__, result);
+}
+#endif
+
int main(int argc, const char **argv)
{
int result;
diff --git a/git-compat-util.h b/git-compat-util.h
index 0000000000..0000000000 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1047,7 +1047,12 @@ int cmd_main(int, const char **);
* optionally emit a message before calling the real exit().
*/
int common_exit(const char *file, int line, int code);
+#ifdef GITHUG_EMBEDDED_MAIN
+NORETURN void githug_exit(int code);
+#define exit(code) githug_exit(common_exit(__FILE__, __LINE__, (code)))
+#else
#define exit(code) exit(common_exit(__FILE__, __LINE__, (code)))
+#endif
/*
* This include must come after system headers, since it introduces macros that