commit 03a234e7f939dd356cc220ad31fd378d3219d4fe
parent 5da030ecec26d4bf4f92ee3320a252148a0d314e
Author: sin <sin@2f30.org>
Date: Fri, 9 Aug 2013 09:42:34 +0100
Add rmmod(8)
No manpage yet.
Diffstat:
M | Makefile | | | 3 | ++- |
A | rmmod.c | | | 47 | +++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -18,7 +18,8 @@ SRC = \
ifeq ($(OS),linux)
SRC += \
- insmod.c
+ insmod.c \
+ rmmod.c
endif
OBJ = $(SRC:.c=.o) $(LIB)
diff --git a/rmmod.c b/rmmod.c
@@ -0,0 +1,47 @@
+/* See LICENSE file for copyright and license details. */
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <libgen.h>
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [-fw] modulename...\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *mod, *p;
+ int i;
+ int flags = O_NONBLOCK;
+
+ ARGBEGIN {
+ case 'f':
+ flags |= O_TRUNC;
+ break;
+ case 'w':
+ flags &= ~O_NONBLOCK;
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc < 1)
+ usage();
+
+ for (i = 0; i < argc; i++) {
+ mod = argv[i];
+ p = strrchr(mod, '.');
+ if (strlen(p) == 3 && !strcmp(p, ".ko"))
+ *p = '\0';
+ if (syscall(__NR_delete_module, mod, flags) < 0)
+ eprintf("delete_module:");
+ }
+
+ return 0;
+}