From 3d381237c8a7d563f132e30789fa3cfc6f7c32f6 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 28 Sep 2012 14:28:13 -0700 Subject: [PATCH] stapdyn: Check and report the child exit status * stapdyn/dynutil.cxx (check_dyninst_exit): New, check how the given BPatch_process exited, and report failures. * stapdyn/stapdyn.cxx (main): Use check_dyninst_exit. * stapdyn/dynsdt.cxx (main): Use check_dyninst_exit. --- stapdyn/dynsdt.cxx | 2 +- stapdyn/dynutil.cxx | 26 ++++++++++++++++++++++++++ stapdyn/dynutil.h | 5 +++++ stapdyn/stapdyn.cxx | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/stapdyn/dynsdt.cxx b/stapdyn/dynsdt.cxx index 3c2eb6ac4..7df612eaf 100644 --- a/stapdyn/dynsdt.cxx +++ b/stapdyn/dynsdt.cxx @@ -368,7 +368,7 @@ main(int argc, const char* argv[]) } warnx("done!"); - return 0; + return check_dyninst_exit(app) ? EXIT_SUCCESS : EXIT_FAILURE; } /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ diff --git a/stapdyn/dynutil.cxx b/stapdyn/dynutil.cxx index 598cdb855..5c99bca14 100644 --- a/stapdyn/dynutil.cxx +++ b/stapdyn/dynutil.cxx @@ -112,4 +112,30 @@ check_dyninst_sebools(void) } +// Check whether a process exited cleanly +bool +check_dyninst_exit(BPatch_process *process) +{ + int code; + switch (process->terminationStatus()) + { + case ExitedNormally: + code = process->getExitCode(); + if (code == EXIT_SUCCESS) + return true; + warnx("Warning: child process exited with status %d", code); + return false; + + case ExitedViaSignal: + code = process->getExitSignal(); + warnx("Warning: child process exited with signal %d (%s)", + code, strsignal(code)); + return false; + + default: + return false; + } +} + + /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ diff --git a/stapdyn/dynutil.h b/stapdyn/dynutil.h index 111c7bac4..aa1521cd0 100644 --- a/stapdyn/dynutil.h +++ b/stapdyn/dynutil.h @@ -1,6 +1,8 @@ #ifndef DYNUTIL_H #define DYNUTIL_H +#include + // Check that environment DYNINSTAPI_RT_LIB exists and is a valid file. // If not, try to guess a good value and set it. bool check_dyninst_rt(void); @@ -8,4 +10,7 @@ bool check_dyninst_rt(void); // Check that SELinux settings are ok for Dyninst operation. bool check_dyninst_sebools(void); +// Check whether a process exited cleanly +bool check_dyninst_exit(BPatch_process *process); + #endif // DYNUTIL_H diff --git a/stapdyn/stapdyn.cxx b/stapdyn/stapdyn.cxx index 90e8686ff..ffa342c8c 100644 --- a/stapdyn/stapdyn.cxx +++ b/stapdyn/stapdyn.cxx @@ -344,7 +344,7 @@ main(int argc, char * const argv[]) * call_inferior_function(app, "stp_dyninst_session_exit"); */ - return 0; + return check_dyninst_exit(app) ? EXIT_SUCCESS : EXIT_FAILURE; } /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ -- 2.43.5