2
* kmod-insmod - insert modules into linux kernel using libkmod.
4
* Copyright (C) 2011 ProFUSION embedded systems
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28
static const char cmdopts_s[] = "psfVh";
29
static const struct option cmdopts[] = {
30
{"version", no_argument, 0, 'V'},
31
{"help", no_argument, 0, 'h'},
35
static void help(const char *progname)
39
"\t%s [options] filename [args]\n"
41
"\t-V, --version show version\n"
42
"\t-h, --help show this help\n",
46
static const char *mod_strerror(int err)
50
return "Invalid module format";
52
return "Unknown symbol in module";
54
return "Module has wrong symbol version";
56
return "Invalid parameters";
62
static int do_insmod(int argc, char *argv[])
65
struct kmod_module *mod;
70
const char *null_config = NULL;
74
c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
81
/* ignored, for compatibility only */
84
help(basename(argv[0]));
87
puts(PACKAGE " version " VERSION);
93
"Error: unexpected getopt_long() value '%c'.\n",
100
fprintf(stderr, "Error: missing filename.\n");
104
filename = argv[optind];
105
if (strcmp(filename, "-") == 0) {
106
fputs("Error: this tool does not support loading from stdin!\n",
111
for (i = optind + 1; i < argc; i++) {
112
size_t len = strlen(argv[i]);
113
void *tmp = realloc(opts, optslen + len + 2);
115
fputs("Error: out of memory\n", stderr);
124
memcpy(opts + optslen, argv[i], len);
126
opts[optslen] = '\0';
129
ctx = kmod_new(NULL, &null_config);
131
fputs("Error: kmod_new() failed!\n", stderr);
136
err = kmod_module_new_from_path(ctx, filename, &mod);
138
fprintf(stderr, "Error: could not load module %s: %s\n",
139
filename, strerror(-err));
143
err = kmod_module_insert_module(mod, 0, opts);
145
fprintf(stderr, "Error: could not insert module %s: %s\n",
146
filename, mod_strerror(-err));
148
kmod_module_unref(mod);
153
return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
156
#ifndef KMOD_BUNDLE_TOOL
157
int main(int argc, char *argv[])
159
return do_insmod(argc, argv);
165
const struct kmod_cmd kmod_cmd_compat_insmod = {
168
.help = "compat insmod command",