blob: 25257cc393de2b0f55dbdaadc24c9b09ece0c278 [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];
Tanguy Pruvotec4db512011-09-01 13:16:18 +020028 else modname++;
29
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080030 dot = strchr(argv[1], '.');
31 if (dot)
32 *dot = '\0';
33
34 /* pass it to the kernel */
35 ret = delete_module(modname, O_NONBLOCK | O_EXCL);
36 if (ret != 0) {
37 fprintf(stderr, "rmmod: delete_module '%s' failed (errno %d)\n",
38 modname, errno);
39 return -1;
40 }
41
42 return 0;
43}
44