rmmod.c - ubase - suckless linux base utils | |
git clone git://git.suckless.org/ubase | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
rmmod.c (754B) | |
--- | |
1 /* See LICENSE file for copyright and license details. */ | |
2 #include <sys/syscall.h> | |
3 | |
4 #include <fcntl.h> | |
5 #include <libgen.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <unistd.h> | |
10 | |
11 #include "util.h" | |
12 | |
13 static void | |
14 usage(void) | |
15 { | |
16 eprintf("usage: %s [-fw] module...\n", argv0); | |
17 } | |
18 | |
19 int | |
20 main(int argc, char *argv[]) | |
21 { | |
22 char *mod, *p; | |
23 int i; | |
24 int flags = O_NONBLOCK; | |
25 | |
26 ARGBEGIN { | |
27 case 'f': | |
28 flags |= O_TRUNC; | |
29 break; | |
30 case 'w': | |
31 flags &= ~O_NONBLOCK; | |
32 break; | |
33 default: | |
34 usage(); | |
35 } ARGEND; | |
36 | |
37 if (argc < 1) | |
38 usage(); | |
39 | |
40 for (i = 0; i < argc; i++) { | |
41 mod = argv[i]; | |
42 p = strrchr(mod, '.'); | |
43 if (p && !strcmp(p, ".ko")) | |
44 *p = '\0'; | |
45 if (syscall(__NR_delete_module, mod, flags) < 0) | |
46 eprintf("delete_module:"); | |
47 } | |
48 | |
49 return 0; | |
50 } |