Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13700a69 authored by Steve Muckle's avatar Steve Muckle
Browse files

libmodprobe: support parameters in LoadWithAliases

Add support to specify module parameters in LoadWithAliases. These
parameters will be appended to any which are specified for the module in
modules.options.

Change-Id: I9aff1656ea397826f815b658b3b52c1892748601
parent bb58b015
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -25,13 +25,14 @@ class Modprobe {
    Modprobe(const std::vector<std::string>&);

    bool LoadListedModules();
    bool LoadWithAliases(const std::string& module_name, bool strict);
    bool LoadWithAliases(const std::string& module_name, bool strict,
                         const std::string& parameters = "");
    bool Remove(const std::string& module_name);

  private:
    std::string MakeCanonical(const std::string& module_path);
    bool InsmodWithDeps(const std::string& module_name);
    bool Insmod(const std::string& path_name);
    bool InsmodWithDeps(const std::string& module_name, const std::string& parameters);
    bool Insmod(const std::string& path_name, const std::string& parameters);
    bool Rmmod(const std::string& module_name);
    std::vector<std::string> GetDependencies(const std::string& module);
    bool ModuleExists(const std::string& module_name);
+5 −4
Original line number Diff line number Diff line
@@ -242,7 +242,7 @@ std::vector<std::string> Modprobe::GetDependencies(const std::string& module) {
    return it->second;
}

bool Modprobe::InsmodWithDeps(const std::string& module_name) {
bool Modprobe::InsmodWithDeps(const std::string& module_name, const std::string& parameters) {
    if (module_name.empty()) {
        LOG(ERROR) << "Need valid module name, given: " << module_name;
        return false;
@@ -269,7 +269,7 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name) {
    }

    // load target module itself with args
    if (!Insmod(dependencies[0])) {
    if (!Insmod(dependencies[0], parameters)) {
        return false;
    }

@@ -283,7 +283,8 @@ bool Modprobe::InsmodWithDeps(const std::string& module_name) {
    return true;
}

bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict) {
bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict,
                               const std::string& parameters) {
    std::set<std::string> modules_to_load = {MakeCanonical(module_name)};
    bool module_loaded = false;

@@ -297,7 +298,7 @@ bool Modprobe::LoadWithAliases(const std::string& module_name, bool strict) {
    // attempt to load all modules aliased to this name
    for (const auto& module : modules_to_load) {
        if (!ModuleExists(module)) continue;
        if (InsmodWithDeps(module)) module_loaded = true;
        if (InsmodWithDeps(module, parameters)) module_loaded = true;
    }

    if (strict && !module_loaded) {
+4 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@

#include <modprobe/modprobe.h>

bool Modprobe::Insmod(const std::string& path_name) {
bool Modprobe::Insmod(const std::string& path_name, const std::string& parameters) {
    android::base::unique_fd fd(
            TEMP_FAILURE_RETRY(open(path_name.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC)));
    if (fd == -1) {
@@ -35,6 +35,9 @@ bool Modprobe::Insmod(const std::string& path_name) {
    if (options_iter != module_options_.end()) {
        options = options_iter->second;
    }
    if (!parameters.empty()) {
        options = options + " " + parameters;
    }

    LOG(INFO) << "Loading module " << path_name << " with args \"" << options << "\"";
    int ret = syscall(__NR_finit_module, fd.get(), options.c_str(), 0);
+5 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@

#include "libmodprobe_test.h"

bool Modprobe::Insmod(const std::string& path_name) {
bool Modprobe::Insmod(const std::string& path_name, const std::string& parameters) {
    auto deps = GetDependencies(MakeCanonical(path_name));
    if (deps.empty()) {
        return false;
@@ -47,6 +47,10 @@ bool Modprobe::Insmod(const std::string& path_name) {
    if (options_iter != module_options_.end()) {
        options = " " + options_iter->second;
    }
    if (!parameters.empty()) {
        options = options + " " + parameters;
    }

    modules_loaded.emplace_back(path_name + options);
    return true;
}