blob: 2ebf4beb99f786ad79a11eb43bfb2e5fc1978843
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * Mini insmod implementation for busybox |
4 | * |
5 | * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi> |
6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ |
9 | //config:config INSMOD |
10 | //config: bool "insmod" |
11 | //config: default n |
12 | //config: depends on !MODPROBE_SMALL |
13 | //config: select PLATFORM_LINUX |
14 | //config: help |
15 | //config: insmod is used to load specified modules in the running kernel. |
16 | |
17 | //applet:IF_INSMOD(APPLET(insmod, BB_DIR_SBIN, BB_SUID_DROP)) |
18 | |
19 | //kbuild:lib-$(CONFIG_INSMOD) += insmod.o modutils.o |
20 | |
21 | #include "libbb.h" |
22 | #include "modutils.h" |
23 | |
24 | /* 2.6 style insmod has no options and required filename |
25 | * (not module name - .ko can't be omitted) */ |
26 | |
27 | //usage:#if !ENABLE_MODPROBE_SMALL |
28 | //usage:#define insmod_trivial_usage |
29 | //usage: IF_FEATURE_2_4_MODULES("[OPTIONS] MODULE ") |
30 | //usage: IF_NOT_FEATURE_2_4_MODULES("FILE ") |
31 | //usage: "[SYMBOL=VALUE]..." |
32 | //usage:#define insmod_full_usage "\n\n" |
33 | //usage: "Load kernel module" |
34 | //usage: IF_FEATURE_2_4_MODULES( "\n" |
35 | //usage: "\n -f Force module to load into the wrong kernel version" |
36 | //usage: "\n -k Make module autoclean-able" |
37 | //usage: "\n -v Verbose" |
38 | //usage: "\n -q Quiet" |
39 | //usage: "\n -L Lock: prevent simultaneous loads" |
40 | //usage: IF_FEATURE_INSMOD_LOAD_MAP( |
41 | //usage: "\n -m Output load map to stdout" |
42 | //usage: ) |
43 | //usage: "\n -x Don't export externs" |
44 | //usage: ) |
45 | //usage:#endif |
46 | |
47 | int insmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
48 | int insmod_main(int argc UNUSED_PARAM, char **argv) |
49 | { |
50 | char *filename; |
51 | int rc; |
52 | |
53 | /* Compat note: |
54 | * 2.6 style insmod has no options and required filename |
55 | * (not module name - .ko can't be omitted). |
56 | * 2.4 style insmod can take module name without .o |
57 | * and performs module search in default directories |
58 | * or in $MODPATH. |
59 | */ |
60 | |
61 | IF_FEATURE_2_4_MODULES( |
62 | getopt32(argv, INSMOD_OPTS INSMOD_ARGS); |
63 | argv += optind - 1; |
64 | ); |
65 | |
66 | filename = *++argv; |
67 | if (!filename) |
68 | bb_show_usage(); |
69 | |
70 | rc = bb_init_module(filename, parse_cmdline_module_options(argv, /*quote_spaces:*/ 0)); |
71 | if (rc) |
72 | bb_error_msg("can't insert '%s': %s", filename, moderror(rc)); |
73 | |
74 | return rc; |
75 | } |
76 |