diff options
author | randomdan <randomdan@localhost> | 2012-04-23 22:32:56 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-04-23 22:32:56 +0000 |
commit | 729a8ba1de5969c416b7c0895b37ad516f0b64dc (patch) | |
tree | 91ba47995fb9434efacfbf8a9cd1e048d5c430a1 /project2/processes/processStream.cpp | |
parent | Plugable loggers (diff) | |
download | project2-729a8ba1de5969c416b7c0895b37ad516f0b64dc.tar.bz2 project2-729a8ba1de5969c416b7c0895b37ad516f0b64dc.tar.xz project2-729a8ba1de5969c416b7c0895b37ad516f0b64dc.zip |
Tidy up some error handling and mutables
Diffstat (limited to 'project2/processes/processStream.cpp')
-rw-r--r-- | project2/processes/processStream.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/project2/processes/processStream.cpp b/project2/processes/processStream.cpp index 13c2555..1a853e4 100644 --- a/project2/processes/processStream.cpp +++ b/project2/processes/processStream.cpp @@ -1,5 +1,6 @@ #include "iHaveParameters.h" #include "scriptLoader.h" +#include "scopeObject.h" #include "scripts.h" #include "stream.h" #include <exception> @@ -29,8 +30,13 @@ class ProcessStream : public Stream, IHaveParameters { callProc[pidx++] = p.second(); } callProc[pidx] = NULL; + int fds[2]; popenrw(callProc, fds); + ScopeObject doClose([&] { + close(fds[0]); + close(fds[1]); + }); char buf[BUFSIZ]; while (ssize_t r = read(fds[1], buf, BUFSIZ) != 0) { if (r < 0) { @@ -39,8 +45,6 @@ class ProcessStream : public Stream, IHaveParameters { sink(buf, r); } - close(fds[0]); - close(fds[1]); int status; wait(&status); // ignore any error if the application is still running, @@ -51,7 +55,6 @@ class ProcessStream : public Stream, IHaveParameters { } } protected: - mutable int fds[2]; const Variable path; }; |