Skip to content

Instantly share code, notes, and snippets.

@illiliti
Created March 30, 2020 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illiliti/ef9ee781b5c6bf36d9493d99b4a1ffb6 to your computer and use it in GitHub Desktop.
Save illiliti/ef9ee781b5c6bf36d9493d99b4a1ffb6 to your computer and use it in GitHub Desktop.
add -S option to busybox modprobe
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 0a372a049..ecb29a8fd 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -111,7 +111,7 @@
//usage: " from the command line\n"
//usage:
//usage:#define modprobe_trivial_usage
-//usage: "[-alrqvsD" IF_FEATURE_MODPROBE_BLACKLIST("b") "]"
+//usage: "[-alrqvsD" IF_FEATURE_MODPROBE_BLACKLIST("b") "]" " [-S VERSION]"
//usage: " MODULE" IF_FEATURE_CMDLINE_MODULE_OPTIONS(" [SYMBOL=VALUE]...")
//usage:#define modprobe_full_usage "\n\n"
//usage: " -a Load multiple MODULEs"
@@ -121,6 +121,7 @@
//usage: "\n -v Verbose"
//usage: "\n -s Log to syslog"
//usage: "\n -D Show dependencies"
+//usage: "\n -S Set kernel version"
//usage: IF_FEATURE_MODPROBE_BLACKLIST(
//usage: "\n -b Apply blacklist to module names too"
//usage: )
@@ -131,7 +132,7 @@
* Note2: -b is always accepted, but if !FEATURE_MODPROBE_BLACKLIST,
* it is a no-op.
*/
-#define MODPROBE_OPTS "alrDb"
+#define MODPROBE_OPTS "alrDS:b"
/* -a and -D _are_ in fact compatible */
#define MODPROBE_COMPLEMENTARY "q-v:v-q:l--arD:r--alD:a--lr:D--rl"
//#define MODPROBE_OPTS "acd:lnrt:C:b"
@@ -147,7 +148,8 @@ enum {
//OPT_VERONLY = (INSMOD_OPT_UNUSED << x), /* V */
//OPT_CONFIGFILE = (INSMOD_OPT_UNUSED << x), /* C */
OPT_SHOW_DEPS = (INSMOD_OPT_UNUSED << 3), /* D */
- OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 4) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
+ OPT_KERNEL = (INSMOD_OPT_UNUSED << 4), /* S */
+ OPT_BLACKLIST = (INSMOD_OPT_UNUSED << 5) * ENABLE_FEATURE_MODPROBE_BLACKLIST,
};
#if ENABLE_LONG_OPTS
static const char modprobe_longopts[] ALIGN1 =
@@ -560,6 +562,7 @@ int modprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int modprobe_main(int argc UNUSED_PARAM, char **argv)
{
int rc;
+ char *kernel;
unsigned opt;
struct module_entry *me;
@@ -567,13 +570,20 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
opt = getopt32long(argv, "^" INSMOD_OPTS MODPROBE_OPTS "\0" MODPROBE_COMPLEMENTARY,
modprobe_longopts
- INSMOD_ARGS
+ INSMOD_ARGS,
+ &kernel
);
argv += optind;
+ /* Set user specified kernel version */
+ if (opt & OPT_KERNEL) {
+ safe_strncpy(G.uts.release, kernel, sizeof(G.uts.release));
+ } else {
+ uname(&G.uts);
+ }
+
/* Goto modules location */
xchdir(CONFIG_DEFAULT_MODULES_DIR);
- uname(&G.uts);
xchdir(G.uts.release);
if (opt & OPT_LIST_ONLY) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment