From 0624562e3e1ae24fd1df66e3e38afca7b0f1c70f Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 18 Sep 2018 00:06:29 +0200 Subject: Fix bugs - Cleanup open file descriptors properly - Use cout, not cerr - Better error logging, including when a program is killed by a signal --- process.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'process.h') diff --git a/process.h b/process.h index 900a0b6..24ff4b0 100644 --- a/process.h +++ b/process.h @@ -14,8 +14,12 @@ class Process { pid_t pid = -1; int infd = -1, outfd = -1; + int exitStatus = -1; + string readBuf; + void cleanup(); + public: Process(const string_view execname); Process(const Process&) = delete; @@ -24,10 +28,13 @@ public: void redirectStderr(const string_view fname); void run(); - void wait(); void stop(); void unStop(); - void terminate(); + // These return -1 if an error occurred, and the process return value otherwise. + // If the process was killed by a signal, (1000 + signal) is returned. + int wait(); + int waitPoll(); // Also returns -1 if process hasn't finished yet + int terminate(); pid_t getPid() const; -- cgit v1.2.3-54-g00ecf