summaryrefslogtreecommitdiff
path: root/runtime/exec_utils.h
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2022-09-09 11:58:56 +0100
committer Treehugger Robot <treehugger-gerrit@google.com> 2022-09-16 20:14:46 +0000
commit4c9498e8f1c8ef8c54cfd7462e24a505690cdc10 (patch)
tree64248e7108103d2e00928f3968b2dc4e98a81082 /runtime/exec_utils.h
parent5494695148b63ab33e6e5e178dcef5fa6380116c (diff)
Change ExecUtils to support callbacks.
artd needs the callbacks to get the pid in order to kill the subprocess. Partially cherry-picked from commit 659f49bdb1263ceb26f666052f3ef7e4732b4eb2 Bug: 244412198 Test: m test-art-host-gtest-art_runtime_tests Merged-In: I8c40949b5ed88ff85ddedad9d86f0b9bbfddb98d Change-Id: Ia28410bdf6314178756ee5e3a94000dc6f3ecc97
Diffstat (limited to 'runtime/exec_utils.h')
-rw-r--r--runtime/exec_utils.h14
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;