blob: 17a8c1716bf8d27f1369f79eb897c620a023d8de [file] [log] [blame]
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -02001/*
Lucas De Marchi8b013762012-01-12 17:14:30 -02002 * kmod-modprobe - manage linux kernel modules using libkmod.
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -02003 *
Lucas De Marchia66a6a92012-01-09 00:40:50 -02004 * Copyright (C) 2011-2012 ProFUSION embedded systems
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -02005 *
Lucas De Marchicb451f32011-12-12 18:24:35 -02006 * 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.
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020010 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Lucas De Marchicb451f32011-12-12 18:24:35 -020013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020015 *
Lucas De Marchicb451f32011-12-12 18:24:35 -020016 * 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/>.
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020018 */
Lucas De Marchicb451f32011-12-12 18:24:35 -020019
Lucas De Marchi4744ebc2012-03-15 00:14:35 -030020#include <assert.h>
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020021#include <stdio.h>
22#include <stdlib.h>
Lucas De Marchi0cf28322012-01-12 02:21:26 -020023#include <stdbool.h>
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020024#include <getopt.h>
25#include <errno.h>
26#include <string.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <sys/utsname.h>
Thierry Vignaudeff917c2012-01-17 17:32:48 -020030#include <sys/wait.h>
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020031#include <unistd.h>
32#include <syslog.h>
33#include <limits.h>
34
35#include "libkmod.h"
Lucas De Marchi8b013762012-01-12 17:14:30 -020036#include "libkmod-array.h"
Lucas De Marchibc434962012-01-13 02:35:34 -020037#include "macro.h"
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020038
39static int log_priority = LOG_CRIT;
40static int use_syslog = 0;
41
42#define DEFAULT_VERBOSE LOG_WARNING
43static int verbose = DEFAULT_VERBOSE;
Gustavo Sverzut Barbieri525fa072012-01-08 13:58:28 -020044static int do_show = 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020045static int dry_run = 0;
46static int ignore_loaded = 0;
Lucas De Marchi81229852011-12-16 02:58:48 -020047static int lookup_only = 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020048static int first_time = 0;
49static int ignore_commands = 0;
50static int use_blacklist = 0;
51static int force = 0;
52static int strip_modversion = 0;
53static int strip_vermagic = 0;
54static int remove_dependencies = 0;
Lucas De Marchid8a6c0c2012-01-01 06:07:46 -020055static int quiet_inuse = 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020056
Dave Reisnercc988302012-01-26 11:36:35 -050057static const char cmdopts_s[] = "arRibfDcnC:d:S:sqvVh";
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020058static const struct option cmdopts[] = {
59 {"all", no_argument, 0, 'a'},
60 {"remove", no_argument, 0, 'r'},
61 {"remove-dependencies", no_argument, 0, 5},
62 {"resolve-alias", no_argument, 0, 'R'},
63 {"first-time", no_argument, 0, 3},
64 {"ignore-install", no_argument, 0, 'i'},
65 {"ignore-remove", no_argument, 0, 'i'},
66 {"use-blacklist", no_argument, 0, 'b'},
67 {"force", no_argument, 0, 'f'},
68 {"force-modversion", no_argument, 0, 2},
69 {"force-vermagic", no_argument, 0, 1},
70
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -020071 {"show-depends", no_argument, 0, 'D'},
72 {"showconfig", no_argument, 0, 'c'},
73 {"show-config", no_argument, 0, 'c'},
74 {"show-modversions", no_argument, 0, 4},
75 {"dump-modversions", no_argument, 0, 4},
76
77 {"dry-run", no_argument, 0, 'n'},
78 {"show", no_argument, 0, 'n'},
79
80 {"config", required_argument, 0, 'C'},
81 {"dirname", required_argument, 0, 'd'},
82 {"set-version", required_argument, 0, 'S'},
83
84 {"syslog", no_argument, 0, 's'},
85 {"quiet", no_argument, 0, 'q'},
86 {"verbose", no_argument, 0, 'v'},
87 {"version", no_argument, 0, 'V'},
88 {"help", no_argument, 0, 'h'},
89 {NULL, 0, 0, 0}
90};
91
92static void help(const char *progname)
93{
94 fprintf(stderr,
95 "Usage:\n"
96 "\t%s [options] [-i] [-b] modulename\n"
97 "\t%s [options] -a [-i] [-b] modulename [modulename...]\n"
98 "\t%s [options] -r [-i] modulename\n"
99 "\t%s [options] -r -a [-i] modulename [modulename...]\n"
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200100 "\t%s [options] -c\n"
101 "\t%s [options] --dump-modversions filename\n"
102 "Management Options:\n"
Gustavo Sverzut Barbieriab70dce2011-12-19 13:02:15 -0200103 "\t-a, --all Consider every non-argument to\n"
104 "\t be a module name to be inserted\n"
105 "\t or removed (-r)\n"
106 "\t-r, --remove Remove modules instead of inserting\n"
107 "\t --remove-dependencies Also remove modules depending on it\n"
108 "\t-R, --resolve-alias Only lookup and print alias and exit\n"
109 "\t --first-time Fail if module already inserted or removed\n"
110 "\t-i, --ignore-install Ignore install commands\n"
111 "\t-i, --ignore-remove Ignore remove commands\n"
112 "\t-b, --use-blacklist Apply blacklist to resolved alias.\n"
113 "\t-f, --force Force module insertion or removal.\n"
114 "\t implies --force-modversions and\n"
115 "\t --force-vermagic\n"
116 "\t --force-modversion Ignore module's version\n"
117 "\t --force-vermagic Ignore module's version magic\n"
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200118 "\n"
119 "Query Options:\n"
Gustavo Sverzut Barbieriab70dce2011-12-19 13:02:15 -0200120 "\t-D, --show-depends Only print module dependencies and exit\n"
121 "\t-c, --showconfig Print out known configuration and exit\n"
122 "\t-c, --show-config Same as --showconfig\n"
123 "\t --show-modversions Dump module symbol version and exit\n"
124 "\t --dump-modversions Same as --show-modversions\n"
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200125 "\n"
126 "General Options:\n"
Gustavo Sverzut Barbieriab70dce2011-12-19 13:02:15 -0200127 "\t-n, --dry-run Do not execute operations, just print out\n"
128 "\t-n, --show Same as --dry-run\n"
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200129
Lucas De Marchi2c966932011-12-20 16:39:59 -0200130 "\t-C, --config=FILE Use FILE instead of default search paths\n"
Dave Reisnerc5b37db2012-09-27 11:00:42 -0400131 "\t-d, --dirname=DIR Use DIR as filesystem root for /lib/modules\n"
Gustavo Sverzut Barbieriab70dce2011-12-19 13:02:15 -0200132 "\t-S, --set-version=VERSION Use VERSION instead of `uname -r`\n"
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200133
134 "\t-s, --syslog print to syslog, not stderr\n"
135 "\t-q, --quiet disable messages\n"
136 "\t-v, --verbose enables more messages\n"
137 "\t-V, --version show version\n"
138 "\t-h, --help show this help\n",
Lucas De Marchi3ef848b2012-01-26 16:01:34 -0200139 progname, progname, progname, progname, progname, progname);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200140}
141
142static inline void _show(const char *fmt, ...)
143{
144 va_list args;
145
Gustavo Sverzut Barbieri525fa072012-01-08 13:58:28 -0200146 if (!do_show && verbose <= DEFAULT_VERBOSE)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200147 return;
148
149 va_start(args, fmt);
150 vfprintf(stdout, fmt, args);
151 fflush(stdout);
152 va_end(args);
153}
154
Lucas De Marchi1e947e32012-10-31 22:00:40 -0200155static _always_inline_ const char *prio_to_str(int prio)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200156{
157 const char *prioname;
Lucas De Marchi1e947e32012-10-31 22:00:40 -0200158 char buf[32];
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200159
160 switch (prio) {
161 case LOG_CRIT:
162 prioname = "FATAL";
163 break;
164 case LOG_ERR:
165 prioname = "ERROR";
166 break;
167 case LOG_WARNING:
168 prioname = "WARNING";
169 break;
170 case LOG_NOTICE:
171 prioname = "NOTICE";
172 break;
173 case LOG_INFO:
174 prioname = "INFO";
175 break;
176 case LOG_DEBUG:
177 prioname = "DEBUG";
178 break;
179 default:
180 snprintf(buf, sizeof(buf), "LOG-%03d", prio);
181 prioname = buf;
182 }
183
Lucas De Marchi1e947e32012-10-31 22:00:40 -0200184 return prioname;
185}
186
187static inline void _log(int prio, const char *fmt, ...)
188{
189 const char *prioname;
190 char *msg;
191 va_list args;
192
193 if (prio > verbose)
194 return;
195
196 va_start(args, fmt);
197 if (vasprintf(&msg, fmt, args) < 0)
198 msg = NULL;
199 va_end(args);
200 if (msg == NULL)
201 return;
202
203 prioname = prio_to_str(prio);
204
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200205 if (use_syslog)
206 syslog(LOG_NOTICE, "%s: %s", prioname, msg);
207 else
208 fprintf(stderr, "%s: %s", prioname, msg);
209 free(msg);
210
211 if (prio <= LOG_CRIT)
212 exit(EXIT_FAILURE);
213}
214#define ERR(...) _log(LOG_ERR, __VA_ARGS__)
215#define WRN(...) _log(LOG_WARNING, __VA_ARGS__)
216#define INF(...) _log(LOG_INFO, __VA_ARGS__)
217#define DBG(...) _log(LOG_DEBUG, __VA_ARGS__)
218#define LOG(...) _log(log_priority, __VA_ARGS__)
219#define SHOW(...) _show(__VA_ARGS__)
220
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200221static int show_config(struct kmod_ctx *ctx)
222{
Lucas De Marchibc434962012-01-13 02:35:34 -0200223 struct config_iterators {
224 const char *name;
225 struct kmod_config_iter *(*get_iter)(const struct kmod_ctx *ctx);
226 } ci[] = {
227 { "blacklist", kmod_config_get_blacklists },
228 { "install", kmod_config_get_install_commands },
229 { "remove", kmod_config_get_remove_commands },
230 { "alias", kmod_config_get_aliases },
Elan Ruusamäe02629fa2012-03-22 12:00:16 -0300231 { "options", kmod_config_get_options },
Lucas De Marchibc434962012-01-13 02:35:34 -0200232 { "softdep", kmod_config_get_softdeps },
233 };
234 size_t i;
235
236 for (i = 0; i < ARRAY_SIZE(ci); i++) {
237 struct kmod_config_iter *iter = ci[i].get_iter(ctx);
238
239 if (iter == NULL)
240 continue;
241
242 while (kmod_config_iter_next(iter)) {
243 const char *val;
244
245 printf("%s %s", ci[i].name,
246 kmod_config_iter_get_key(iter));
247 val = kmod_config_iter_get_value(iter);
248 if (val != NULL) {
249 putchar(' ');
250 puts(val);
251 } else
252 putchar('\n');
253 }
254
255 kmod_config_iter_free_iter(iter);
256 }
257
Lucas De Marchi28f32c62012-01-27 23:56:46 -0200258 puts("\n# End of configuration files. Dumping indexes now:\n");
Lucas De Marchi09e9ae52012-01-17 10:05:02 -0200259 fflush(stdout);
260
Lucas De Marchi49a16372012-01-16 16:00:35 -0200261 kmod_dump_index(ctx, KMOD_INDEX_MODULES_ALIAS, STDOUT_FILENO);
262 kmod_dump_index(ctx, KMOD_INDEX_MODULES_SYMBOL, STDOUT_FILENO);
263
Lucas De Marchibc434962012-01-13 02:35:34 -0200264 return 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200265}
266
267static int show_modversions(struct kmod_ctx *ctx, const char *filename)
268{
Gustavo Sverzut Barbieri0e3e2f42011-12-19 12:45:22 -0200269 struct kmod_list *l, *list = NULL;
270 struct kmod_module *mod;
271 int err = kmod_module_new_from_path(ctx, filename, &mod);
272 if (err < 0) {
273 LOG("Module %s not found.\n", filename);
274 return err;
275 }
276
277 err = kmod_module_get_versions(mod, &list);
278 if (err < 0) {
Dave Reisner63698372012-01-04 10:41:50 -0500279 LOG("could not get modversions of %s: %s\n",
Gustavo Sverzut Barbieri0e3e2f42011-12-19 12:45:22 -0200280 filename, strerror(-err));
281 kmod_module_unref(mod);
282 return err;
283 }
284
285 kmod_list_foreach(l, list) {
286 const char *symbol = kmod_module_version_get_symbol(l);
287 uint64_t crc = kmod_module_version_get_crc(l);
288 printf("0x%08"PRIx64"\t%s\n", crc, symbol);
289 }
290 kmod_module_versions_free_list(list);
291 kmod_module_unref(mod);
292 return 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200293}
294
Lucas De Marchi8f192212012-01-11 15:38:50 -0200295static int command_do(struct kmod_module *module, const char *type,
296 const char *command, const char *cmdline_opts)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200297{
298 const char *modname = kmod_module_get_name(module);
299 char *p, *cmd = NULL;
300 size_t cmdlen, cmdline_opts_len, varlen;
301 int ret = 0;
302
303 if (cmdline_opts == NULL)
304 cmdline_opts = "";
305 cmdline_opts_len = strlen(cmdline_opts);
306
307 cmd = strdup(command);
308 if (cmd == NULL)
309 return -ENOMEM;
310 cmdlen = strlen(cmd);
311 varlen = sizeof("$CMDLINE_OPTS") - 1;
312 while ((p = strstr(cmd, "$CMDLINE_OPTS")) != NULL) {
313 size_t prefixlen = p - cmd;
314 size_t suffixlen = cmdlen - prefixlen - varlen;
315 size_t slen = cmdlen - varlen + cmdline_opts_len;
316 char *suffix = p + varlen;
317 char *s = malloc(slen + 1);
318 if (s == NULL) {
319 free(cmd);
320 return -ENOMEM;
321 }
322 memcpy(s, cmd, p - cmd);
323 memcpy(s + prefixlen, cmdline_opts, cmdline_opts_len);
324 memcpy(s + prefixlen + cmdline_opts_len, suffix, suffixlen);
325 s[slen] = '\0';
326
327 free(cmd);
328 cmd = s;
329 cmdlen = slen;
330 }
331
332 SHOW("%s %s\n", type, cmd);
333 if (dry_run)
334 goto end;
335
336 setenv("MODPROBE_MODULE", modname, 1);
337 ret = system(cmd);
338 unsetenv("MODPROBE_MODULE");
339 if (ret == -1 || WEXITSTATUS(ret)) {
340 LOG("Error running %s command for %s\n", type, modname);
341 if (ret != -1)
342 ret = -WEXITSTATUS(ret);
343 }
344
345end:
346 free(cmd);
347 return ret;
348}
349
Lucas De Marchia872bba2012-01-12 15:23:51 -0200350static int rmmod_do_remove_module(struct kmod_module *mod)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200351{
Lucas De Marchia872bba2012-01-12 15:23:51 -0200352 const char *modname = kmod_module_get_name(mod);
Dave Reisner69a19742012-01-30 17:16:50 -0500353 struct kmod_list *deps, *itr;
Lucas De Marchia872bba2012-01-12 15:23:51 -0200354 int flags = 0, err;
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200355
Lucas De Marchia872bba2012-01-12 15:23:51 -0200356 SHOW("rmmod %s\n", kmod_module_get_name(mod));
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200357
Lucas De Marchia872bba2012-01-12 15:23:51 -0200358 if (dry_run)
359 return 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200360
Lucas De Marchia872bba2012-01-12 15:23:51 -0200361 if (force)
362 flags |= KMOD_REMOVE_FORCE;
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200363
Lucas De Marchia872bba2012-01-12 15:23:51 -0200364 err = kmod_module_remove_module(mod, flags);
365 if (err == -EEXIST) {
366 if (!first_time)
367 err = 0;
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200368 else
Lucas De Marchia872bba2012-01-12 15:23:51 -0200369 LOG("Module %s is not in kernel.\n", modname);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200370 }
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200371
Dave Reisner69a19742012-01-30 17:16:50 -0500372 deps = kmod_module_get_dependencies(mod);
373 if (deps != NULL) {
374 kmod_list_foreach(itr, deps) {
375 struct kmod_module *dep = kmod_module_get_module(itr);
376 if (kmod_module_get_refcnt(dep) == 0)
377 rmmod_do_remove_module(dep);
378 kmod_module_unref(dep);
379 }
380 kmod_module_unref_list(deps);
381 }
382
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200383 return err;
384}
385
Lucas De Marchia872bba2012-01-12 15:23:51 -0200386static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies);
387
388static int rmmod_do_deps_list(struct kmod_list *list, bool stop_on_errors)
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200389{
Lucas De Marchia872bba2012-01-12 15:23:51 -0200390 struct kmod_list *l;
391
392 kmod_list_foreach_reverse(l, list) {
393 struct kmod_module *m = kmod_module_get_module(l);
394 int r = rmmod_do_module(m, false);
395 kmod_module_unref(m);
396
397 if (r < 0 && stop_on_errors)
398 return r;
399 }
400
401 return 0;
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200402}
403
Lucas De Marchia872bba2012-01-12 15:23:51 -0200404static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200405{
406 const char *modname = kmod_module_get_name(mod);
Lucas De Marchia872bba2012-01-12 15:23:51 -0200407 struct kmod_list *pre = NULL, *post = NULL;
408 const char *cmd = NULL;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200409 int err;
410
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200411 if (!ignore_commands) {
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200412 err = kmod_module_get_softdeps(mod, &pre, &post);
413 if (err < 0) {
414 WRN("could not get softdeps of '%s': %s\n",
Lucas De Marchi8f192212012-01-11 15:38:50 -0200415 modname, strerror(-err));
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200416 return err;
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200417 }
418
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200419 cmd = kmod_module_get_remove_commands(mod);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200420 }
421
Lucas De Marchia872bba2012-01-12 15:23:51 -0200422 if (cmd == NULL && !ignore_loaded) {
Lucas De Marchi9bf60d22011-12-19 02:18:14 -0200423 int state = kmod_module_get_initstate(mod);
424
Lucas De Marchie5e2a682011-12-19 02:26:34 -0200425 if (state < 0) {
Dave Reisnerf758caf2012-03-14 22:15:21 -0400426 if (first_time) {
427 LOG("Module %s is not in kernel.\n", modname);
428 err = -ENOENT;
429 } else {
430 err = 0;
431 }
Lucas De Marchie4e1e642012-01-12 15:36:54 -0200432 goto error;
Lucas De Marchie5e2a682011-12-19 02:26:34 -0200433 } else if (state == KMOD_MODULE_BUILTIN) {
Lucas De Marchi9bf60d22011-12-19 02:18:14 -0200434 LOG("Module %s is builtin.\n", modname);
Lucas De Marchie4e1e642012-01-12 15:36:54 -0200435 err = -ENOENT;
436 goto error;
Lucas De Marchi9bf60d22011-12-19 02:18:14 -0200437 }
438 }
439
Lucas De Marchia872bba2012-01-12 15:23:51 -0200440 rmmod_do_deps_list(post, false);
441
442 if (do_dependencies && remove_dependencies) {
443 struct kmod_list *deps = kmod_module_get_dependencies(mod);
444
445 err = rmmod_do_deps_list(deps, true);
Lucas De Marchi9bf60d22011-12-19 02:18:14 -0200446 if (err < 0)
Lucas De Marchia872bba2012-01-12 15:23:51 -0200447 goto error;
Lucas De Marchi9bf60d22011-12-19 02:18:14 -0200448 }
449
450 if (!ignore_loaded) {
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200451 int usage = kmod_module_get_refcnt(mod);
Lucas De Marchid8a6c0c2012-01-01 06:07:46 -0200452
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200453 if (usage > 0) {
Lucas De Marchid8a6c0c2012-01-01 06:07:46 -0200454 if (!quiet_inuse)
455 LOG("Module %s is in use.\n", modname);
456
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200457 err = -EBUSY;
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200458 goto error;
459 }
460 }
461
Lucas De Marchia872bba2012-01-12 15:23:51 -0200462 if (cmd == NULL)
463 err = rmmod_do_remove_module(mod);
464 else
465 err = command_do(mod, "remove", cmd, NULL);
Lucas De Marchid8a6c0c2012-01-01 06:07:46 -0200466
Lucas De Marchia872bba2012-01-12 15:23:51 -0200467 if (err < 0)
468 goto error;
Lucas De Marchid8a6c0c2012-01-01 06:07:46 -0200469
Lucas De Marchia872bba2012-01-12 15:23:51 -0200470 rmmod_do_deps_list(pre, false);
Dave Reisner0e9bd2d2011-12-31 18:02:45 -0500471
Gustavo Sverzut Barbierie793f1e2011-12-16 22:35:28 -0200472error:
473 kmod_module_unref_list(pre);
474 kmod_module_unref_list(post);
Lucas De Marchia872bba2012-01-12 15:23:51 -0200475
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200476 return err;
477}
478
Lucas De Marchi569f1602012-01-21 02:45:06 -0200479static int rmmod(struct kmod_ctx *ctx, const char *alias)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200480{
481 struct kmod_list *l, *list = NULL;
482 int err;
483
484 err = kmod_module_new_from_lookup(ctx, alias, &list);
Lucas De Marchie5e2a682011-12-19 02:26:34 -0200485 if (err < 0)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200486 return err;
Lucas De Marchie5e2a682011-12-19 02:26:34 -0200487
Dave Reisnerf758caf2012-03-14 22:15:21 -0400488 if (list == NULL) {
Lucas De Marchie5e2a682011-12-19 02:26:34 -0200489 LOG("Module %s not found.\n", alias);
Dave Reisnerf758caf2012-03-14 22:15:21 -0400490 err = -ENOENT;
491 }
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200492
493 kmod_list_foreach(l, list) {
494 struct kmod_module *mod = kmod_module_get_module(l);
Lucas De Marchia872bba2012-01-12 15:23:51 -0200495 err = rmmod_do_module(mod, true);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200496 kmod_module_unref(mod);
497 if (err < 0)
498 break;
499 }
500
501 kmod_module_unref_list(list);
502 return err;
503}
504
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200505static int rmmod_all(struct kmod_ctx *ctx, char **args, int nargs)
506{
507 int i, err = 0;
508
509 for (i = 0; i < nargs; i++) {
510 int r = rmmod(ctx, args[i]);
511 if (r < 0)
512 err = r;
513 }
514
515 return err;
516}
517
Lucas De Marchi92122612012-01-11 21:48:08 -0200518static int handle_failed_lookup(struct kmod_ctx *ctx, const char *alias)
519{
520 struct kmod_module *mod;
521 int state, err;
522
523 DBG("lookup failed - trying to check if it's builtin\n");
524
525 err = kmod_module_new_from_name(ctx, alias, &mod);
526 if (err < 0)
527 return err;
528
529 state = kmod_module_get_initstate(mod);
530 kmod_module_unref(mod);
531
532 if (state != KMOD_MODULE_BUILTIN) {
533 LOG("Module %s not found.\n", alias);
534 return -ENOENT;
535 }
536
537 if (first_time) {
538 LOG("Module %s already in kernel (builtin).\n", alias);
539 return -ENOENT;
540 }
541
542 SHOW("builtin %s\n", alias);
543 return 0;
544}
545
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200546static void print_action(struct kmod_module *m, bool install,
547 const char *options)
548{
Lucas De Marchi4744ebc2012-03-15 00:14:35 -0300549 const char *path;
550
551 if (install) {
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200552 printf("install %s %s\n", kmod_module_get_install_commands(m),
553 options);
Lucas De Marchi4744ebc2012-03-15 00:14:35 -0300554 return;
555 }
556
557 path = kmod_module_get_path(m);
558
559 if (path == NULL) {
560 assert(kmod_module_get_initstate(m) == KMOD_MODULE_BUILTIN);
561 printf("builtin %s\n", kmod_module_get_name(m));
562 } else
563 printf("insmod %s %s\n", kmod_module_get_path(m), options);
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200564}
565
Lucas De Marchi569f1602012-01-21 02:45:06 -0200566static int insmod(struct kmod_ctx *ctx, const char *alias,
Lucas De Marchi8f192212012-01-11 15:38:50 -0200567 const char *extra_options)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200568{
569 struct kmod_list *l, *list = NULL;
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200570 int err, flags = 0;
571
572 void (*show)(struct kmod_module *m, bool install,
573 const char *options) = NULL;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200574
575 err = kmod_module_new_from_lookup(ctx, alias, &list);
Lucas De Marchie5e2a682011-12-19 02:26:34 -0200576 if (err < 0)
577 return err;
578
Lucas De Marchi92122612012-01-11 21:48:08 -0200579 if (list == NULL)
580 return handle_failed_lookup(ctx, alias);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200581
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200582 if (strip_modversion || force)
583 flags |= KMOD_PROBE_FORCE_MODVERSION;
584 if (strip_vermagic || force)
585 flags |= KMOD_PROBE_FORCE_VERMAGIC;
586 if (ignore_commands)
587 flags |= KMOD_PROBE_IGNORE_COMMAND;
588 if (ignore_loaded)
589 flags |= KMOD_PROBE_IGNORE_LOADED;
590 if (dry_run)
591 flags |= KMOD_PROBE_DRY_RUN;
592 if (do_show || verbose > DEFAULT_VERBOSE)
593 show = &print_action;
594
Lucas De Marchi36ddee62012-08-17 09:42:47 -0300595 flags |= KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY;
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200596
597 if (use_blacklist)
598 flags |= KMOD_PROBE_APPLY_BLACKLIST;
599 if (first_time)
Lucas De Marchi814a57b2012-02-06 12:46:39 -0200600 flags |= KMOD_PROBE_FAIL_ON_LOADED;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200601
602 kmod_list_foreach(l, list) {
603 struct kmod_module *mod = kmod_module_get_module(l);
Lucas De Marchi8b013762012-01-12 17:14:30 -0200604
Lucas De Marchi81229852011-12-16 02:58:48 -0200605 if (lookup_only)
606 printf("%s\n", kmod_module_get_name(mod));
Lucas De Marchi8b013762012-01-12 17:14:30 -0200607 else {
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200608 err = kmod_module_probe_insert_module(mod, flags,
609 extra_options, NULL, NULL, show);
Lucas De Marchi8b013762012-01-12 17:14:30 -0200610 }
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200611
Dave Reisner297a3182012-01-30 20:57:36 -0500612 if (err >= 0)
613 /* ignore flag return values such as a mod being blacklisted */
614 err = 0;
615 else {
616 switch (err) {
617 case -EEXIST:
618 ERR("could not insert '%s': Module already in kernel\n",
619 kmod_module_get_name(mod));
620 break;
Dave Reisnerccb64d12012-04-16 10:37:32 -0400621 case -ENOENT:
622 ERR("could not insert '%s': Unknown symbol in module, "
623 "or unknown parameter (see dmesg)\n",
624 kmod_module_get_name(mod));
625 break;
Dave Reisner297a3182012-01-30 20:57:36 -0500626 default:
627 ERR("could not insert '%s': %s\n",
628 kmod_module_get_name(mod),
629 strerror(-err));
630 break;
631 }
Lucas De Marchi2e9dcd72012-01-30 19:01:24 -0200632 }
633
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200634 kmod_module_unref(mod);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200635 }
636
637 kmod_module_unref_list(list);
638 return err;
639}
640
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200641static int insmod_all(struct kmod_ctx *ctx, char **args, int nargs)
642{
643 int i, err = 0;
644
645 for (i = 0; i < nargs; i++) {
646 int r = insmod(ctx, args[i], NULL);
647 if (r < 0)
648 err = r;
649 }
650
651 return err;
652}
653
654static void env_modprobe_options_append(const char *value)
655{
656 const char *old = getenv("MODPROBE_OPTIONS");
657 char *env;
658
659 if (old == NULL) {
660 setenv("MODPROBE_OPTIONS", value, 1);
661 return;
662 }
663
664 if (asprintf(&env, "%s %s", old, value) < 0) {
665 ERR("could not append value to $MODPROBE_OPTIONS\n");
666 return;
667 }
668
669 if (setenv("MODPROBE_OPTIONS", env, 1) < 0)
670 ERR("could not setenv(MODPROBE_OPTIONS, \"%s\")\n", env);
671 free(env);
672}
673
674static int options_from_array(char **args, int nargs, char **output)
675{
676 char *opts = NULL;
677 size_t optslen = 0;
678 int i, err = 0;
679
680 for (i = 1; i < nargs; i++) {
681 size_t len = strlen(args[i]);
682 size_t qlen = 0;
683 const char *value;
684 void *tmp;
685
686 value = strchr(args[i], '=');
687 if (value) {
688 value++;
689 if (*value != '"' && *value != '\'') {
690 if (strchr(value, ' '))
691 qlen = 2;
692 }
693 }
694
695 tmp = realloc(opts, optslen + len + qlen + 2);
696 if (!tmp) {
697 err = -errno;
698 free(opts);
699 opts = NULL;
700 ERR("could not gather module options: out-of-memory\n");
701 break;
702 }
703 opts = tmp;
704 if (optslen > 0) {
705 opts[optslen] = ' ';
706 optslen++;
707 }
708 if (qlen == 0) {
709 memcpy(opts + optslen, args[i], len + 1);
710 optslen += len;
711 } else {
712 size_t keylen = value - args[i];
713 size_t valuelen = len - keylen;
714 memcpy(opts + optslen, args[i], keylen);
715 optslen += keylen;
716 opts[optslen] = '"';
717 optslen++;
718 memcpy(opts + optslen, value, valuelen);
719 optslen += valuelen;
720 opts[optslen] = '"';
721 optslen++;
722 opts[optslen] = '\0';
723 }
724 }
725
726 *output = opts;
727 return err;
728}
729
730static char **prepend_options_from_env(int *p_argc, char **orig_argv)
731{
732 const char *p, *env = getenv("MODPROBE_OPTIONS");
733 char **new_argv, *str_start, *str_end, *str, *s, *quote;
734 int i, argc = *p_argc;
735 size_t envlen, space_count = 0;
736
737 if (env == NULL)
738 return orig_argv;
739
740 for (p = env; *p != '\0'; p++) {
741 if (*p == ' ')
742 space_count++;
743 }
744
745 envlen = p - env;
746 new_argv = malloc(sizeof(char *) * (argc + space_count + 3 + envlen));
747 if (new_argv == NULL)
748 return NULL;
749
750 new_argv[0] = orig_argv[0];
751 str_start = str = (char *) (new_argv + argc + space_count + 3);
752 memcpy(str, env, envlen + 1);
753
754 str_end = str_start + envlen;
755
756 quote = NULL;
757 for (i = 1, s = str; *s != '\0'; s++) {
758 if (quote == NULL) {
759 if (*s == ' ') {
760 new_argv[i] = str;
761 i++;
762 *s = '\0';
763 str = s + 1;
764 } else if (*s == '"' || *s == '\'')
765 quote = s;
766 } else {
767 if (*s == *quote) {
768 if (quote == str) {
769 new_argv[i] = str + 1;
770 i++;
771 *s = '\0';
772 str = s + 1;
773 } else {
774 char *it;
775 for (it = quote; it < s - 1; it++)
776 it[0] = it[1];
777 for (it = s - 1; it < str_end - 2; it++)
778 it[0] = it[2];
779 str_end -= 2;
780 *str_end = '\0';
781 s -= 2;
782 }
783 quote = NULL;
784 }
785 }
786 }
787 if (str < s) {
788 new_argv[i] = str;
789 i++;
790 }
791
792 memcpy(new_argv + i, orig_argv + 1, sizeof(char *) * (argc - 1));
793 new_argv[i + argc] = NULL;
794 *p_argc = i + argc - 1;
795
796 return new_argv;
797}
798
Lucas De Marchi86cc1f22012-11-01 12:24:58 -0200799static void log_modprobe(void *data, int priority, const char *file, int line,
Lucas De Marchi8f192212012-01-11 15:38:50 -0200800 const char *fn, const char *format, va_list args)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200801{
Lucas De Marchi1e947e32012-10-31 22:00:40 -0200802 const char *prioname = prio_to_str(priority);
Lucas De Marchi86cc1f22012-11-01 12:24:58 -0200803 char *str;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200804
805 if (vasprintf(&str, format, args) < 0)
806 return;
Lucas De Marchi86cc1f22012-11-01 12:24:58 -0200807
808 if (use_syslog) {
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200809#ifdef ENABLE_DEBUG
Lucas De Marchi86cc1f22012-11-01 12:24:58 -0200810 syslog(priority, "%s: %s:%d %s() %s", prioname, file, line,
811 fn, str);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200812#else
Lucas De Marchi86cc1f22012-11-01 12:24:58 -0200813 syslog(priority, "%s: %s", prioname, str);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200814#endif
Lucas De Marchi86cc1f22012-11-01 12:24:58 -0200815 } else {
816#ifdef ENABLE_DEBUG
817 fprintf(stderr, "modprobe: %s: %s:%d %s() %s", prioname, file,
818 line, fn, str);
819#else
820 fprintf(stderr, "modprobe: %s: %s", prioname, str);
821#endif
822 }
823
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200824 free(str);
825 (void)data;
826}
827
Lucas De Marchifa29c0e2011-12-22 03:54:46 -0200828static int do_modprobe(int argc, char **orig_argv)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200829{
830 struct kmod_ctx *ctx;
831 char **args = NULL, **argv;
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200832 const char **config_paths = NULL;
833 int nargs = 0, n_config_paths = 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200834 char dirname_buf[PATH_MAX];
835 const char *dirname = NULL;
836 const char *root = NULL;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200837 const char *kversion = NULL;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200838 int use_all = 0;
839 int do_remove = 0;
840 int do_show_config = 0;
841 int do_show_modversions = 0;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200842 int err;
843
844 argv = prepend_options_from_env(&argc, orig_argv);
845 if (argv == NULL) {
846 fputs("Error: could not prepend options from command line\n",
847 stderr);
848 return EXIT_FAILURE;
849 }
850
851 for (;;) {
852 int c, idx = 0;
853 c = getopt_long(argc, argv, cmdopts_s, cmdopts, &idx);
854 if (c == -1)
855 break;
856 switch (c) {
857 case 'a':
858 log_priority = LOG_WARNING;
859 use_all = 1;
860 break;
861 case 'r':
862 do_remove = 1;
863 break;
864 case 5:
865 remove_dependencies = 1;
866 break;
867 case 'R':
Lucas De Marchi81229852011-12-16 02:58:48 -0200868 lookup_only = 1;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200869 break;
870 case 3:
871 first_time = 1;
872 break;
873 case 'i':
874 ignore_commands = 1;
875 break;
876 case 'b':
877 use_blacklist = 1;
878 break;
879 case 'f':
880 force = 1;
881 break;
882 case 2:
883 strip_modversion = 1;
884 break;
885 case 1:
886 strip_vermagic = 1;
887 break;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200888 case 'D':
889 ignore_loaded = 1;
890 dry_run = 1;
Gustavo Sverzut Barbieri525fa072012-01-08 13:58:28 -0200891 do_show = 1;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200892 break;
893 case 'c':
894 do_show_config = 1;
895 break;
896 case 4:
897 do_show_modversions = 1;
898 break;
899 case 'n':
900 dry_run = 1;
901 break;
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200902 case 'C': {
903 size_t bytes = sizeof(char *) * (n_config_paths + 2);
904 void *tmp = realloc(config_paths, bytes);
905 if (!tmp) {
906 fputs("Error: out-of-memory\n", stderr);
907 goto cmdline_failed;
908 }
909 config_paths = tmp;
910 config_paths[n_config_paths] = optarg;
911 n_config_paths++;
912 config_paths[n_config_paths] = NULL;
913
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200914 env_modprobe_options_append("-C");
915 env_modprobe_options_append(optarg);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200916 break;
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200917 }
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200918 case 'd':
919 root = optarg;
920 break;
921 case 'S':
922 kversion = optarg;
923 break;
924 case 's':
925 env_modprobe_options_append("-s");
926 use_syslog = 1;
927 break;
928 case 'q':
929 env_modprobe_options_append("-q");
Lucas De Marchiae7ebe82012-03-15 01:11:10 -0300930 verbose = LOG_EMERG;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200931 break;
932 case 'v':
933 env_modprobe_options_append("-v");
934 verbose++;
935 break;
936 case 'V':
937 puts(PACKAGE " version " VERSION);
Lucas De Marchi4434d8b2012-10-31 21:29:54 -0200938 err = EXIT_SUCCESS;
939 goto done;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200940 case 'h':
Lucas De Marchi3e8de632011-12-23 01:36:10 -0200941 help(basename(argv[0]));
Lucas De Marchi4434d8b2012-10-31 21:29:54 -0200942 err = EXIT_SUCCESS;
943 goto done;
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200944 case '?':
945 goto cmdline_failed;
946 default:
Lucas De Marchi8f192212012-01-11 15:38:50 -0200947 fprintf(stderr, "Error: unexpected getopt_long() value '%c'.\n",
948 c);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200949 goto cmdline_failed;
950 }
951 }
952
953 args = argv + optind;
954 nargs = argc - optind;
955
Dave Reisnerb09668c2011-12-31 16:51:40 -0500956 if (!do_show_config) {
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200957 if (nargs == 0) {
958 fputs("Error: missing parameters. See -h.\n", stderr);
959 goto cmdline_failed;
960 }
961 }
962
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200963 if (root != NULL || kversion != NULL) {
964 struct utsname u;
965 if (root == NULL)
966 root = "";
967 if (kversion == NULL) {
968 if (uname(&u) < 0) {
969 fprintf(stderr, "Error: uname() failed: %s\n",
970 strerror(errno));
971 goto cmdline_failed;
972 }
973 kversion = u.release;
974 }
Lucas De Marchi8f192212012-01-11 15:38:50 -0200975 snprintf(dirname_buf, sizeof(dirname_buf),
Dave Reisnerc5b37db2012-09-27 11:00:42 -0400976 "%s/lib/modules/%s", root,
Lucas De Marchi8f192212012-01-11 15:38:50 -0200977 kversion);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200978 dirname = dirname_buf;
979 }
980
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200981 ctx = kmod_new(dirname, config_paths);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200982 if (!ctx) {
983 fputs("Error: kmod_new() failed!\n", stderr);
984 goto cmdline_failed;
985 }
986 kmod_load_resources(ctx);
987
988 kmod_set_log_priority(ctx, verbose);
Lucas De Marchi86cc1f22012-11-01 12:24:58 -0200989 kmod_set_log_fn(ctx, log_modprobe, NULL);
990 if (use_syslog)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200991 openlog("modprobe", LOG_CONS, LOG_DAEMON);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200992
Dave Reisnerb09668c2011-12-31 16:51:40 -0500993 if (do_show_config)
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200994 err = show_config(ctx);
995 else if (do_show_modversions)
996 err = show_modversions(ctx, args[0]);
997 else if (do_remove)
Lucas De Marchic1b84542012-03-15 00:27:18 -0300998 err = rmmod_all(ctx, args, nargs);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -0200999 else if (use_all)
1000 err = insmod_all(ctx, args, nargs);
1001 else {
1002 char *opts;
1003 err = options_from_array(args, nargs, &opts);
1004 if (err == 0) {
1005 err = insmod(ctx, args[0], opts);
1006 free(opts);
1007 }
1008 }
1009
1010 kmod_unref(ctx);
1011
1012 if (use_syslog)
1013 closelog();
1014
Lucas De Marchi4434d8b2012-10-31 21:29:54 -02001015done:
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -02001016 if (argv != orig_argv)
1017 free(argv);
Lucas De Marchi8f192212012-01-11 15:38:50 -02001018
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -02001019 free(config_paths);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -02001020 return err >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
1021
1022cmdline_failed:
1023 if (argv != orig_argv)
1024 free(argv);
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -02001025 free(config_paths);
Gustavo Sverzut Barbieric3d0a5f2011-12-11 19:36:18 -02001026 return EXIT_FAILURE;
1027}
Lucas De Marchifa29c0e2011-12-22 03:54:46 -02001028
Lucas De Marchifa29c0e2011-12-22 03:54:46 -02001029#include "kmod.h"
1030
1031const struct kmod_cmd kmod_cmd_compat_modprobe = {
1032 .name = "modprobe",
1033 .cmd = do_modprobe,
1034 .help = "compat modprobe command",
1035};