From: Josh Stone Date: Tue, 8 Feb 2011 23:06:25 +0000 (-0800) Subject: Clean up exit paths X-Git-Tag: release-1.5~259 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=504d2b61306d133bfde0dcfee542eb48479b6851;p=systemtap.git Clean up exit paths We need to strive not to leave files/processes around, so exit() calls are reduced to only places where nothings been allocated yet. Errors are rarely so fatal to require immediate exit. --- diff --git a/buildrun.cxx b/buildrun.cxx index b57a2ca18..e07feeb98 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -688,8 +688,15 @@ make_typequery(systemtap_session& s, string& module) if (end == string::npos) return -1; string header = module.substr(i, end - i); - assert_regexp_match("@cast header", header, "^[a-z0-9/_.+-]+$"); - headers.push_back(header); + vector matches; + if (regexp_match(header, "^[a-z0-9/_.+-]+$", matches)) + { + if (! s.suppress_warnings) + cerr << "Warning: skipping malformed @cast header \"" + << header << "\"" << endl; + } + else + headers.push_back(header); } if (headers.empty()) return -1; diff --git a/coveragedb.cxx b/coveragedb.cxx index ae88f24d9..28f19ecca 100644 --- a/coveragedb.cxx +++ b/coveragedb.cxx @@ -334,7 +334,7 @@ void update_coverage_db(systemtap_session &s) if( rc ){ cerr << "Can't open database: " << sqlite3_errmsg(db) << endl; sqlite3_close(db); - exit(EXIT_FAILURE); + return; } // lock the database diff --git a/main.cxx b/main.cxx index a338f4a22..a205a0b3c 100644 --- a/main.cxx +++ b/main.cxx @@ -366,11 +366,11 @@ int parse_kernel_exports (systemtap_session &s) } -static void +static int create_temp_dir (systemtap_session &s) { if (!s.tmpdir.empty()) - return; + return 0; // Create a temporary directory to build within. // Be careful with this, as "tmpdir" is "rm -rf"'d at the end. @@ -389,7 +389,7 @@ create_temp_dir (systemtap_session &s) //we can't make the directory due to the error cerr << autosprintf(_("ERROR: cannot create temporary directory (\" %s \"): %s"), tmpdirt.c_str(), e) << endl; //cerr << "ERROR: cannot create temporary directory (\"" << tmpdirt << "\"): " << e << endl; - exit (1); // die + return 1; } else s.tmpdir = tmpdir_name; @@ -397,6 +397,7 @@ create_temp_dir (systemtap_session &s) if (s.verbose>1) clog << autosprintf(_("Created temporary directory \"%s\""), s.tmpdir.c_str()) << endl; //clog << "Created temporary directory \"" << s.tmpdir << "\"" << endl; + return 0; } static void @@ -430,9 +431,22 @@ passes_0_4 (systemtap_session &s) { int rc = 0; + // If we don't know the release, there's no hope either locally or on a server. + if (s.kernel_release.empty()) + { + if (s.kernel_build_tree.empty()) + cerr << _("ERROR: kernel release isn't specified") << endl; + else + cerr << autosprintf(_("ERROR: kernel release isn't found in \"%s\""), + s.kernel_build_tree.c_str()) << endl; + return 1; + } + // Create a temporary directory to build within. // Be careful with this, as "s.tmpdir" is "rm -rf"'d at the end. - create_temp_dir (s); + rc = create_temp_dir (s); + if (rc) + return rc; // Perform passes 0 through 4 using a compile server? if (! s.specified_servers.empty ()) @@ -949,14 +963,14 @@ main (int argc, char * const argv []) // If requested, manage trust of servers. This is independent of other tasks. manage_server_trust (s); + // Some of the remote methods need to write temporary data, so go ahead + // and create the main tempdir now. + rc = create_temp_dir (s); + // Run the passes only if a script has been specified. The requirement for // a script has already been checked in systemtap_session::check_options. - if (s.have_script) + if (rc == 0 && s.have_script) { - // Some of the remote methods need to write temporary data, so go ahead - // and create the main tempdir now. - create_temp_dir (s); - vector targets; if (s.remote_uris.empty()) { diff --git a/remote.cxx b/remote.cxx index bb22d8d6d..38e81943d 100644 --- a/remote.cxx +++ b/remote.cxx @@ -190,7 +190,10 @@ class ssh_remote : public remote { public: friend class remote; - virtual ~ssh_remote() {} + virtual ~ssh_remote() + { + close_control_master(); + } int start() { diff --git a/session.cxx b/session.cxx index ded969bda..79e0d4d2a 100644 --- a/session.cxx +++ b/session.cxx @@ -1233,6 +1233,7 @@ void systemtap_session::insert_loaded_modules() void systemtap_session::setup_kernel_release (const char* kstr) { + kernel_release = kernel_build_tree = kernel_source_tree = ""; if (kstr[0] == '/') // fully specified path { kernel_build_tree = kstr; @@ -1242,13 +1243,13 @@ systemtap_session::setup_kernel_release (const char* kstr) ifstream version_file (version_file_name.c_str()); if (version_file.fail ()) { - cerr << autosprintf(_("Missing %s"), version_file_name.c_str()) << endl; - exit(1); + if (verbose > 1) + cerr << autosprintf(_("Missing %s"), version_file_name.c_str()) << endl; + return; // pass0 will realize the failure } else { char c; - kernel_release = ""; while (version_file.get(c) && c != '\n') kernel_release.push_back(c); } @@ -1271,7 +1272,8 @@ systemtap_session::setup_kernel_release (const char* kstr) else { kernel_release = string (kstr); - kernel_build_tree = "/lib/modules/" + kernel_release + "/build"; + if (!kernel_release.empty()) + kernel_build_tree = "/lib/modules/" + kernel_release + "/build"; // PR10745 // Let's not look for the kernel_source_tree; it's definitely diff --git a/util.cxx b/util.cxx index 9f8cab366..01f20594e 100644 --- a/util.cxx +++ b/util.cxx @@ -595,7 +595,7 @@ int regexp_match (const string& value, const string& re, vector& matches int rc = regcomp (r, re.c_str(), REG_EXTENDED); /* REG_ICASE? */ if (rc) { cerr << "regcomp " << re << " error rc=" << rc << endl; - exit(1); + return rc; } compiled[re] = r; }