From dd732cc38f57844bfcedc5687d4b66df7102f31f Mon Sep 17 00:00:00 2001 From: Orion Hodson Date: Fri, 15 Jan 2021 16:31:30 +0000 Subject: Add an overload of ExecAndReturnCode taking a timeout Enables callers to timeout waiting on a subprocess. Bug: 177432913 Test: test-art-host-gtest-art_runtime_tests32 Change-Id: I7a27e0ca4679f45daf815d7e2563ca9b723bd701 --- runtime/exec_utils.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'runtime/exec_utils.h') diff --git a/runtime/exec_utils.h b/runtime/exec_utils.h index 093f7b8d80..5e22639a08 100644 --- a/runtime/exec_utils.h +++ b/runtime/exec_utils.h @@ -23,11 +23,19 @@ namespace art { // Wrapper on fork/execv to run a command in a subprocess. -// Both of these spawn child processes using the environment as it was set when the single instance +// 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 // will use the current environment settings. -bool Exec(std::vector& arg_vector, std::string* error_msg); -int ExecAndReturnCode(std::vector& arg_vector, std::string* error_msg); + +bool Exec(std::vector& arg_vector, /*out*/ std::string* error_msg); +int ExecAndReturnCode(std::vector& arg_vector, /*out*/ std::string* error_msg); + +// Execute the command specified in `argv_vector` in a subprocess with a timeout. +// Returns the process exit code on success, -1 otherwise. +int ExecAndReturnCode(std::vector& arg_vector, + time_t timeout_secs, + /*out*/ bool* timed_out, + /*out*/ std::string* error_msg); } // namespace art -- cgit v1.2.3-59-g8ed1b