summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Maennich <maennich@google.com>2021-11-08 22:14:27 +0000
committerMatthias Maennich <maennich@google.com>2021-11-09 18:48:32 +0000
commitc55b76cbf334d18096d4224ca0193e0d66de00d0 (patch)
tree4e44b9f452244dbd035437b5dbbbf9d71d0bd6d1
parentf9a6d187425027a396cf0e8c718fe0836e9bd813 (diff)
downloadbuild-tools-c55b76cbf334d18096d4224ca0193e0d66de00d0.tar.gz
Interceptor: add support for Command execution
That is necessary to execute modified commands. Otherwise the function would return and fall back to the original execve. This change itself does make sense together with a later change that actually modifies the command. Bug: 205577427 Signed-off-by: Matthias Maennich <maennich@google.com> Change-Id: I6a9d7e31256063f3fe2883975fdc4cf486566b24
-rw-r--r--interceptor/interceptor.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/interceptor/interceptor.cc b/interceptor/interceptor.cc
index de3b2f3..71f67a2 100644
--- a/interceptor/interceptor.cc
+++ b/interceptor/interceptor.cc
@@ -44,6 +44,9 @@ static void process_command(const char* filename, char* const argv[], char* cons
// log command if logging is enabled
static void log(const interceptor::Command&, const std::string& prefix);
+// execute potentially modified command
+static void exec(const interceptor::Command&);
+
// OVERLOADS for LD_PRELOAD USE
// Intercept execve calls, for that capture the original execve call
@@ -134,6 +137,9 @@ static void process_command(const char* filename, char* const argv[], char* cons
interceptor::Command command(filename, argv, envp);
log(command, "");
+
+ // pass down the transformed command to execve
+ exec(command);
}
static void log(const interceptor::Command& command, const std::string& prefix) {
@@ -147,3 +153,16 @@ static void log(const interceptor::Command& command, const std::string& prefix)
}
}
}
+
+static void exec(const interceptor::Command& command) {
+ std::vector<const char*> c_args;
+ c_args.reserve(command.args().size() + 1);
+ c_args[command.args().size()] = nullptr;
+ for (const auto& arg : command.args()) {
+ c_args.push_back(arg.data());
+ }
+ // TODO: at this point, we could free some memory that is held in Command.
+ // While the args vector is reused for args, we could free the EnvMap
+ // and the original args.
+ old_execve(command.program().c_str(), const_cast<char**>(c_args.data()), command.envp());
+}