]> git.tdb.fi Git - builder.git/commitdiff
Read output from external task while waiting
authorMikko Rasa <tdb@tdb.fi>
Fri, 21 Jun 2019 17:59:15 +0000 (20:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 21 Jun 2019 17:59:15 +0000 (20:59 +0300)
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.

source/externaltask.cpp

index d9832c2c3e5986587621d6d54c4a6e6991409b7b..f7ab199b417121712ef3d9a408a58565cc6961d8 100644 (file)
@@ -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);
        }