Merge "modprobe: add --all=modules.load flag" am: 3d246cced8
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1346626 Change-Id: Id4cd3f3fde6d286b2cc8b1f7e10149ef42ed31e9
This commit is contained in:
commit
f1ae0e66e3
1 changed files with 32 additions and 4 deletions
|
|
@ -15,10 +15,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
|
|
@ -37,10 +40,11 @@ void print_usage(void) {
|
||||||
std::cerr << "Usage:" << std::endl;
|
std::cerr << "Usage:" << std::endl;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
// -d option is required on Android
|
// -d option is required on Android
|
||||||
std::cerr << " modprobe [options] -d DIR MODULE..." << std::endl;
|
std::cerr << " modprobe [options] -d DIR [--all=FILE|MODULE]..." << std::endl;
|
||||||
std::cerr << " modprobe [options] -d DIR MODULE [symbol=value]..." << std::endl;
|
std::cerr << " modprobe [options] -d DIR MODULE [symbol=value]..." << std::endl;
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
std::cerr << "Options:" << std::endl;
|
std::cerr << "Options:" << std::endl;
|
||||||
|
std::cerr << " --all=FILE: FILE to acquire module names from" << std::endl;
|
||||||
std::cerr << " -b, --use-blocklist: Apply blocklist to module names too" << std::endl;
|
std::cerr << " -b, --use-blocklist: Apply blocklist to module names too" << std::endl;
|
||||||
std::cerr << " -d, --dirname=DIR: Load modules from DIR, option may be used multiple times"
|
std::cerr << " -d, --dirname=DIR: Load modules from DIR, option may be used multiple times"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
@ -61,11 +65,23 @@ void print_usage(void) {
|
||||||
return EXIT_FAILURE; \
|
return EXIT_FAILURE; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string stripComments(const std::string& str) {
|
||||||
|
for (std::string rv = str;;) {
|
||||||
|
auto comment = rv.find('#');
|
||||||
|
if (comment == std::string::npos) return rv;
|
||||||
|
auto end = rv.find('\n', comment);
|
||||||
|
if (end != std::string::npos) end = end - comment;
|
||||||
|
rv.erase(comment, end);
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
extern "C" int modprobe_main(int argc, char** argv) {
|
extern "C" int modprobe_main(int argc, char** argv) {
|
||||||
std::vector<std::string> modules;
|
std::vector<std::string> modules;
|
||||||
std::string module_parameters;
|
std::string module_parameters;
|
||||||
|
std::string mods;
|
||||||
std::vector<std::string> mod_dirs;
|
std::vector<std::string> mod_dirs;
|
||||||
modprobe_mode mode = AddModulesMode;
|
modprobe_mode mode = AddModulesMode;
|
||||||
bool blocklist = false;
|
bool blocklist = false;
|
||||||
|
|
@ -78,7 +94,7 @@ extern "C" int modprobe_main(int argc, char** argv) {
|
||||||
// OEMs to transition from toybox.
|
// OEMs to transition from toybox.
|
||||||
// clang-format off
|
// clang-format off
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{ "all", no_argument, 0, 'a' },
|
{ "all", optional_argument, 0, 'a' },
|
||||||
{ "use-blocklist", no_argument, 0, 'b' },
|
{ "use-blocklist", no_argument, 0, 'b' },
|
||||||
{ "dirname", required_argument, 0, 'd' },
|
{ "dirname", required_argument, 0, 'd' },
|
||||||
{ "show-depends", no_argument, 0, 'D' },
|
{ "show-depends", no_argument, 0, 'D' },
|
||||||
|
|
@ -89,12 +105,24 @@ extern "C" int modprobe_main(int argc, char** argv) {
|
||||||
{ "verbose", no_argument, 0, 'v' },
|
{ "verbose", no_argument, 0, 'v' },
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
while ((opt = getopt_long(argc, argv, "abd:Dhlqrv", long_options, &option_index)) != -1) {
|
while ((opt = getopt_long(argc, argv, "a::bd:Dhlqrv", long_options, &option_index)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
// toybox modprobe supported -a to load multiple modules, this
|
// toybox modprobe supported -a to load multiple modules, this
|
||||||
// is supported here by default, ignore flag
|
// is supported here by default, ignore flag if no argument.
|
||||||
check_mode();
|
check_mode();
|
||||||
|
if (optarg == NULL) break;
|
||||||
|
if (!android::base::ReadFileToString(optarg, &mods)) {
|
||||||
|
std::cerr << "Failed to open " << optarg << ": " << strerror(errno)
|
||||||
|
<< std::endl;
|
||||||
|
rv = EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
for (auto mod : android::base::Split(stripComments(mods), "\n")) {
|
||||||
|
mod = android::base::Trim(mod);
|
||||||
|
if (mod == "") continue;
|
||||||
|
if (std::find(modules.begin(), modules.end(), mod) != modules.end()) continue;
|
||||||
|
modules.emplace_back(mod);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
blocklist = true;
|
blocklist = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue