source: MondoRescue/branches/2.2.9/mindi-busybox/modutils/rmmod.c@ 2725

Last change on this file since 2725 was 2725, checked in by Bruno Cornec, 13 years ago
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File size: 1.8 KB
RevLine 
[821]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>
[2725]6 * Copyright (C) 2008 Timo Teras <timo.teras@iki.fi>
[821]7 *
[2725]8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
[821]9 */
10
[2725]11//applet:IF_RMMOD(APPLET(rmmod, _BB_DIR_SBIN, _BB_SUID_DROP))
[821]12
[2725]13//usage:#if !ENABLE_MODPROBE_SMALL
14//usage:#define rmmod_trivial_usage
15//usage: "[-wfa] [MODULE]..."
16//usage:#define rmmod_full_usage "\n\n"
17//usage: "Unload kernel modules\n"
18//usage: "\nOptions:"
19//usage: "\n -w Wait until the module is no longer used"
20//usage: "\n -f Force unload"
21//usage: "\n -a Remove all unused modules (recursively)"
22//usage:#define rmmod_example_usage
23//usage: "$ rmmod tulip\n"
24//usage:#endif
[821]25
[2725]26#include "libbb.h"
27#include "modutils.h"
[1765]28
[2725]29int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
30int rmmod_main(int argc UNUSED_PARAM, char **argv)
[821]31{
[2725]32 int n;
33 unsigned flags = O_NONBLOCK | O_EXCL;
[821]34
35 /* Parse command line. */
[2725]36 n = getopt32(argv, "wfas"); // -s ignored
37 argv += optind;
38 if (n & 1) // --wait
[821]39 flags &= ~O_NONBLOCK;
[2725]40 if (n & 2) // --force
[821]41 flags |= O_TRUNC;
[1765]42 if (n & 4) {
[821]43 /* Unload _all_ unused modules via NULL delete_module() call */
[2725]44 if (bb_delete_module(NULL, flags) != 0 && errno != EFAULT)
45 bb_perror_msg_and_die("rmmod");
[821]46 return EXIT_SUCCESS;
47 }
48
[2725]49 if (!*argv)
[821]50 bb_show_usage();
51
[2725]52 n = ENABLE_FEATURE_2_4_MODULES && get_linux_version_code() < KERNEL_VERSION(2,6,0);
53 while (*argv) {
54 char modname[MODULE_NAME_LEN];
55 const char *bname;
[821]56
[2725]57 bname = bb_basename(*argv++);
58 if (n)
59 safe_strncpy(modname, bname, MODULE_NAME_LEN);
60 else
61 filename2modname(bname, modname);
62 if (bb_delete_module(modname, flags))
63 bb_error_msg_and_die("can't unload '%s': %s",
64 modname, moderror(errno));
[821]65 }
66
[2725]67 return EXIT_SUCCESS;
[821]68}
Note: See TracBrowser for help on using the repository browser.