Prevent subprocesses from accessing FDs opened in other threads.
Unlike installd, artd is multi-threaded. When we fork & exec, the
subprocess gets FDs opened in all threads. This is unexpected. For
example, profman gets FDs opened for dex2oat. This CL prevents this by
closing other FDs before we exec.
Bug: 262230400
Test: m test-art-host-gtest-art_artd_tests
Test: m test-art-host-gtest-art_libarttools_tests
Test: atest ArtGtestsTargetChroot:ArtExecTest
Test: -
1. adb shell setprop pm.dexopt.bg-dexopt.concurrency 4
2. adb shell pm art optimize-packages bg-dexopt
3. No longer see SELinux complaining that profman is trying to read
some files opened for dex2oat.
Ignore-AOSP-First: ART Services.
Change-Id: Ia8068d804294debe0de6c947f3878da4dbf8c8ca
diff --git a/libarttools/tools/cmdline_builder.h b/libarttools/tools/cmdline_builder.h
index 13b79ca..fd11ee8 100644
--- a/libarttools/tools/cmdline_builder.h
+++ b/libarttools/tools/cmdline_builder.h
@@ -17,6 +17,8 @@
#ifndef ART_LIBARTTOOLS_TOOLS_CMDLINE_BUILDER_H_
#define ART_LIBARTTOOLS_TOOLS_CMDLINE_BUILDER_H_
+#include <algorithm>
+#include <iterator>
#include <string>
#include <string_view>
#include <vector>
@@ -135,6 +137,15 @@
return *this;
}
+ // Concatenates this builder with another. Returns the concatenated result and nullifies the input
+ // builder.
+ CmdlineBuilder& Concat(CmdlineBuilder&& other) {
+ elements_.reserve(elements_.size() + other.elements_.size());
+ std::move(other.elements_.begin(), other.elements_.end(), std::back_inserter(elements_));
+ other.elements_.clear();
+ return *this;
+ }
+
private:
std::vector<std::string> elements_;
};