summaryrefslogtreecommitdiffstats
path: root/util.cxx
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@elastic.org>2009-08-21 16:00:27 -0400
committerFrank Ch. Eigler <fche@elastic.org>2009-08-21 16:00:27 -0400
commit36ef6d6a310d7a4a35a3c505d041e9fbd11125fa (patch)
tree46233e0e37d3407a05b9c4e5c3f60c6393171806 /util.cxx
parentb6921d5942950cb988318c36ee0e0792311f1ccc (diff)
downloadsystemtap-steved-36ef6d6a310d7a4a35a3c505d041e9fbd11125fa.tar.gz
systemtap-steved-36ef6d6a310d7a4a35a3c505d041e9fbd11125fa.tar.xz
systemtap-steved-36ef6d6a310d7a4a35a3c505d041e9fbd11125fa.zip
PR10544: clean up stap child process error handling
* util.cxx (stap_system): Take extra verbosity value. Standardize error handling / tracing. * util.h: Corresponding changes. * buildrun.cxx, main.cxx, modsign.cxx: Update callers.
Diffstat (limited to 'util.cxx')
-rw-r--r--util.cxx35
1 files changed, 27 insertions, 8 deletions
diff --git a/util.cxx b/util.cxx
index 495d2f5a..057cc7ab 100644
--- a/util.cxx
+++ b/util.cxx
@@ -326,22 +326,41 @@ static pid_t spawned_pid = 0;
// 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;