Loading cmds/installd/file_parsing.h +13 −8 Original line number Diff line number Diff line Loading @@ -19,18 +19,14 @@ #include <fstream> #include <functional> #include <string> #include <string_view> #include "android-base/unique_fd.h" namespace android { namespace installd { bool ParseFile(const std::string& strFile, std::function<bool (const std::string&)> parse) { std::ifstream input_stream(strFile); if (!input_stream.is_open()) { return false; } template<typename Func> bool ParseFile(std::istream& input_stream, Func parse) { while (!input_stream.eof()) { // Read the next line. std::string line; Loading @@ -54,6 +50,15 @@ bool ParseFile(const std::string& strFile, std::function<bool (const std::string return true; } template<typename Func> bool ParseFile(std::string_view str_file, Func parse) { std::ifstream ifs(str_file); if (!ifs.is_open()) { return false; } return ParseFile(ifs, parse); } } // namespace installd } // namespace android Loading cmds/installd/otapreopt.cpp +51 −24 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <sys/capability.h> #include <sys/prctl.h> #include <sys/stat.h> #include <sys/mman.h> #include <android-base/logging.h> #include <android-base/macros.h> Loading @@ -36,6 +37,7 @@ #include <log/log.h> #include <private/android_filesystem_config.h> #include "android-base/file.h" #include "dexopt.h" #include "file_parsing.h" #include "globals.h" Loading Loading @@ -195,18 +197,14 @@ private: // export NAME VALUE // For simplicity, don't respect string quotation. The values we are interested in can be // encoded without them. // init.environ.rc and etc/classpath have the same format for // environment variable exports and can be matched by the same regex. // TODO Just like with the system-properties above we really should have // common code between init and otapreopt to deal with reading these // things. See b/181182967 static constexpr const char* kEnvironmentVariableSources[] = { "/init.environ.rc", "/etc/classpath" }; // // init.environ.rc and derive_classpath all have the same format for // environment variable exports (since they are all meant to be read by // init) and can be matched by the same regex. std::regex export_regex("\\s*export\\s+(\\S+)\\s+(\\S+)"); for (const char* env_vars_file : kEnvironmentVariableSources) { bool parse_result = ParseFile(env_vars_file, [&](const std::string& line) { auto parse_results = [&](auto& input) { ParseFile(input, [&](const std::string& line) { std::smatch export_match; if (!std::regex_match(line, export_match, export_regex)) { return true; Loading @@ -223,10 +221,39 @@ private: return true; }); if (!parse_result) { }; // TODO Just like with the system-properties above we really should have // common code between init and otapreopt to deal with reading these // things. See b/181182967 // There have been a variety of places the various env-vars have been // over the years. Expand or reduce this list as needed. static constexpr const char* kEnvironmentVariableSources[] = { "/init.environ.rc", }; // First get everything from the static files. for (const char* env_vars_file : kEnvironmentVariableSources) { parse_results(env_vars_file); } // Next get everything from derive_classpath, since we're already in the // chroot it will get the new versions of any dependencies. { android::base::unique_fd fd(memfd_create("derive_classpath_temp", MFD_CLOEXEC)); if (!fd.ok()) { LOG(ERROR) << "Unable to create fd for derive_classpath"; return false; } std::string memfd_file = StringPrintf("/proc/%d/fd/%d", getpid(), fd.get()); std::string error_msg; if (!Exec({"/apex/com.android.sdkext/bin/derive_classpath", memfd_file}, &error_msg)) { PLOG(ERROR) << "Running derive_classpath failed: " << error_msg; return false; } std::ifstream ifs(memfd_file); parse_results(ifs); } if (system_properties_.GetProperty(kAndroidDataPathPropertyName) == nullptr) { return false; } Loading cmds/installd/otapreopt_chroot.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -275,6 +275,7 @@ static int otapreopt_chroot(const int argc, char **arg) { static constexpr const std::string_view kRequiredApexs[] = { "com.android.art", "com.android.runtime", "com.android.sdkext", // For derive_classpath }; std::array<bool, arraysize(kRequiredApexs)> found_apexs{ false, false }; DIR* apex_dir = opendir("/apex"); Loading Loading
cmds/installd/file_parsing.h +13 −8 Original line number Diff line number Diff line Loading @@ -19,18 +19,14 @@ #include <fstream> #include <functional> #include <string> #include <string_view> #include "android-base/unique_fd.h" namespace android { namespace installd { bool ParseFile(const std::string& strFile, std::function<bool (const std::string&)> parse) { std::ifstream input_stream(strFile); if (!input_stream.is_open()) { return false; } template<typename Func> bool ParseFile(std::istream& input_stream, Func parse) { while (!input_stream.eof()) { // Read the next line. std::string line; Loading @@ -54,6 +50,15 @@ bool ParseFile(const std::string& strFile, std::function<bool (const std::string return true; } template<typename Func> bool ParseFile(std::string_view str_file, Func parse) { std::ifstream ifs(str_file); if (!ifs.is_open()) { return false; } return ParseFile(ifs, parse); } } // namespace installd } // namespace android Loading
cmds/installd/otapreopt.cpp +51 −24 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <sys/capability.h> #include <sys/prctl.h> #include <sys/stat.h> #include <sys/mman.h> #include <android-base/logging.h> #include <android-base/macros.h> Loading @@ -36,6 +37,7 @@ #include <log/log.h> #include <private/android_filesystem_config.h> #include "android-base/file.h" #include "dexopt.h" #include "file_parsing.h" #include "globals.h" Loading Loading @@ -195,18 +197,14 @@ private: // export NAME VALUE // For simplicity, don't respect string quotation. The values we are interested in can be // encoded without them. // init.environ.rc and etc/classpath have the same format for // environment variable exports and can be matched by the same regex. // TODO Just like with the system-properties above we really should have // common code between init and otapreopt to deal with reading these // things. See b/181182967 static constexpr const char* kEnvironmentVariableSources[] = { "/init.environ.rc", "/etc/classpath" }; // // init.environ.rc and derive_classpath all have the same format for // environment variable exports (since they are all meant to be read by // init) and can be matched by the same regex. std::regex export_regex("\\s*export\\s+(\\S+)\\s+(\\S+)"); for (const char* env_vars_file : kEnvironmentVariableSources) { bool parse_result = ParseFile(env_vars_file, [&](const std::string& line) { auto parse_results = [&](auto& input) { ParseFile(input, [&](const std::string& line) { std::smatch export_match; if (!std::regex_match(line, export_match, export_regex)) { return true; Loading @@ -223,10 +221,39 @@ private: return true; }); if (!parse_result) { }; // TODO Just like with the system-properties above we really should have // common code between init and otapreopt to deal with reading these // things. See b/181182967 // There have been a variety of places the various env-vars have been // over the years. Expand or reduce this list as needed. static constexpr const char* kEnvironmentVariableSources[] = { "/init.environ.rc", }; // First get everything from the static files. for (const char* env_vars_file : kEnvironmentVariableSources) { parse_results(env_vars_file); } // Next get everything from derive_classpath, since we're already in the // chroot it will get the new versions of any dependencies. { android::base::unique_fd fd(memfd_create("derive_classpath_temp", MFD_CLOEXEC)); if (!fd.ok()) { LOG(ERROR) << "Unable to create fd for derive_classpath"; return false; } std::string memfd_file = StringPrintf("/proc/%d/fd/%d", getpid(), fd.get()); std::string error_msg; if (!Exec({"/apex/com.android.sdkext/bin/derive_classpath", memfd_file}, &error_msg)) { PLOG(ERROR) << "Running derive_classpath failed: " << error_msg; return false; } std::ifstream ifs(memfd_file); parse_results(ifs); } if (system_properties_.GetProperty(kAndroidDataPathPropertyName) == nullptr) { return false; } Loading
cmds/installd/otapreopt_chroot.cpp +1 −0 Original line number Diff line number Diff line Loading @@ -275,6 +275,7 @@ static int otapreopt_chroot(const int argc, char **arg) { static constexpr const std::string_view kRequiredApexs[] = { "com.android.art", "com.android.runtime", "com.android.sdkext", // For derive_classpath }; std::array<bool, arraysize(kRequiredApexs)> found_apexs{ false, false }; DIR* apex_dir = opendir("/apex"); Loading