blob: 7e10c061b70c68de601ccece10a663ce88bc88fc [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001#include <stdio.h>
2#include <string.h>
3#include <fcntl.h>
4#include <unistd.h>
5#include <malloc.h>
6#include <errno.h>
7#include <asm/unistd.h>
8
9extern int delete_module(const char *, unsigned int);
10
11int rmmod_main(int argc, char **argv)
12{
13 int ret;
14 char *modname, *dot;
15
16 /* make sure we've got an argument */
17 if (argc < 2) {
18 fprintf(stderr, "usage: rmmod <module>\n");
19 return -1;
20 }
21
22 /* if given /foo/bar/blah.ko, make a weak attempt
23 * to convert to "blah", just for convenience
24 */
25 modname = strrchr(argv[1], '/');
26 if (!modname)
27 modname = argv[1];
28 dot = strchr(argv[1], '.');
29 if (dot)
30 *dot = '\0';
31
32 /* pass it to the kernel */
33 ret = delete_module(modname, O_NONBLOCK | O_EXCL);
34 if (ret != 0) {
35 fprintf(stderr, "rmmod: delete_module '%s' failed (errno %d)\n",
36 modname, errno);
37 return -1;
38 }
39
40 return 0;
41}
42