2000-02-08 19:58:47 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-12-16 23:04:20 +00:00
|
|
|
/*
|
|
|
|
* Mini rmmod implementation for busybox
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2008-09-13 14:59:38 +00:00
|
|
|
* Copyright (C) 2008 Timo Teras <timo.teras@iki.fi>
|
1999-12-16 23:04:20 +00:00
|
|
|
*
|
2006-06-03 19:35:15 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
1999-12-16 23:04:20 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2008-09-13 14:59:38 +00:00
|
|
|
#include "modutils.h"
|
2006-08-28 19:40:08 +00:00
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int rmmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-09-13 14:59:38 +00:00
|
|
|
int rmmod_main(int argc UNUSED_PARAM, char **argv)
|
1999-12-16 23:04:20 +00:00
|
|
|
{
|
2008-09-13 14:59:38 +00:00
|
|
|
int n;
|
2004-07-13 00:09:34 +00:00
|
|
|
unsigned int flags = O_NONBLOCK|O_EXCL;
|
1999-12-16 23:04:20 +00:00
|
|
|
|
2001-03-09 21:49:12 +00:00
|
|
|
/* Parse command line. */
|
2008-09-13 14:59:38 +00:00
|
|
|
n = getopt32(argv, "wfas"); // -s ignored
|
|
|
|
argv += optind;
|
|
|
|
|
2007-04-12 00:32:05 +00:00
|
|
|
if (n & 1) // --wait
|
2005-11-28 15:54:22 +00:00
|
|
|
flags &= ~O_NONBLOCK;
|
2007-04-12 00:32:05 +00:00
|
|
|
if (n & 2) // --force
|
2005-11-28 15:54:22 +00:00
|
|
|
flags |= O_TRUNC;
|
2007-04-12 00:32:05 +00:00
|
|
|
if (n & 4) {
|
2005-11-28 15:54:22 +00:00
|
|
|
/* Unload _all_ unused modules via NULL delete_module() call */
|
2008-09-13 14:59:38 +00:00
|
|
|
if (bb_delete_module(NULL, flags) != 0 && errno != EFAULT)
|
|
|
|
bb_perror_msg_and_die("rmmod");
|
2005-11-28 15:54:22 +00:00
|
|
|
return EXIT_SUCCESS;
|
1999-12-16 23:04:20 +00:00
|
|
|
}
|
|
|
|
|
2008-09-13 14:59:38 +00:00
|
|
|
if (!*argv)
|
2003-12-24 20:30:45 +00:00
|
|
|
bb_show_usage();
|
2001-03-09 21:49:12 +00:00
|
|
|
|
2008-09-13 14:59:38 +00:00
|
|
|
while (*argv) {
|
|
|
|
char modname[MODULE_NAME_LEN];
|
|
|
|
filename2modname(bb_basename(*argv++), modname);
|
|
|
|
if (bb_delete_module(modname, flags))
|
|
|
|
bb_error_msg_and_die("cannot unload '%s': %s",
|
|
|
|
modname, moderror(errno));
|
1999-12-16 23:04:20 +00:00
|
|
|
}
|
2001-03-09 21:49:12 +00:00
|
|
|
|
2008-09-13 14:59:38 +00:00
|
|
|
return EXIT_SUCCESS;
|
1999-12-16 23:04:20 +00:00
|
|
|
}
|