diff options
Diffstat (limited to 'libmodprobe/libmodprobe.cpp')
-rw-r--r-- | libmodprobe/libmodprobe.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp index 1a9d3642c..5a6ae8be1 100644 --- a/libmodprobe/libmodprobe.cpp +++ b/libmodprobe/libmodprobe.cpp @@ -66,7 +66,6 @@ bool Modprobe::ParseDepCallback(const std::string& base_path, deps.emplace_back(prefix + args[0].substr(0, pos)); } else { LOG(ERROR) << "dependency lines must start with name followed by ':'"; - return false; } // Remaining items are dependencies of our module @@ -313,9 +312,7 @@ void Modprobe::ParseKernelCmdlineOptions(void) { } } -Modprobe::Modprobe(const std::vector<std::string>& base_paths, const std::string load_file, - bool use_blocklist) - : blocklist_enabled(use_blocklist) { +Modprobe::Modprobe(const std::vector<std::string>& base_paths, const std::string load_file) { using namespace std::placeholders; for (const auto& base_path : base_paths) { @@ -339,6 +336,19 @@ Modprobe::Modprobe(const std::vector<std::string>& base_paths, const std::string } ParseKernelCmdlineOptions(); + android::base::SetMinimumLogSeverity(android::base::INFO); +} + +void Modprobe::EnableBlocklist(bool enable) { + blocklist_enabled = enable; +} + +void Modprobe::EnableVerbose(bool enable) { + if (enable) { + android::base::SetMinimumLogSeverity(android::base::VERBOSE); + } else { + android::base::SetMinimumLogSeverity(android::base::INFO); + } } std::vector<std::string> Modprobe::GetDependencies(const std::string& module) { @@ -425,23 +435,10 @@ bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict, return true; } -bool Modprobe::IsBlocklisted(const std::string& module_name) { - if (!blocklist_enabled) return false; - - auto canonical_name = MakeCanonical(module_name); - auto dependencies = GetDependencies(canonical_name); - for (auto dep = dependencies.begin(); dep != dependencies.end(); ++dep) { - if (module_blocklist_.count(MakeCanonical(*dep))) return true; - } - - return module_blocklist_.count(canonical_name) > 0; -} - bool Modprobe::LoadListedModules(bool strict) { auto ret = true; for (const auto& module : module_load_) { if (!LoadWithAliases(module, true)) { - if (IsBlocklisted(module)) continue; ret = false; if (strict) break; } @@ -451,10 +448,16 @@ bool Modprobe::LoadListedModules(bool strict) { bool Modprobe::Remove(const std::string& module_name) { auto dependencies = GetDependencies(MakeCanonical(module_name)); - for (auto dep = dependencies.begin(); dep != dependencies.end(); ++dep) { + if (dependencies.empty()) { + LOG(ERROR) << "Empty dependencies for module " << module_name; + return false; + } + if (!Rmmod(dependencies[0])) { + return false; + } + for (auto dep = dependencies.begin() + 1; dep != dependencies.end(); ++dep) { Rmmod(*dep); } - Rmmod(module_name); return true; } |