diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-12-16 17:42:12 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-12-16 17:42:12 +0200 |
commit | ae5cab7489fe014dd3aa818cf2655d7a4714af83 (patch) | |
tree | a80fdc22ce5909b98bd58292aaf8e2bc28e70492 /build2/utility.cxx | |
parent | 530e8914ba00ce0e7ee89ba30d2b88f2c09f43c9 (diff) |
Improve process execution diagnostics by reusing run_*() API
Diffstat (limited to 'build2/utility.cxx')
-rw-r--r-- | build2/utility.cxx | 49 |
1 files changed, 30 insertions, 19 deletions
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). // |