From d5d626c9f7eff613cbac2a9bfed68103f79dd4c5 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 12 Jun 2018 10:57:35 -0700 Subject: [PATCH] ueventd: fix extraneous 'Invalid section' error When adding a new error case for host_init_parser, I didn't handle the individual line callbacks used for ueventd correctly. This change fixes that. Test: bullhead boots without extraneous ueventd warnings Change-Id: I56cad854b0defd936a7fbcab73fe2f2963c0e2e4 --- init/parser.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/init/parser.cpp b/init/parser.cpp index ee6ee06db..4f1cac495 100644 --- a/init/parser.cpp +++ b/init/parser.cpp @@ -70,24 +70,23 @@ void Parser::ParseData(const std::string& filename, const std::string& data) { case T_EOF: end_section(); return; - case T_NEWLINE: + case T_NEWLINE: { state.line++; if (args.empty()) break; // If we have a line matching a prefix we recognize, call its callback and unset any // current section parsers. This is meant for /sys/ and /dev/ line entries for // uevent. - for (const auto& [prefix, callback] : line_callbacks_) { - if (android::base::StartsWith(args[0], prefix)) { - end_section(); + auto line_callback = std::find_if( + line_callbacks_.begin(), line_callbacks_.end(), + [&args](const auto& c) { return android::base::StartsWith(args[0], c.first); }); + if (line_callback != line_callbacks_.end()) { + end_section(); - if (auto result = callback(std::move(args)); !result) { - parse_error_count_++; - LOG(ERROR) << filename << ": " << state.line << ": " << result.error(); - } - break; + if (auto result = line_callback->second(std::move(args)); !result) { + parse_error_count_++; + LOG(ERROR) << filename << ": " << state.line << ": " << result.error(); } - } - if (section_parsers_.count(args[0])) { + } else if (section_parsers_.count(args[0])) { end_section(); section_parser = section_parsers_[args[0]].get(); section_start_line = state.line; @@ -111,6 +110,7 @@ void Parser::ParseData(const std::string& filename, const std::string& data) { } args.clear(); break; + } case T_TEXT: args.emplace_back(state.text); break;