blob: dd293523d675b04ed6a9662b36ebfeefe8594023 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Erik Andersen3d7e3411999-12-16 23:04:20 +00002/*
3 * Mini rmmod implementation for busybox
4 *
Erik Andersen61677fe2000-04-13 01:18:56 +00005 * Copyright (C) 1999,2000 by Lineo, inc.
Erik Andersen3d7e3411999-12-16 23:04:20 +00006 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
Eric Andersen3570a342000-09-25 21:45:58 +000024#include "busybox.h"
Erik Andersen3d7e3411999-12-16 23:04:20 +000025#include <stdio.h>
26#include <errno.h>
27#include <unistd.h>
Erik Andersen1d1d9502000-04-21 01:26:49 +000028#define __LIBRARY__
Erik Andersen3d7e3411999-12-16 23:04:20 +000029
30
31
32/* And the system call of the day is... */
Erik Andersen6da0ae81999-12-17 01:08:27 +000033_syscall1(int, delete_module, const char *, name)
Erik Andersen3d7e3411999-12-16 23:04:20 +000034
Erik Andersen3d7e3411999-12-16 23:04:20 +000035extern int rmmod_main(int argc, char **argv)
36{
Eric Andersena5716d32000-07-28 15:16:37 +000037 int ret = TRUE;
Erik Andersene49d5ec2000-02-08 19:58:47 +000038 if (argc <= 1) {
Erik Andersen3d7e3411999-12-16 23:04:20 +000039 usage(rmmod_usage);
Erik Andersen3d7e3411999-12-16 23:04:20 +000040 }
Erik Andersen3d7e3411999-12-16 23:04:20 +000041
Erik Andersene49d5ec2000-02-08 19:58:47 +000042 /* Parse any options */
43 while (--argc > 0 && **(++argv) == '-') {
44 while (*(++(*argv))) {
45 switch (**argv) {
46 case 'a':
47 /* Unload _all_ unused modules via NULL delete_module() call */
48 if (delete_module(NULL)) {
49 perror("rmmod");
50 exit(FALSE);
51 }
52 exit(TRUE);
53 default:
54 usage(rmmod_usage);
55 }
56 }
Erik Andersen3d7e3411999-12-16 23:04:20 +000057 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000058
59 while (argc-- > 0) {
60 if (delete_module(*argv) < 0) {
61 perror(*argv);
Eric Andersena5716d32000-07-28 15:16:37 +000062 ret=FALSE;
Erik Andersene49d5ec2000-02-08 19:58:47 +000063 }
64 argv++;
65 }
Eric Andersena5716d32000-07-28 15:16:37 +000066 return(ret);
Erik Andersen3d7e3411999-12-16 23:04:20 +000067}