From f014b0d6daf8cc02626d642d748f2c02718f82d7 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Thu, 24 Jul 2014 00:31:57 -0400 Subject: [PATCH 1/3] client: return a possible error code to the core client if execv fails for some reason in the switcher tool. --- client/switcher.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/switcher.cpp b/client/switcher.cpp index 7bc1aa84f0..3200ed62dc 100644 --- a/client/switcher.cpp +++ b/client/switcher.cpp @@ -130,9 +130,13 @@ int main(int /*argc*/, char** argv) { #endif } - execv(argv[1], argv+2); + retval = execv(argv[1], argv+2); + if (retval == -1) { + retval = errno; - // If we got here execv failed - fprintf(stderr, "Process creation (%s) failed: errno=%d\n", argv[1], errno); + // If we got here execv failed + fprintf(stderr, "Process creation (%s) failed: %s (errno = %d)\n", argv[1], strerror(retval), retval); + } + return retval; } From 99daa414455981a9c3237f1596fa22e81eb23a22 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 24 Jul 2014 01:06:43 -0700 Subject: [PATCH 2/3] client: attempt to get a more useful error message from kill_app_process() on non-Windows platforms. --- client/app_control.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/app_control.cpp b/client/app_control.cpp index 6a088b82da..01a8904c8f 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -224,7 +224,7 @@ static void kill_app_process(int pid, bool) { if (retval && log_flags.task_debug) { msg_printf(0, MSG_INFO, "[task] kill_via_switcher() failed: %s", - boincerror(retval) + (retval==-1) ? strerror(errno) : boincerror(retval) ); } #endif @@ -232,7 +232,7 @@ static void kill_app_process(int pid, bool) { if (retval && log_flags.task_debug) { msg_printf(0, MSG_INFO, "[task] kill() failed: %s", - boincerror(retval) + (retval==-1) ? strerror(errno) : boincerror(retval) ); } } @@ -268,6 +268,7 @@ int ACTIVE_TASK::kill_running_task(bool will_restart) { int ACTIVE_TASK::kill_exited_task() { kill_processes(other_pids, true); kill_processes(descendants, true); + return 0; } // We have sent a quit request to the process; see if it's exited. From fb66dd82ae4e47a3918db9cf9a73f8296a6483b0 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 24 Jul 2014 02:39:17 -0700 Subject: [PATCH 3/3] client: try to get a return code from switcher (i.e., from the command that switcher executed.) --- client/sandbox.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/sandbox.cpp b/client/sandbox.cpp index ff6ff93a23..776726eca8 100644 --- a/client/sandbox.cpp +++ b/client/sandbox.cpp @@ -95,6 +95,7 @@ int set_to_project_group(const char* path) { int switcher_exec(const char *util_filename, const char* cmdline) { char* argv[100]; char util_path[MAXPATHLEN]; + int stat; sprintf(util_path, "%s/%s", SWITCHER_DIR, util_filename); argv[0] = const_cast(util_filename); @@ -111,7 +112,12 @@ int switcher_exec(const char *util_filename, const char* cmdline) { return ERR_EXEC; } // Wait for command to complete, like system() does. - waitpid(pid, 0, 0); + waitpid(pid, &stat, 0); + + if (WIFEXITED(stat)) { + return WEXITSTATUS(stat); + } + return 0; }