1 /* vi: set sw=4 ts=4: */
3 * Mini rmmod implementation for busybox
5 * Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 extern int delete_module(const char * name);
33 extern int rmmod_main(int argc, char **argv)
35 int n, ret = EXIT_SUCCESS;
36 size_t nmod = 0; /* number of modules */
37 size_t pnmod = -1; /* previous number of modules */
38 void *buf; /* hold the module names which we ignore but must get */
41 /* Parse command line. */
42 while ((n = getopt(argc, argv, "a")) != EOF) {
45 /* Unload _all_ unused modules via NULL delete_module() call */
46 /* until the number of modules does not change */
47 buf = xmalloc(bufsize = 256);
48 while (nmod != pnmod) {
49 if (delete_module(NULL))
50 bb_perror_msg_and_die("rmmod");
53 if (my_query_module(NULL, 1, &buf, &bufsize, &nmod)) {
54 bb_perror_msg_and_die("QM_MODULES");
57 #ifdef CONFIG_FEATURE_CLEAN_UP
69 for (n = optind; n < argc; n++) {
70 if (delete_module(argv[n]) < 0) {
71 bb_perror_msg("%s", argv[n]);