summaryrefslogtreecommitdiff
path: root/init/builtins.cpp
diff options
context:
space:
mode:
authorHung-ying Tyan <tyanh@google.com>2016-05-17 18:49:10 +0800
committerHung-ying Tyan <tyanh@google.com>2016-06-24 11:10:46 +0800
commitbfa6d75c60704e73b204b9ddcccd443e862ffa34 (patch)
tree8cfc0613c4cb72556a37a6b338ff1ee81b0dced8 /init/builtins.cpp
parent59e6afc617bf5ce341de4f3d0428c2b1a79879ee (diff)
Add -f to insmod
When the flag is on, insmod will bypass vermagic and symbol version checking in the kernel. This is to make it possible to update kernel without recompiling kernel modules. BUG=28803994 Change-Id: Ib4be6999ef52baefd4210ee0d242360e43318907
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r--init/builtins.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 89f6c68c8..98595da0e 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -36,6 +36,7 @@
#include <sys/wait.h>
#include <unistd.h>
#include <linux/loop.h>
+#include <linux/module.h>
#include <ext4_crypt_init_extensions.h>
#include <selinux/selinux.h>
@@ -44,6 +45,7 @@
#include <fs_mgr.h>
#include <android-base/file.h>
#include <android-base/parseint.h>
+#include <android-base/strings.h>
#include <android-base/stringprintf.h>
#include <cutils/partition_utils.h>
#include <cutils/android_reboot.h>
@@ -66,13 +68,13 @@
static const int kTerminateServiceDelayMicroSeconds = 50000;
-static int insmod(const char *filename, const char *options) {
+static int insmod(const char *filename, const char *options, int flags) {
int fd = open(filename, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
if (fd == -1) {
ERROR("insmod: open(\"%s\") failed: %s", filename, strerror(errno));
return -1;
}
- int rc = syscall(__NR_finit_module, fd, options, 0);
+ int rc = syscall(__NR_finit_module, fd, options, flags);
if (rc == -1) {
ERROR("finit_module for \"%s\" failed: %s", filename, strerror(errno));
}
@@ -269,17 +271,17 @@ static int do_ifup(const std::vector<std::string>& args) {
}
static int do_insmod(const std::vector<std::string>& args) {
- std::string options;
+ int flags = 0;
+ auto it = args.begin() + 1;
- if (args.size() > 2) {
- options += args[2];
- for (std::size_t i = 3; i < args.size(); ++i) {
- options += ' ';
- options += args[i];
- }
+ if (!(*it).compare("-f")) {
+ flags = MODULE_INIT_IGNORE_VERMAGIC | MODULE_INIT_IGNORE_MODVERSIONS;
+ it++;
}
- return insmod(args[1].c_str(), options.c_str());
+ std::string filename = *it++;
+ std::string options = android::base::Join(std::vector<std::string>(it, args.end()), ' ');
+ return insmod(filename.c_str(), options.c_str(), flags);
}
static int do_mkdir(const std::vector<std::string>& args) {