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

Commit 279de56b authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "init: handle properties and imports for host init verifier"

parents fe86a147 194b5d1d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -236,7 +236,8 @@ cc_binary {
        "epoll.cpp",
        "keychords.cpp",
        "import_parser.cpp",
        "host_init_parser.cpp",
        "host_import_parser.cpp",
        "host_init_verifier.cpp",
        "host_init_stubs.cpp",
        "parser.cpp",
        "rlimit_parser.cpp",
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "host_import_parser.h"

#include <android-base/strings.h>

using android::base::StartsWith;

namespace android {
namespace init {

Result<Success> HostImportParser::ParseSection(std::vector<std::string>&& args,
                                               const std::string& filename, int line) {
    if (args.size() != 2) {
        return Error() << "single argument needed for import\n";
    }

    auto import_path = args[1];

    if (StartsWith(import_path, "/system") || StartsWith(import_path, "/product") ||
        StartsWith(import_path, "/odm") || StartsWith(import_path, "/vendor")) {
        import_path = out_dir_ + "/" + import_path;
    } else {
        import_path = out_dir_ + "/root/" + import_path;
    }

    return ImportParser::ParseSection({"import", import_path}, filename, line);
}

}  // namespace init
}  // namespace android
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <string>
#include <vector>

#include "import_parser.h"
#include "parser.h"

namespace android {
namespace init {

class HostImportParser : public ImportParser {
  public:
    HostImportParser(const std::string& out_dir, Parser* parser)
        : ImportParser(parser), out_dir_(out_dir) {}
    Result<Success> ParseSection(std::vector<std::string>&& args, const std::string& filename,
                                 int line) override;

  private:
    std::string out_dir_;
};

}  // namespace init
}  // namespace android
+7 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#include "host_init_stubs.h"

#include <android-base/properties.h>

// unistd.h
int setgroups(size_t __size, const gid_t* __list) {
    return 0;
@@ -28,7 +30,11 @@ namespace init {
std::string default_console = "/dev/console";

// property_service.h
uint32_t (*property_set)(const std::string& name, const std::string& value) = nullptr;
uint32_t SetProperty(const std::string& key, const std::string& value) {
    android::base::SetProperty(key, value);
    return 0;
}
uint32_t (*property_set)(const std::string& name, const std::string& value) = SetProperty;
uint32_t HandlePropertySet(const std::string&, const std::string&, const std::string&, const ucred&,
                           std::string*) {
    return 0;
+28 −8
Original line number Diff line number Diff line
@@ -16,15 +16,25 @@

#include <pwd.h>

#include <iostream>
#include <string>

#include <android-base/logging.h>
#include <android-base/strings.h>

#include "action.h"
#include "action_manager.h"
#include "action_parser.h"
#include "host_import_parser.h"
#include "host_init_stubs.h"
#include "parser.h"
#include "result.h"
#include "service.h"

using namespace std::literals;

using android::base::Split;

// The host passwd file won't have the Android entries, so we fake success here.
passwd* getpwnam(const char* login) {  // NOLINT: implementing bad function.
    char dummy_buf[] = "dummy";
@@ -49,10 +59,21 @@ static Result<Success> do_stub(const BuiltinArguments& args) {

int main(int argc, char** argv) {
    android::base::InitLogging(argv, &android::base::StdioLogger);
    if (argc != 2) {
        LOG(ERROR) << "Usage: " << argv[0] << " <init file to parse>";
    android::base::SetMinimumLogSeverity(android::base::ERROR);
    if (argc != 3) {
        LOG(ERROR) << "Usage: " << argv[0] << " <out directory> <properties>";
        return -1;
    }

    auto properties = Split(argv[2], ",");
    for (const auto& property : properties) {
        auto split_property = Split(property, "=");
        if (split_property.size() != 2) {
            continue;
        }
        property_set(split_property[0], split_property[1]);
    }

    const BuiltinFunctionMap function_map;
    Action::set_function_map(&function_map);
    ActionManager& am = ActionManager::GetInstance();
@@ -60,17 +81,16 @@ int main(int argc, char** argv) {
    Parser parser;
    parser.AddSectionParser("service", std::make_unique<ServiceParser>(&sl, nullptr));
    parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr));
    parser.AddSectionParser("import", std::make_unique<HostImportParser>(argv[1], &parser));

    size_t num_errors = 0;
    if (!parser.ParseConfig(argv[1], &num_errors)) {
        LOG(ERROR) << "Failed to find script";
    if (!parser.ParseConfig(argv[1] + "/root/init.rc"s)) {
        LOG(ERROR) << "Failed to find root init.rc script";
        return -1;
    }
    if (num_errors > 0) {
        LOG(ERROR) << "Parse failed with " << num_errors << " errors";
    if (parser.parse_error_count() > 0) {
        LOG(ERROR) << "Init script parsing failed with " << parser.parse_error_count() << " errors";
        return -1;
    }
    LOG(INFO) << "Parse success!";
    return 0;
}

Loading