From 5b271797de617efd9f3ccc37e9333410c7a3e5c5 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 8 Dec 2020 13:18:14 -0800 Subject: [PATCH] ueventd: add the import option from the init parser Vendors have an interest in importing ueventd files based on certain property values. Instead of baking this logic in the ueventd binary, add the import option from the init parser to the ueventd parser, to allow vendors to expand as needed. Test: imported files are parsed Change-Id: I674987fd48f3218e4703528c6d905b1afb5fb366 --- init/README.ueventd.md | 10 ++++++++++ init/ueventd.cpp | 7 +------ init/ueventd_parser.cpp | 8 ++++---- init/ueventd_parser.h | 2 +- rootdir/ueventd.rc | 4 ++++ 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/init/README.ueventd.md b/init/README.ueventd.md index 4363f3c89..62b8899cb 100644 --- a/init/README.ueventd.md +++ b/init/README.ueventd.md @@ -13,6 +13,16 @@ For example uevent_socket_rcvbuf_size 16M Sets the uevent socket rcvbuf_size to 16 megabytes. +## Importing configuration files +-------------------------------- +Ueventd reads /system/etc/ueventd.rc, all other files are imported via the `import` command, which +takes the format of + + import +This command parses an ueventd config file, extending the current configuration. If _path_ is a +directory, each file in the directory is parsed as a config file. It is not recursive, nested +directories will not be parsed. Imported files are parsed after the current file has been parsed. + ## /dev ---- Ueventd listens to the kernel uevent sockets and creates/deletes nodes in `/dev` based on the diff --git a/init/ueventd.cpp b/init/ueventd.cpp index 54659c5d7..923d76906 100644 --- a/init/ueventd.cpp +++ b/init/ueventd.cpp @@ -283,12 +283,7 @@ int ueventd_main(int argc, char** argv) { std::vector> uevent_handlers; - // Keep the current product name base configuration so we remain backwards compatible and - // allow it to override everything. - auto hardware = android::base::GetProperty("ro.hardware", ""); - - auto ueventd_configuration = ParseConfig({"/system/etc/ueventd.rc", "/vendor/ueventd.rc", - "/odm/ueventd.rc", "/ueventd." + hardware + ".rc"}); + auto ueventd_configuration = ParseConfig("/system/etc/ueventd.rc"); uevent_handlers.emplace_back(std::make_unique( std::move(ueventd_configuration.dev_permissions), diff --git a/init/ueventd_parser.cpp b/init/ueventd_parser.cpp index 09dce4481..02d1b7fec 100644 --- a/init/ueventd_parser.cpp +++ b/init/ueventd_parser.cpp @@ -21,6 +21,7 @@ #include +#include "import_parser.h" #include "keyword_map.h" #include "parser.h" @@ -220,10 +221,11 @@ Result SubsystemParser::EndSection() { return {}; } -UeventdConfiguration ParseConfig(const std::vector& configs) { +UeventdConfiguration ParseConfig(const std::string& config) { Parser parser; UeventdConfiguration ueventd_configuration; + parser.AddSectionParser("import", std::make_unique(&parser)); parser.AddSectionParser("subsystem", std::make_unique(&ueventd_configuration.subsystems)); @@ -249,9 +251,7 @@ UeventdConfiguration ParseConfig(const std::vector& configs) { std::bind(ParseEnabledDisabledLine, _1, &ueventd_configuration.enable_parallel_restorecon)); - for (const auto& config : configs) { - parser.ParseConfig(config); - } + parser.ParseConfig(config); return ueventd_configuration; } diff --git a/init/ueventd_parser.h b/init/ueventd_parser.h index eaafa5aa7..2672626c9 100644 --- a/init/ueventd_parser.h +++ b/init/ueventd_parser.h @@ -36,7 +36,7 @@ struct UeventdConfiguration { bool enable_parallel_restorecon = false; }; -UeventdConfiguration ParseConfig(const std::vector& configs); +UeventdConfiguration ParseConfig(const std::string& config); } // namespace init } // namespace android diff --git a/rootdir/ueventd.rc b/rootdir/ueventd.rc index 1994bdb8c..42229bdaa 100644 --- a/rootdir/ueventd.rc +++ b/rootdir/ueventd.rc @@ -1,3 +1,7 @@ +import /vendor/ueventd.rc +import /odm/ueventd.rc +import /ueventd.{ro.hardware}.rc + firmware_directories /etc/firmware/ /odm/firmware/ /vendor/firmware/ /firmware/image/ uevent_socket_rcvbuf_size 16M