From: Mikko Rasa Date: Fri, 21 Jun 2019 17:59:15 +0000 (+0300) Subject: Read output from external task while waiting X-Git-Url: http://git.tdb.fi/?p=builder.git;a=commitdiff_plain;h=a5a1ecb806ec2dec26701b931b8d2d6cbe7f4928 Read output from external task while waiting Waiting for the process to finish first may lead to a deadlock if it produces more output than can fit in the pipe's buffers. --- diff --git a/source/externaltask.cpp b/source/externaltask.cpp index d9832c2..f7ab199 100644 --- a/source/externaltask.cpp +++ b/source/externaltask.cpp @@ -128,9 +128,9 @@ Task::Status ExternalTask::wait() Task::Status ExternalTask::do_wait(bool block) { - if(process) + while(process) { - if(process->wait(block)) + if(process->wait(!capture_pipe)) { exit_code = process->get_exit_code(); delete process; @@ -138,7 +138,7 @@ Task::Status ExternalTask::do_wait(bool block) } // Do this after waiting to avoid a race condition - while(capture_pipe && IO::poll(*capture_pipe, IO::P_INPUT, Time::zero)) + while(capture_pipe && IO::poll(*capture_pipe, IO::P_INPUT, 10*Time::msec)) { char buf[1024]; unsigned len = capture_pipe->read(buf, sizeof(buf)); @@ -149,7 +149,10 @@ Task::Status ExternalTask::do_wait(bool block) } if(process) - return RUNNING; + { + if(!block) + return RUNNING; + } else signal_finished.emit(!exit_code); }