diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-12-15 18:20:09 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-12-15 18:20:30 +0300 |
commit | 7761021425f7b1884360a8be0b2d0d8965040f4e (patch) | |
tree | 0854c29a0c8c5a9ede29e8f922dcf6c47acd3b67 | |
parent | 53b4f58c78e21cbc442891c2ce2a2b99a32e47bc (diff) |
Make BLODA timeout indefinite for non-whitelisted programs
-rw-r--r-- | libbutl/process.cxx | 25 |
1 files 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 <map> -#include <ratio> // milli +#include <ratio> // milli #include <chrono> -#include <cstdlib> // getenv(), __argv[] +#include <cstdlib> // getenv(), __argv[] +#include <algorithm> // 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<path> 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<DWORD, milli> wd (200); + const chrono::duration<DWORD, milli> 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; } |