diff options
Diffstat (limited to 'runtime/exec_utils.h')
-rw-r--r-- | runtime/exec_utils.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/runtime/exec_utils.h b/runtime/exec_utils.h index 751c64d9c8..aa0d0fc932 100644 --- a/runtime/exec_utils.h +++ b/runtime/exec_utils.h @@ -19,6 +19,7 @@ #include <time.h> +#include <functional> #include <string> #include <vector> @@ -34,6 +35,14 @@ struct ProcessStat { int cpu_time_ms = 0; }; +struct ExecCallbacks { + // Called in the parent process as soon as the child process is forked. + std::function<void(pid_t pid)> on_start = [](pid_t) {}; + // Called in the parent process after the child process exits while still in a waitable state, no + // matter the child process succeeds or not. + std::function<void(pid_t pid)> on_end = [](pid_t) {}; +}; + // Wrapper on fork/execv to run a command in a subprocess. // These spawn child processes using the environment as it was set when the single instance // of the runtime (Runtime::Current()) was started. If no instance of the runtime was started, it @@ -57,10 +66,11 @@ class ExecUtils { /*out*/ bool* timed_out, /*out*/ std::string* error_msg) const; - // Same as above, but also collects stat of the process. The stat is collected no matter the child - // process succeeds or not. + // Same as above, but also collects stat of the process and calls callbacks. The stat is collected + // no matter the child process succeeds or not. virtual int ExecAndReturnCode(const std::vector<std::string>& arg_vector, int timeout_sec, + const ExecCallbacks& callbacks, /*out*/ bool* timed_out, /*out*/ ProcessStat* stat, /*out*/ std::string* error_msg) const; |