From 6fb95a63ecfa32b1524790ee42695f19773f2174 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Tue, 20 Oct 2009 22:14:00 +0200 Subject: Change stap parser to use an input file descriptor other than stdin * grapher/StapParser.hxx (_inFd, getInFd, setInFd): new member and fuctions * grapher/StapParser.cxx (ioCallback): Use _inFd variable instead of stdin. * grapher/grapher.cxx (StapLauncher::launch): Don't read input from stap on stdin; use the the read end of the pipe. --- grapher/StapParser.cxx | 2 +- grapher/StapParser.hxx | 8 +++++++- grapher/grapher.cxx | 21 +++++++-------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/grapher/StapParser.cxx b/grapher/StapParser.cxx index 9bb9b9c9..eea85006 100644 --- a/grapher/StapParser.cxx +++ b/grapher/StapParser.cxx @@ -70,7 +70,7 @@ vector commaSplit(const boost::sub_range& range) return true; char buf[256]; ssize_t bytes_read = 0; - bytes_read = read(STDIN_FILENO, buf, sizeof(buf) - 1); + bytes_read = read(_inFd, buf, sizeof(buf) - 1); if (bytes_read <= 0) { _win.hide(); diff --git a/grapher/StapParser.hxx b/grapher/StapParser.hxx index f4f6bdef..eeebed63 100644 --- a/grapher/StapParser.hxx +++ b/grapher/StapParser.hxx @@ -13,14 +13,20 @@ class StapParser Gtk::Window& _win; GraphWidget& _widget; int _errFd; + int _inFd; public: StapParser(Gtk::Window& win, - GraphWidget& widget) : _win(win), _widget(widget), _errFd(-1) {} + GraphWidget& widget) : _win(win), _widget(widget), _errFd(-1), + _inFd(-1) + { + } void parseData(std::tr1::shared_ptr gdata, double time, const std::string& dataString); bool ioCallback(Glib::IOCondition ioCondition); bool errIoCallback(Glib::IOCondition ioCondition); int getErrFd() { return _errFd; } void setErrFd(int fd) { _errFd = fd; } + int getInFd() { return _inFd; } + void setInFd(int fd) { _inFd = fd; } }; } diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 429d0537..398b35f1 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -257,8 +257,6 @@ protected: int StapLauncher::launch() { - int stapErrFd = -1; - if (pipe(&signalPipe[0]) < 0) { std::perror("pipe"); @@ -286,9 +284,6 @@ int StapLauncher::launch() } else if (_childPid) { - dup2(pipefd[0], STDIN_FILENO); - stapErrFd = pipefd[2]; - close(pipefd[0]); close(pipefd[1]); close(pipefd[3]); } @@ -318,14 +313,12 @@ int StapLauncher::launch() } _exit(1); } - if (stapErrFd >= 0) - { - _stapParser->setErrFd(stapErrFd); - Glib::signal_io().connect(sigc::mem_fun(*_stapParser, - &StapParser::errIoCallback), - stapErrFd, - Glib::IO_IN); - } + _stapParser->setErrFd(pipefd[2]); + _stapParser->setInFd(pipefd[0]); + Glib::signal_io().connect(sigc::mem_fun(*_stapParser, + &StapParser::errIoCallback), + pipefd[2], + Glib::IO_IN); setSigfd(signalPipe[0]); if (signalPipe[0] >= 0) { @@ -335,7 +328,7 @@ int StapLauncher::launch() } Glib::signal_io().connect(sigc::mem_fun(*_stapParser, &StapParser::ioCallback), - STDIN_FILENO, + pipefd[0], Glib::IO_IN | Glib::IO_HUP); return _childPid; } -- cgit