summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Muckle <smuckle@google.com>2019-08-01 14:55:07 -0700
committerSteve Muckle <smuckle@google.com>2019-08-06 13:58:13 -0700
commit781aa78ee25fca2bb27a9b724ae111f9581e63f7 (patch)
tree668e5b4ae072eb656323516a3657612ae6bc5f5c
parent012cfa19b0a3105089ba932f32b286e4129fe79a (diff)
libmodprobe: add GetAllDependencies
Add a method to retrieve the dependencies (both hard and soft) of a module. Change-Id: Ie44ceb3e36856bb1a3e68c5d3c0d55a38deb0ef9
-rw-r--r--libmodprobe/include/modprobe/modprobe.h3
-rw-r--r--libmodprobe/libmodprobe.cpp33
2 files changed, 36 insertions, 0 deletions
diff --git a/libmodprobe/include/modprobe/modprobe.h b/libmodprobe/include/modprobe/modprobe.h
index 913a7870b..0599ec538 100644
--- a/libmodprobe/include/modprobe/modprobe.h
+++ b/libmodprobe/include/modprobe/modprobe.h
@@ -30,6 +30,9 @@ class Modprobe {
const std::string& parameters = "");
bool Remove(const std::string& module_name);
std::vector<std::string> ListModules(const std::string& pattern);
+ bool GetAllDependencies(const std::string& module, std::vector<std::string>* pre_dependencies,
+ std::vector<std::string>* dependencies,
+ std::vector<std::string>* post_dependencies);
void EnableBlacklist(bool enable);
private:
diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp
index 010624240..3e9001a0e 100644
--- a/libmodprobe/libmodprobe.cpp
+++ b/libmodprobe/libmodprobe.cpp
@@ -376,3 +376,36 @@ std::vector<std::string> Modprobe::ListModules(const std::string& pattern) {
}
return rv;
}
+
+bool Modprobe::GetAllDependencies(const std::string& module,
+ std::vector<std::string>* pre_dependencies,
+ std::vector<std::string>* dependencies,
+ std::vector<std::string>* post_dependencies) {
+ std::string canonical_name = MakeCanonical(module);
+ if (pre_dependencies) {
+ pre_dependencies->clear();
+ for (const auto& [it_module, it_softdep] : module_pre_softdep_) {
+ if (canonical_name == it_module) {
+ pre_dependencies->emplace_back(it_softdep);
+ }
+ }
+ }
+ if (dependencies) {
+ dependencies->clear();
+ auto hard_deps = GetDependencies(canonical_name);
+ if (hard_deps.empty()) {
+ return false;
+ }
+ for (auto dep = hard_deps.rbegin(); dep != hard_deps.rend(); dep++) {
+ dependencies->emplace_back(*dep);
+ }
+ }
+ if (post_dependencies) {
+ for (const auto& [it_module, it_softdep] : module_post_softdep_) {
+ if (canonical_name == it_module) {
+ post_dependencies->emplace_back(it_softdep);
+ }
+ }
+ }
+ return true;
+}