From ae5cab7489fe014dd3aa818cf2655d7a4714af83 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 16 Dec 2017 17:42:12 +0200 Subject: Improve process execution diagnostics by reusing run_*() API --- build2/utility.cxx | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'build2/utility.cxx') diff --git a/build2/utility.cxx b/build2/utility.cxx index df19b92..e8e5fe9 100644 --- a/build2/utility.cxx +++ b/build2/utility.cxx @@ -208,29 +208,32 @@ namespace build2 } process - run_start (const process_path& pp, const char* args[], bool err) + run_start (const process_path& pp, + const char* args[], + int out, + bool err, + const dir_path& cwd) + try { assert (args[0] == pp.recall_string ()); - - if (verb >= 3) - print_process (args); - - try - { - return process (pp, args, 0, -1, (err ? 2 : 1)); - } - catch (const process_error& e) + return process (pp, args, 0, out, (err ? 2 : 1), cwd.string ().c_str ()); + } + catch (const process_error& e) + { + if (e.child) { - if (e.child) - { - // Note: run_finish() expects this exact message. - // - cerr << "unable to execute " << args[0] << ": " << e << endl; - exit (1); - } - else - fail << "unable to execute " << args[0] << ": " << e << endf; + // Note: run_finish() expects this exact message. + // + cerr << "unable to execute " << args[0] << ": " << e << endl; + + // In a multi-threaded program that fork()'ed but did not exec(), it is + // unwise to try to do any kind of cleanup (like unwinding the stack and + // running destructors). + // + exit (1); } + else + fail << "unable to execute " << args[0] << ": " << e << endf; } bool @@ -240,6 +243,14 @@ namespace build2 if (pr.wait ()) return true; + const process_exit& e (*pr.exit); + + if (!e.normal ()) + fail << "process " << args[0] << " terminated abnormally: " + << e.description () << (e.core () ? " (core dumped)" : ""); + + // Normall but non-zero exit status. + // if (err) // Assuming diagnostics has already been issued (to STDERR). // -- cgit v1.1