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

Commit d172618e authored by Nikita Ioffe's avatar Nikita Ioffe Committed by Android (Google) Code Review
Browse files

Merge "Reject services that are both critical and oneshot" into rvc-dev

parents 65e8e380 6a3c94b3
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()) {