summaryrefslogtreecommitdiff
path: root/project2/processes/processStream.cpp
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2012-04-23 22:32:56 +0000
committerrandomdan <randomdan@localhost>2012-04-23 22:32:56 +0000
commit8c8a58b7fa3e99d9c8de493ed67688293f8c89cd (patch)
tree91ba47995fb9434efacfbf8a9cd1e048d5c430a1 /project2/processes/processStream.cpp
parentPlugable loggers (diff)
downloadproject2-8c8a58b7fa3e99d9c8de493ed67688293f8c89cd.tar.bz2
project2-8c8a58b7fa3e99d9c8de493ed67688293f8c89cd.tar.xz
project2-8c8a58b7fa3e99d9c8de493ed67688293f8c89cd.zip
Tidy up some error handling and mutables
Diffstat (limited to 'project2/processes/processStream.cpp')
-rw-r--r--project2/processes/processStream.cpp9
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;
};