summaryrefslogtreecommitdiffstats
path: root/runtime/staprun/mainloop.c
diff options
context:
space:
mode:
authorWilliam Cohen <wcohen@redhat.com>2009-01-28 16:19:21 -0500
committerWilliam Cohen <wcohen@redhat.com>2009-01-28 16:19:21 -0500
commit7914abbdb3050c04628b0daaec2349b257998715 (patch)
tree753819d68d965409af5e19516146bca8c744bc16 /runtime/staprun/mainloop.c
parentff90b2974f841b92434cb46d89c39f08d01cc966 (diff)
parent078198eb01e89d1b79ae96203525d59945f68067 (diff)
downloadsystemtap-steved-7914abbdb3050c04628b0daaec2349b257998715.tar.gz
systemtap-steved-7914abbdb3050c04628b0daaec2349b257998715.tar.xz
systemtap-steved-7914abbdb3050c04628b0daaec2349b257998715.zip
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap
Diffstat (limited to 'runtime/staprun/mainloop.c')
-rw-r--r--runtime/staprun/mainloop.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c
index 2fb049b0..29eb4f1f 100644
--- a/runtime/staprun/mainloop.c
+++ b/runtime/staprun/mainloop.c
@@ -357,6 +357,8 @@ void cleanup_and_exit(int detach)
err("\nDisconnecting from systemtap module.\n" "To reconnect, type \"staprun -A %s\"\n", modname);
} else {
const char *staprun = getenv ("SYSTEMTAP_STAPRUN") ?: BINDIR "/staprun";
+#define BUG9788_WORKAROUND
+#ifndef BUG9788_WORKAROUND
dbug(2, "removing %s\n", modname);
if (execlp(staprun, basename (staprun), "-d", modname, NULL) < 0) {
if (errno == ENOEXEC) {
@@ -368,6 +370,51 @@ void cleanup_and_exit(int detach)
perror(staprun);
_exit(1);
}
+#else
+ pid_t pid;
+ int rstatus;
+ struct sigaction sa;
+
+ dbug(2, "removing %s\n", modname);
+
+ // So that waitpid() below will work correctly, we need to clear
+ // out our SIGCHLD handler.
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGCHLD, &sa, NULL);
+
+ pid = fork();
+ if (pid < 0) {
+ _perr("fork");
+ _exit(-1);
+ }
+
+ if (pid == 0) { /* child process */
+ /* Run the command. */
+ if (execlp(staprun, basename (staprun), "-d", modname, NULL) < 0) {
+ if (errno == ENOEXEC) {
+ char *cmd;
+ if (asprintf(&cmd, "%s -d '%s'", staprun, modname) > 0)
+ execl("/bin/sh", "sh", "-c", cmd, NULL);
+ free(cmd);
+ }
+ perror(staprun);
+ _exit(1);
+ }
+ }
+
+ /* parent process */
+ if (waitpid(pid, &rstatus, 0) < 0) {
+ _perr("waitpid");
+ _exit(-1);
+ }
+
+ if (WIFEXITED(rstatus)) {
+ _exit(WEXITSTATUS(rstatus));
+ }
+ _exit(-1);
+#endif
}
_exit(0);
}