From 7761021425f7b1884360a8be0b2d0d8965040f4e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 15 Dec 2017 18:20:09 +0300 Subject: Make BLODA timeout indefinite for non-whitelisted programs --- libbutl/process.cxx | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/libbutl/process.cxx b/libbutl/process.cxx index 4a6d5f5..70f05b1 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -58,9 +58,10 @@ #ifdef _WIN32 #include -#include // milli +#include // milli #include -#include // getenv(), __argv[] +#include // getenv(), __argv[] +#include // find() #endif #endif @@ -1455,7 +1456,7 @@ namespace butl using namespace chrono; - for (system_clock::duration timeout (10500ms);;) // Try for about 10s. + for (system_clock::duration timeout (1h);;) // Try for about 1 hour. { if (!CreateProcess ( batch != nullptr ? batch : pp.effect_string (), @@ -1539,18 +1540,30 @@ namespace butl DWORD r; system_clock::duration twd (0); // Total wait time. - for (size_t n (0); n != 10; ++n) // Wait n times by 200ms. + + // We will wait for non-whitelisted program indefinitely, until it + // terminates or prints to stdout/stderr. Note that any MSYS program + // that reads from stdin prior to writing to stdout/stderr must be + // whitelisted. + // + const vector wl ({path ("less.exe")}); + + bool w (find (wl.begin (), wl.end (), pp.effect.leaf ()) != + wl.end ()); + + for (size_t n (0);;) // Wait n times by 100ms. { // Hidden by butl::duration that is introduced via fdstream.mxx. // - const chrono::duration wd (200); + const chrono::duration wd (100); r = WaitForSingleObject (pi.hProcess, wd.count ()); twd += wd; if (r != WAIT_TIMEOUT || probe_fd (in_ofd.in.get (), pout.in) || - probe_fd (in_efd.in.get (), perr.in)) + probe_fd (in_efd.in.get (), perr.in) || + (w && ++n == 5)) break; } -- cgit v1.1