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

Commit 6a3c94b3 authored by Nikita Ioffe's avatar Nikita Ioffe
Browse files

Reject services that are both critical and oneshot

Test: atest CtsInitTestCases
Test: builds
Test: device boots
Bug: 155275196
Change-Id: I1bb9099371bd1a3f339396ef343c49b054fcef66
parent 08929cc3
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
@@ -598,6 +598,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()) {