From 95ddfc079a1d9affdb285f7690f8d5623cd7124a Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 25 May 2009 18:25:47 +0200 Subject: [PATCH] run stap from grapher * grapher/grapher.cxx (main): Start stap + script from program if supplied as an argument. --- grapher/grapher.cxx | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index b7292cfdc..0013d8b04 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -97,12 +97,42 @@ int main(int argc, char** argv) StapParser stapParser(win, win.w); - StapParser stapParser(win, w); + int childPid = -1; + if (argc > 1) + { + int pipefd[2]; + if (pipe(pipefd) < 0) + { + std::perror("pipe"); + exit(1); + } + if ((childPid = fork()) == -1) + { + exit(1); + } + else if (childPid) + { + dup2(pipefd[0], 0); + close(pipefd[0]); + } + else + { + dup2(pipefd[1], 1); + close(pipefd[1]); + execlp("stap", argv[1]); + exit(1); + return 1; + } + } Glib::signal_io().connect(sigc::mem_fun(stapParser, &StapParser::ioCallback), 0, Glib::IO_IN); Gtk::Main::run(win); - + if (childPid > 0) + kill(childPid, SIGTERM); + int status; + while (wait(&status) != -1) + ; return 0; } -- 2.43.5