From a91cdefe52ab755f30822876e06f173fd33d6af2 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Wed, 6 Dec 2023 15:22:36 +0900 Subject: [PATCH] debug-tools: bootlogger: Sort out common rules, if exist --- debug-tools/bootlogger/Logger.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/debug-tools/bootlogger/Logger.cpp b/debug-tools/bootlogger/Logger.cpp index 6e73ed4..9627e0d 100644 --- a/debug-tools/bootlogger/Logger.cpp +++ b/debug-tools/bootlogger/Logger.cpp @@ -423,10 +423,20 @@ int main(int argc, const char** argv) { i.join(); if (kAvcCtx) { - std::string allowrules; - for (const auto& e : *kAvcCtx) - writeAllowRules(e, allowrules); - WriteStringToFile(allowrules, kLogDir.append("rules.autogen.te")); + std::vector allowrules; + std::stringstream iss; + for (const auto& e : *kAvcCtx) { + std::string line; + writeAllowRules(e, line); + allowrules.emplace_back(line); + } + std::sort(allowrules.begin(), allowrules.end()); + allowrules.erase(std::unique(allowrules.begin(), allowrules.end()), allowrules.end()); + for (const auto& l : allowrules) + iss << l; + auto rules = kLogDir; + rules.append("rules.autogen.te"); + WriteStringToFile(iss.str(), rules); } return 0; }