From 0e2f76b6f0ecb4b4c00a4c8001843b3c54bc08ad Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 18 Apr 2017 13:29:50 +0200 Subject: Finish agent and worker logic --- bbot/utility.txx | 91 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 16 deletions(-) (limited to 'bbot/utility.txx') diff --git a/bbot/utility.txx b/bbot/utility.txx index a613b11..edd674b 100644 --- a/bbot/utility.txx +++ b/bbot/utility.txx @@ -11,6 +11,8 @@ namespace bbot { + // run_*() + // template process run_io_start (tracer& t, @@ -18,7 +20,7 @@ namespace bbot O&& out, E&& err, const dir_path& cwd, - P&& p, + const P& p, A&&... args) { try @@ -40,17 +42,19 @@ namespace bbot template process_exit::code_type - run_io_finish_exit (tracer&, process& pr, P&& p) + run_io_finish_exit (tracer&, process& pr, const P& p) { try { pr.wait (); - if (!pr.exit->normal ()) - fail << "process " << p << " terminated abnormally: " - << pr.exit->description (); + const process_exit& e (*pr.exit); - return pr.exit->code (); + if (e.normal ()) + return e.code (); + + fail << "process " << p << " terminated abnormally: " + << e.description () << (e.core () ? " (core dumped)" : "") << endf; } catch (const process_error& e) { @@ -60,7 +64,7 @@ namespace bbot template inline void - run_io_finish (tracer& t, process& pr, P&& p) + run_io_finish (tracer& t, process& pr, const P& p) { if (run_io_finish_exit (t, pr, p) != 0) fail << "process " << p << " terminated with non-zero exit code"; @@ -95,6 +99,47 @@ namespace bbot run_io_finish (t, pr, p); } + // curl + // + template + http_curl:: + http_curl (tracer& t, + I&& in, + O&& out, + method_type m, + const string& url, + A&&... options) + : butl::curl ([&t] (const char* c[], size_t n) {run_trace (t, c, n);}, + forward (in), + forward (out), + 2, // Diagnostics to stderr. + m, + url, + "-A", BBOT_USER_AGENT, + forward (options)...) + { + } + + template + tftp_curl:: + tftp_curl (tracer& t, + I&& in, + O&& out, + method_type m, + const string& url, + A&&... options) + : butl::curl ([&t] (const char* c[], size_t n) {run_trace (t, c, n);}, + forward (in), + forward (out), + 2, // Diagnostics to stderr. + m, + url, + forward (options)...) + { + } + + // *_manifest() + // template T parse_manifest (const path& f, const char* what, bool ignore_unknown) @@ -107,23 +152,38 @@ namespace bbot fail << what << " manifest file " << f << " does not exist"; ifdstream ifs (f); - manifest_parser p (ifs, f.string ()); + return parse_manifest (ifs, f.string (), what, ignore_unknown); + } + catch (const system_error& e) // EACCES, etc. + { + fail << "unable to access " << what << " manifest " << f << ": " << e + << endf; + } + } + + template + T + parse_manifest (istream& is, + const string& name, + const char* what, + bool ignore_unknown) + { + using namespace butl; + + try + { + manifest_parser p (is, name); return T (p, ignore_unknown); } catch (const manifest_parsing& e) { fail << "invalid " << what << " manifest: " - << f << ':' << e.line << ':' << e.column << ": " << e.description + << name << ':' << e.line << ':' << e.column << ": " << e.description << endf; } catch (const io_error& e) { - fail << "unable to read " << what << " manifest " << f << ": " << e - << endf; - } - catch (const system_error& e) // EACCES, etc. - { - fail << "unable to access " << what << " manifest " << f << ": " << e + fail << "unable to read " << what << " manifest " << name << ": " << e << endf; } } @@ -158,7 +218,6 @@ namespace bbot const string& name, const char* what) { - using namespace std; using namespace butl; try -- cgit v1.1