summaryrefslogtreecommitdiffstats
path: root/util.cxx
diff options
context:
space:
mode:
authorDave Brolley <brolley@redhat.com>2009-04-02 12:38:15 -0400
committerDave Brolley <brolley@redhat.com>2009-04-02 12:38:15 -0400
commit2f53f831393d2f0db3d54260c2a7882eff17905c (patch)
treeba140bbad1fd4acaa7c2253949a2b2ade53952a2 /util.cxx
parent2f54c4fe5a3aa21b4d5c38edabf83f3cdad0177d (diff)
parent15a78144473940a4e7c685cc57ba09a92f2293c6 (diff)
downloadsystemtap-steved-2f53f831393d2f0db3d54260c2a7882eff17905c.tar.gz
systemtap-steved-2f53f831393d2f0db3d54260c2a7882eff17905c.tar.xz
systemtap-steved-2f53f831393d2f0db3d54260c2a7882eff17905c.zip
Merge branch 'master' of git://sources.redhat.com/git/systemtap
Conflicts: configure
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 a20e8292..5c05a1dd 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;
@@ -294,4 +296,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 : */