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

Commit 003d1827 authored by Nikita Ioffe's avatar Nikita Ioffe Committed by Automerger Merge Worker
Browse files

Merge "Reject services that are both critical and oneshot" am: e8748755

Change-Id: Iee0d3c1d84cc20c7b26dc93c207705021e02ebe3
parents 6962ba55 e8748755
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -239,6 +239,28 @@ TEST(init, EventTriggerOrderMultipleFiles) {
    EXPECT_EQ(6, num_executed);
}

TEST(init, RejectsCriticalAndOneshotService) {
    std::string init_script =
            R"init(
service A something
  class first
  critical
  oneshot
)init";

    TemporaryFile tf;
    ASSERT_TRUE(tf.fd != -1);
    ASSERT_TRUE(android::base::WriteStringToFd(init_script, tf.fd));

    ServiceList service_list;
    Parser parser;
    parser.AddSectionParser("service",
                            std::make_unique<ServiceParser>(&service_list, nullptr, std::nullopt));

    ASSERT_TRUE(parser.ParseConfig(tf.path));
    ASSERT_EQ(1u, parser.parse_error_count());
}

}  // namespace init
}  // namespace android

+7 −0
Original line number Diff line number Diff line
@@ -605,6 +605,13 @@ Result<void> ServiceParser::EndSection() {
        }
    }

    if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_R__) {
        if ((service_->flags() & SVC_CRITICAL) != 0 && (service_->flags() & SVC_ONESHOT) != 0) {
            return Error() << "service '" << service_->name()
                           << "' can't be both critical and oneshot";
        }
    }

    Service* old_service = service_list_->FindService(service_->name());
    if (old_service) {
        if (!service_->is_override()) {