else
make_cmd += " -s >/dev/null";
- if (s.verbose > 1) clog << "Running " << make_cmd << endl;
- rc = stap_system (make_cmd.c_str());
- if (rc && s.verbose > 1)
- clog << "Error " << rc << " " << strerror(rc) << endl;
- return rc;
+ return stap_system (s.verbose, make_cmd);
}
static void
{
string grep_cmd = string ("/bin/grep -q unregister_uprobe ") +
s.kernel_build_tree + string ("/Module.symvers");
- int rc = stap_system (grep_cmd.c_str());
- if (rc && s.verbose > 1)
- clog << "Error " << rc << " " << strerror(rc) << endl;
- return (rc == 0);
+
+ return (stap_system (s.verbose, grep_cmd) == 0);
}
static bool
string uprobes_home = s.runtime_path + "/uprobes";
string cp_cmd = string("/bin/cp ") + uprobes_home +
string("/Module.symvers ") + s.tmpdir;
- int rc = stap_system (cp_cmd.c_str());
- if (rc && s.verbose > 1)
- clog << "Error " << rc << " " << strerror(rc) << endl;
- return rc;
+
+ return stap_system (s.verbose, cp_cmd);
}
static int
int
run_pass (systemtap_session& s)
{
- int rc = 0;
-
// for now, just spawn staprun
string staprun_cmd = string(getenv("SYSTEMTAP_STAPRUN") ?: BINDIR "/staprun")
+ " "
staprun_cmd += s.tmpdir + "/" + s.module_name + ".ko";
- if (s.verbose>1) clog << "Running " << staprun_cmd << endl;
-
- rc = stap_system (staprun_cmd.c_str ());
- if (rc && s.verbose > 1)
- clog << "Error " << rc << " " << strerror(rc) << endl;
- return rc;
+ return stap_system (s.verbose, staprun_cmd);
}
+ name + " -xc /dev/null -include " + header;
if (s.verbose < 4)
cmd += " >/dev/null 2>&1";
- int rc = stap_system (cmd.c_str());
- if (rc && s.verbose > 1)
- clog << "Error " << rc << " " << strerror(rc) << endl;
- return rc;
+ return stap_system (s.verbose, cmd);
}
// Remove the temporary directory.
string cleanupcmd = "rm -rf ";
cleanupcmd += s.tmpdir;
- if (s.verbose>1) clog << "Running " << cleanupcmd << endl;
- int status = stap_system (cleanupcmd.c_str());
- if (status != 0 && s.verbose>1)
- clog << "Cleanup command failed, status: " << status << endl;
+
+ (void) stap_system (s.verbose, cleanupcmd);
}
}
// Generate the certificate and database.
string cmd = BINDIR "/stap-gen-cert " + cert_db_path;
- rc = stap_system (cmd.c_str()) == 0;
+ rc = stap_system (0, cmd) == 0;
// If we are root, authorize the new certificate as a trusted
// signer. It is not an error if this fails.
if (geteuid () == 0)
{
cmd = BINDIR "/stap-authorize-signing-cert " + cert_db_path + "/stap.cert";
- stap_system (cmd.c_str());
+ stap_system (0, cmd);
}
return rc;
s.op->line() << " .finder = {";
if (p->pid != 0)
s.op->line() << " .pid=" << p->pid;
- else if (p->section == ".absolute")
+ else if (p->section == ".absolute") // proxy for ET_EXEC -> exec()'d program
s.op->line() << " .procname=" << lex_cast_qstring(p->module) << ", ";
// else ".dynamic" gets procname=0, pid=0, activating task_finder "global tracing"
s.op->line() << "},";
// Runs a command with a saved PID, so we can kill it from the signal handler
int
-stap_system(const char *command)
+stap_system(int verbose, const std::string& command)
{
- STAP_PROBE1(stap, stap_system__start, command);
- const char * argv[] = { "sh", "-c", command, NULL };
+ const char *cmd = command.c_str();
+ STAP_PROBE1(stap, stap_system__start, cmd);
+ char const * const argv[] = { "sh", "-c", cmd, NULL };
int ret, status;
spawned_pid = 0;
- ret = posix_spawn(&spawned_pid, "/bin/sh", NULL, NULL,
- const_cast<char **>(argv), environ);
+
+ if (verbose > 1)
+ clog << "Running " << command << endl;
+
+ ret = posix_spawn(&spawned_pid, "/bin/sh", NULL, NULL, const_cast<char * const *>(argv), environ);
STAP_PROBE2(stap, stap_system__spawn, ret, spawned_pid);
if (ret == 0)
{
- if (waitpid(spawned_pid, &status, 0) == spawned_pid)
- ret = WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status);
+ ret = waitpid(spawned_pid, &status, 0);
+ if (ret == spawned_pid)
+ {
+ ret = WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status);
+ if (verbose > 2)
+ clog << "Spawn waitpid result (0x" << ios::hex << status << ios::dec << "): " << ret << endl;
+ }
else
- ret = errno;
+ {
+ if (verbose > 1)
+ clog << "Spawn waitpid error (" << ret << "): " << strerror(errno) << endl;
+ ret = -1;
+ }
+ }
+ else
+ {
+ if (verbose > 1)
+ clog << "Spawn error (" << ret << "): " << strerror(ret) << endl;
+ ret = -1;
}
STAP_PROBE1(stap, stap_system__complete, ret);
spawned_pid = 0;
std::string find_executable(const std::string& name);
const std::string cmdstr_quoted(const std::string& cmd);
std::string git_revision(const std::string& path);
-int stap_system(const char *command);
+int stap_system(int verbose, const std::string& command);
int kill_stap_spawn(int sig);