From aa8c92d0cb854dcc93d7f9076285332417354889 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 29 Aug 2018 22:54:57 +0200 Subject: Fix wait()'ing on a Process after terminate()'ing it --- main.cpp | 3 --- process.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 173346c..aa92b64 100644 --- a/main.cpp +++ b/main.cpp @@ -311,9 +311,6 @@ match_done: if (success) usleep(10000); procs[i].terminate(); } - for (int i = 0; i < 2; i++) { - procs[i].wait(); - } gMultiLog.append(logId, mres.describe(p1, p2)); gMultiLog.complete(logId); diff --git a/process.cpp b/process.cpp index d3ceb28..cab5484 100644 --- a/process.cpp +++ b/process.cpp @@ -64,6 +64,7 @@ void Process::run() { } void Process::wait() { + if (pid == -1) return; while (true) { int status; if (waitpid(pid, &status, 0) < 0) { @@ -88,6 +89,8 @@ void Process::unStop() { } bool Process::writeLine(const string_view line) { + if (pid == -1) return false; + string str; str.reserve(line.size() + 1); str += line; @@ -108,6 +111,8 @@ bool Process::writeLine(const string_view line) { } optional Process::readLine() { + if (pid == -1) return nullopt; + size_t idx = readBuf.find('\n'); if (idx != string::npos) { string res = readBuf.substr(0, idx); @@ -144,6 +149,7 @@ void Process::terminate() { // SIGKILL if necessary if (pid != -1) { kill(pid, SIGKILL); // force kill + wait(); pid = -1; } } -- cgit v1.2.3-70-g09d2