Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9200fb2d authored by Jiyong Park's avatar Jiyong Park Committed by android-build-merger
Browse files

Merge "init parses *.rc files from APEXes"

am: a4e4e394

Change-Id: I0fe8a465c38282dcb17db227c35d96bb6e2b46fb
parents 869f2df6 a4e4e394
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -275,6 +275,10 @@ runs the service.
  since it has some peculiarities for backwards compatibility reasons. The 'imports' section of
  since it has some peculiarities for backwards compatibility reasons. The 'imports' section of
  this file has more details on the order.
  this file has more details on the order.


`parse_apex_configs`
  Parses config file(s) from the mounted APEXes. Intented to be used only once
  when apexd notifies the mount event by setting apexd.status to ready.

`priority <priority>`
`priority <priority>`
> Scheduling priority of the service process. This value has to be in range
> Scheduling priority of the service process. This value has to be in range
  -20 to 19. Default priority is 0. Priority is set via setpriority().
  -20 to 19. Default priority is 0. Priority is set via setpriority().
+34 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#include <fts.h>
#include <fts.h>
#include <glob.h>
#include <linux/loop.h>
#include <linux/loop.h>
#include <linux/module.h>
#include <linux/module.h>
#include <mntent.h>
#include <mntent.h>
@@ -1053,6 +1054,38 @@ static Result<Success> do_init_user0(const BuiltinArguments& args) {
        {{"exec", "/system/bin/vdc", "--wait", "cryptfs", "init_user0"}, args.context});
        {{"exec", "/system/bin/vdc", "--wait", "cryptfs", "init_user0"}, args.context});
}
}


static Result<Success> do_parse_apex_configs(const BuiltinArguments& args) {
    glob_t glob_result;
    // @ is added to filter out the later paths, which are bind mounts of the places
    // where the APEXes are really mounted at. Otherwise, we will parse the
    // same file twice.
    static constexpr char glob_pattern[] = "/apex/*@*/etc/*.rc";
    if (glob(glob_pattern, GLOB_MARK, nullptr, &glob_result) != 0) {
        globfree(&glob_result);
        return Error() << "glob pattern '" << glob_pattern << "' failed";
    }
    std::vector<std::string> configs;
    Parser parser = CreateServiceOnlyParser(ServiceList::GetInstance());
    for (size_t i = 0; i < glob_result.gl_pathc; i++) {
        configs.emplace_back(glob_result.gl_pathv[i]);
    }
    globfree(&glob_result);

    bool success = true;
    for (const auto& c : configs) {
        if (c.back() == '/') {
            // skip if directory
            continue;
        }
        success &= parser.ParseConfigFile(c);
    }
    if (success) {
        return Success();
    } else {
        return Error() << "Could not parse apex configs";
    }
}

// Builtin-function-map start
// Builtin-function-map start
const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const {
const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const {
    constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
    constexpr std::size_t kMax = std::numeric_limits<std::size_t>::max();
@@ -1090,6 +1123,7 @@ const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const {
        // mount and umount are run in the same context as mount_all for symmetry.
        // mount and umount are run in the same context as mount_all for symmetry.
        {"mount_all",               {1,     kMax, {false,  do_mount_all}}},
        {"mount_all",               {1,     kMax, {false,  do_mount_all}}},
        {"mount",                   {3,     kMax, {false,  do_mount}}},
        {"mount",                   {3,     kMax, {false,  do_mount}}},
        {"parse_apex_configs",      {0,     0,    {false,  do_parse_apex_configs}}},
        {"umount",                  {1,     1,    {false,  do_umount}}},
        {"umount",                  {1,     1,    {false,  do_umount}}},
        {"readahead",               {1,     2,    {true,   do_readahead}}},
        {"readahead",               {1,     2,    {true,   do_readahead}}},
        {"restart",                 {1,     1,    {false,  do_restart}}},
        {"restart",                 {1,     1,    {false,  do_restart}}},
+8 −0
Original line number Original line Diff line number Diff line
@@ -132,6 +132,14 @@ Parser CreateParser(ActionManager& action_manager, ServiceList& service_list) {
    return parser;
    return parser;
}
}


// parser that only accepts new services
Parser CreateServiceOnlyParser(ServiceList& service_list) {
    Parser parser;

    parser.AddSectionParser("service", std::make_unique<ServiceParser>(&service_list, subcontexts));
    return parser;
}

static void LoadBootScripts(ActionManager& action_manager, ServiceList& service_list) {
static void LoadBootScripts(ActionManager& action_manager, ServiceList& service_list) {
    Parser parser = CreateParser(action_manager, service_list);
    Parser parser = CreateParser(action_manager, service_list);


+1 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ extern std::string default_console;
extern std::vector<std::string> late_import_paths;
extern std::vector<std::string> late_import_paths;


Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
Parser CreateServiceOnlyParser(ServiceList& service_list);


void HandleControlMessage(const std::string& msg, const std::string& arg, pid_t pid);
void HandleControlMessage(const std::string& msg, const std::string& arg, pid_t pid);


+1 −1
Original line number Original line Diff line number Diff line
@@ -72,6 +72,7 @@ class Parser {
    Parser();
    Parser();


    bool ParseConfig(const std::string& path);
    bool ParseConfig(const std::string& path);
    bool ParseConfigFile(const std::string& path);
    void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser);
    void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser);
    void AddSingleLineParser(const std::string& prefix, LineCallback callback);
    void AddSingleLineParser(const std::string& prefix, LineCallback callback);


@@ -82,7 +83,6 @@ class Parser {


  private:
  private:
    void ParseData(const std::string& filename, std::string* data);
    void ParseData(const std::string& filename, std::string* data);
    bool ParseConfigFile(const std::string& path);
    bool ParseConfigDir(const std::string& path);
    bool ParseConfigDir(const std::string& path);


    std::map<std::string, std::unique_ptr<SectionParser>> section_parsers_;
    std::map<std::string, std::unique_ptr<SectionParser>> section_parsers_;
Loading