Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/modutils/rmmod.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 816 - (show annotations) (download)
Fri Apr 24 18:33:46 2009 UTC (15 years, 1 month ago) by niro
File MIME type: text/plain
File size: 1158 byte(s)
-updated to busybox-1.13.4
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Mini rmmod implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi>
7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */
10
11 #include "libbb.h"
12 #include "modutils.h"
13
14 int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15 int rmmod_main(int argc UNUSED_PARAM, char **argv)
16 {
17 int n;
18 unsigned int flags = O_NONBLOCK|O_EXCL;
19
20 /* Parse command line. */
21 n = getopt32(argv, "wfas"); // -s ignored
22 argv += optind;
23
24 if (n & 1) // --wait
25 flags &= ~O_NONBLOCK;
26 if (n & 2) // --force
27 flags |= O_TRUNC;
28 if (n & 4) {
29 /* Unload _all_ unused modules via NULL delete_module() call */
30 if (bb_delete_module(NULL, flags) != 0 && errno != EFAULT)
31 bb_perror_msg_and_die("rmmod");
32 return EXIT_SUCCESS;
33 }
34
35 if (!*argv)
36 bb_show_usage();
37
38 while (*argv) {
39 char modname[MODULE_NAME_LEN];
40 filename2modname(bb_basename(*argv++), modname);
41 if (bb_delete_module(modname, flags))
42 bb_error_msg_and_die("cannot unload '%s': %s",
43 modname, moderror(errno));
44 }
45
46 return EXIT_SUCCESS;
47 }