From 83207784251c560809c06fe391362b312bfb3923 Mon Sep 17 00:00:00 2001 From: Vincent Donnefort Date: Tue, 24 Jan 2023 17:39:16 +0000 Subject: [PATCH] toolbox/modprobe: Fallback to /lib/modules/ Make the module directory optional by reading the kernel release version. This path is where the kernel installs modules by default. Similar behaviour can be found in several modprobe implementations. Bug: 254835242 Change-Id: I61707636705e5b4d9bd8ccf6351e7057eae6bcf5 --- toolbox/modprobe.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/toolbox/modprobe.cpp b/toolbox/modprobe.cpp index 711586a98..17f815697 100644 --- a/toolbox/modprobe.cpp +++ b/toolbox/modprobe.cpp @@ -23,8 +23,11 @@ #include #include #include +#include #include +#include + namespace { enum modprobe_mode { @@ -37,9 +40,8 @@ enum modprobe_mode { void print_usage(void) { LOG(INFO) << "Usage:"; LOG(INFO); - // -d option is required on Android - LOG(INFO) << " modprobe [options] -d DIR [--all=FILE|MODULE]..."; - LOG(INFO) << " modprobe [options] -d DIR MODULE [symbol=value]..."; + LOG(INFO) << " modprobe [options] [-d DIR] [--all=FILE|MODULE]..."; + LOG(INFO) << " modprobe [options] [-d DIR] MODULE [symbol=value]..."; LOG(INFO); LOG(INFO) << "Options:"; LOG(INFO) << " --all=FILE: FILE to acquire module names from"; @@ -189,6 +191,12 @@ extern "C" int modprobe_main(int argc, char** argv) { } } + if (mod_dirs.empty()) { + utsname uts; + uname(&uts); + mod_dirs.emplace_back(android::base::StringPrintf("/lib/modules/%s", uts.release)); + } + LOG(DEBUG) << "mode is " << mode; LOG(DEBUG) << "mod_dirs is: " << android::base::Join(mod_dirs, " "); LOG(DEBUG) << "modules is: " << android::base::Join(modules, " ");