summaryrefslogtreecommitdiffstats
path: root/util.cxx
diff options
context:
space:
mode:
authorJim Keniston <jkenisto@us.ibm.com>2009-04-15 16:02:58 -0700
committerJim Keniston <jkenisto@us.ibm.com>2009-04-15 16:02:58 -0700
commit900686f5e209099d493a15f4e36a5030dc0aa8be (patch)
tree405757c92915c516cd0ff28e217a000843573f3f /util.cxx
parent2020af07c2a7f58538874ce652b52a6883f7ada0 (diff)
parent7c2136cfc88d68cfc5eb490444dc25c7dc1c0632 (diff)
downloadsystemtap-steved-900686f5e209099d493a15f4e36a5030dc0aa8be.tar.gz
systemtap-steved-900686f5e209099d493a15f4e36a5030dc0aa8be.tar.xz
systemtap-steved-900686f5e209099d493a15f4e36a5030dc0aa8be.zip
Merge branch 'master' of ssh://kenistoj@sources.redhat.com/git/systemtap
Diffstat (limited to 'util.cxx')
-rw-r--r--util.cxx41
1 files changed, 37 insertions, 4 deletions
diff --git a/util.cxx b/util.cxx
index 68cc27f7..5fa7a5f2 100644
--- a/util.cxx
+++ b/util.cxx
@@ -20,13 +20,15 @@
#include <cerrno>
extern "C" {
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <fcntl.h>
#include <pwd.h>
-#include <unistd.h>
+#include <spawn.h>
#include <stdio.h>
#include <stdlib.h>
-#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
}
using namespace std;
@@ -275,4 +277,35 @@ git_revision(const string& path)
return revision;
}
+
+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)
+{
+ const char * argv[] = { "sh", "-c", command, NULL };
+ int ret, status;
+
+ spawned_pid = 0;
+ ret = posix_spawn(&spawned_pid, "/bin/sh", NULL, NULL,
+ const_cast<char **>(argv), environ);
+ if (ret == 0)
+ {
+ if (waitpid(spawned_pid, &status, 0) == spawned_pid)
+ ret = WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status);
+ else
+ ret = errno;
+ }
+ spawned_pid = 0;
+ return ret;
+}
+
+// Send a signal to our spawned command
+int
+kill_stap_spawn(int sig)
+{
+ return spawned_pid ? kill(spawned_pid, sig) : 0;
+}
+
/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */