Reject services that are both critical and oneshot
Test: atest CtsInitTestCases Test: builds Test: device boots Bug: 155275196 Change-Id: I1bb9099371bd1a3f339396ef343c49b054fcef66
This commit is contained in:
parent
08929cc389
commit
6a3c94b3aa
2 changed files with 29 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue