From 6737a6bf3f81105f4153bed6e447cc2f26fb3999 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Mon, 5 Aug 2019 15:03:58 -0700 Subject: [PATCH] init: Check onrestart commands Test: have bad users/groups in onrestart chown commands fail the build Change-Id: Ic7fea6395c1f6e09f06800ba373d402a81cb774c --- init/host_init_verifier.cpp | 2 +- init/service.h | 1 + init/service_list.cpp | 8 ++++++++ init/service_list.h | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp index dce3eda10..076e8b046 100644 --- a/init/host_init_verifier.cpp +++ b/init/host_init_verifier.cpp @@ -239,7 +239,7 @@ int main(int argc, char** argv) { LOG(ERROR) << "Failed to open init rc script '" << *argv << "'"; return EXIT_FAILURE; } - size_t failures = parser.parse_error_count() + am.CheckAllCommands(); + size_t failures = parser.parse_error_count() + am.CheckAllCommands() + sl.CheckAllCommands(); if (failures > 0) { LOG(ERROR) << "Failed to parse init script '" << *argv << "' with " << failures << " errors"; diff --git a/init/service.h b/init/service.h index 6f79faac7..ccefc8e91 100644 --- a/init/service.h +++ b/init/service.h @@ -97,6 +97,7 @@ class Service { void AddReapCallback(std::function callback) { reap_callbacks_.emplace_back(std::move(callback)); } + size_t CheckAllCommands() const { return onrestart_.CheckAllCommands(); } static bool is_exec_service_running() { return is_exec_service_running_; } diff --git a/init/service_list.cpp b/init/service_list.cpp index 3a4818350..c51a9cf2c 100644 --- a/init/service_list.cpp +++ b/init/service_list.cpp @@ -28,6 +28,14 @@ ServiceList& ServiceList::GetInstance() { return instance; } +size_t ServiceList::CheckAllCommands() { + size_t failures = 0; + for (const auto& service : services_) { + failures += service->CheckAllCommands(); + } + return failures; +} + void ServiceList::AddService(std::unique_ptr service) { services_.emplace_back(std::move(service)); } diff --git a/init/service_list.h b/init/service_list.h index 2136a217a..ee2c7024f 100644 --- a/init/service_list.h +++ b/init/service_list.h @@ -30,6 +30,7 @@ class ServiceList { // Exposed for testing ServiceList(); + size_t CheckAllCommands(); void AddService(std::unique_ptr service); void RemoveService(const Service& svc);