summaryrefslogtreecommitdiff
path: root/libmodprobe/libmodprobe.cpp
diff options
context:
space:
mode:
authorSteve Muckle <smuckle@google.com>2019-07-31 15:55:00 -0700
committerSteve Muckle <smuckle@google.com>2019-08-06 13:58:13 -0700
commit012cfa19b0a3105089ba932f32b286e4129fe79a (patch)
tree2a1c6ecbb68f2c4a085c12ac2d48762e7b85797d /libmodprobe/libmodprobe.cpp
parente31f840a0a081cca2ab2a418c9611a01e3b54a98 (diff)
libmodprobe: add support to list modules
List the known modules with a name matching a given pattern. Change-Id: I7f6bd1f09a688c66682f94c5837e61d7dc61c1f7
Diffstat (limited to 'libmodprobe/libmodprobe.cpp')
-rw-r--r--libmodprobe/libmodprobe.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/libmodprobe/libmodprobe.cpp b/libmodprobe/libmodprobe.cpp
index 354ec7bce..010624240 100644
--- a/libmodprobe/libmodprobe.cpp
+++ b/libmodprobe/libmodprobe.cpp
@@ -363,3 +363,16 @@ bool Modprobe::Remove(const std::string& module_name) {
}
return true;
}
+
+std::vector<std::string> Modprobe::ListModules(const std::string& pattern) {
+ std::vector<std::string> rv;
+ for (const auto& [module, deps] : module_deps_) {
+ // Attempt to match both the canonical module name and the module filename.
+ if (!fnmatch(pattern.c_str(), module.c_str(), 0)) {
+ rv.emplace_back(module);
+ } else if (!fnmatch(pattern.c_str(), basename(deps[0].c_str()), 0)) {
+ rv.emplace_back(deps[0]);
+ }
+ }
+ return rv;
+}