From e95c9fb15fc6b5cdb46dce60579962613762fc49 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Wed, 15 Dec 2021 10:45:02 +0000 Subject: [PATCH] return exit status in change_sysroot --- util/change_sysroot.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/util/change_sysroot.c b/util/change_sysroot.c index 6ca373a..0d561c4 100644 --- a/util/change_sysroot.c +++ b/util/change_sysroot.c @@ -100,7 +100,7 @@ int main(int argc, char **argv) { basePID = pid; } - while (kill(basePID, 0) == 0 /* still alive */) { + while (true) { struct user_regs_struct registers = { 0 }; pid_t pid = waitpid(-1, 0, 0); @@ -161,15 +161,18 @@ int main(int argc, char **argv) { printf("unhandled syscall %llu\n", registers.orig_rax); } + int status; ptrace(PTRACE_SYSCALL, pid, 0, 0); - waitpid(pid, 0, 0); + waitpid(pid, &status, 0); if (ptrace(PTRACE_GETREGS, pid, 0, ®isters) == -1) { - // The process has likely exited. + // The process has exited. + + if (pid == basePID) { + return WEXITSTATUS(status); + } } else { ptrace(PTRACE_SYSCALL, pid, 0, 0); } } - - return 0; }