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

@@ -16,6 +16,7 @@
#define GIT_COMMAND_TIMEOUT_MS 30000
typedef int (*git_main_fn)(int argc, const char **argv);
typedef int (*githug_git_main_fn)(int argc, const char **argv);
typedef void (*git_init_fn)(const char **argv);
struct output_buffer {
@@ -27,6 +28,7 @@ struct output_buffer {
static pthread_mutex_t git_mutex = PTHREAD_MUTEX_INITIALIZER;
static void *git_handle = NULL;
static git_main_fn git_main = NULL;
static githug_git_main_fn githug_git_main = NULL;
static git_init_fn git_init = NULL;
static int append_output(struct output_buffer *buffer, const char *data, size_t length) {
@@ -116,6 +118,7 @@ static int load_git(const char *library_path) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "dlsym init_git failed: %s", dlerror());
return -1;
}
githug_git_main = (githug_git_main_fn)dlsym(git_handle, "githug_git_main");
git_main = (git_main_fn)dlsym(git_handle, "cmd_main");
if (git_main == NULL) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "dlsym cmd_main failed: %s", dlerror());
@@ -274,8 +277,13 @@ Java_solutions_tretter_githugandroid_NativeGitBridge_runGitMainNative(
(void)saved_env;
chdir(working_directory_chars);
git_init((const char **)argv);
int child_exit_code = git_main(argc, (const char **)argv);
int child_exit_code;
if (githug_git_main != NULL) {
child_exit_code = githug_git_main(argc, (const char **)argv);
} else {
git_init((const char **)argv);
child_exit_code = git_main(argc, (const char **)argv);
}
fflush(stdout);
fflush(stderr);
_exit(child_exit_code);

View File

@@ -196,7 +196,7 @@ class GitRepositoryRuntime private constructor(
addAll(GitSandboxEngine.commandReferenceLines())
add("Native Git runtime:")
add(" binary path: nativeLibraryDir/libgit.so")
add(" invocation: init_git(argv), then cmd_main(argc, argv)")
add(" invocation: githug_git_main(argc, argv)")
add(" selected ABI: ${Build.SUPPORTED_ABIS.firstOrNull() ?: "unknown"}")
add(" helper commands: ls/dir, pwd, cat, sh <script>, ./<script>, touch, mkdir/md, cd.., rm/del, echo")
add(" visual editors: vi, vim, nano, emacs, ed, ex, edit, notepad")