From 920be5902c47323add6db7e4b09bf6603b22fb50 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Tue, 6 Jul 2010 15:07:37 -0400 Subject: [PATCH] stap-client: diagnostics * csclient.cxx (compile_server_client::find_and_connect_to_server): Save vital stats of winning server for printing ... (compile_server_client::passes_0_4): ... here. (flush_to_stream): Use char-by-char copying. Avoid accidentally closing cerr/cout. * session.h: Add winning_server field. --- csclient.cxx | 33 ++++++++++++++++++++++----------- session.h | 3 ++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/csclient.cxx b/csclient.cxx index 8db504174..bf2b196f2 100644 --- a/csclient.cxx +++ b/csclient.cxx @@ -116,7 +116,7 @@ compile_server_client::passes_0_4 () // syntax errors, if any, are already printed if (s.verbose) { - clog << "Compilation using a server completed " + clog << "Passes: via server " << s.winning_server << " " << getmemusage() << TIMESPRINT << endl; @@ -402,7 +402,14 @@ compile_server_client::find_and_connect_to_server () ++servers; rc = compile_using_server (default_servers[i]); if (rc == 0) - return rc; // success! + { + s.winning_server = + default_servers[i].host_name + string(" [") + + default_servers[i].ip_address + string(":") + + lex_cast(default_servers[i].port) + string("]"); + return rc; // success! + } + } continue; } @@ -669,7 +676,7 @@ compile_server_client::read_from_file (const string &fname, int &data) goto error; } - f.close (); + // NB: not necessary to f.close (); return 0; // Success error: @@ -703,7 +710,7 @@ compile_server_client::write_to_file (const string &fname, const string &data) goto error; } - f.close (); + // NB: not necessary to f.close (); return 0; // Success error: @@ -729,16 +736,20 @@ compile_server_client::flush_to_stream (const string &fname, ostream &o) } // Stream the data - errno = 0; - o << f.rdbuf (); - if (f.fail ()) + + // NB: o << f.rdbuf() misbehaves for some reason, appearing to close o, + // which is unfortunate if o == cerr or cout. + while (1) { - cerr << "Error reading file '" << fname << "': "; - goto error; + errno = 0; + int c = f.get(); + if (f.eof ()) return 0; // normal exit + if (! f.good()) break; + o.put(c); + if (! o.good()) break; } - f.close (); - return 0; // Success + // NB: not necessary to f.close (); error: if (errno) diff --git a/session.h b/session.h index aaaaf1351..ebb0bf0c7 100644 --- a/session.h +++ b/session.h @@ -154,10 +154,11 @@ struct systemtap_session std::vector server_status_strings; std::vector specified_servers; std::vector server_args; + std::string winning_server; + // XXX: why? std::string host_name; std::string domain_name; - std::string &get_host_name (); std::string &get_domain_name (); void get_host_and_domain_name (); -- 2.43.5