From f2c131bc5294d0531edb3486874f37019b0b1413 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 7 May 2023 14:36:49 +0200 Subject: added a simple rmmod --- Makefile | 3 ++- README | 5 ++--- rmmod.1 | 15 +++++++++++++++ rmmod.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 rmmod.1 create mode 100644 rmmod.c diff --git a/Makefile b/Makefile index 83f8a68..8d6fe49 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,8 @@ BIN =\ more\ hexdump\ ifconfig\ - ping + ping\ + rmmod LIBUTILOBJ = $(LIBUTILSRC:.c=.o) OBJ = $(BIN:=.o) $(LIBUTFOBJ) $(LIBUTILOBJ) diff --git a/README b/README index 5745cd1..e53ed1c 100644 --- a/README +++ b/README @@ -11,11 +11,10 @@ Currently it contains the following: - a 'ifconfig': show and configure simple interfaces - a 'ping': test a network connection - a 'netstat': see list of active connections of a machine -- a 'mkswap': swapon/swapoff exist, so we should also be able to create - a swap +- a 'mkswap': swapon/swapoff/swaplabel exist, so we should also be able + to create a swap - 'fsck.ext4', 'mkfs.ext4': if ext4 is the only file system we support - 'nbd-client': for NBD root mounts -- 'rmmod': 'insmod/lsmod' exists in ubase, removing is important to play with hardware. dependencies can also be done from the text modules.dep file and a samurai or simplistic make, 'modprobe' as shell wrapper on dependencies and insmod calls diff --git a/rmmod.1 b/rmmod.1 new file mode 100644 index 0000000..3c526da --- /dev/null +++ b/rmmod.1 @@ -0,0 +1,15 @@ +.Dd 2023-05-07 +.Dt RMMID 1 +.Os abase +.Sh NAME +.Nm rmmid +.Nd remove module for the Linux kernl +.Sh SYNOPSIS +.Nm +{module} +.Sh DESCRIPTION +.Nm +Removes a loaded Linux kernel module named +.Ar module +.RE + diff --git a/rmmod.c b/rmmod.c new file mode 100644 index 0000000..e0545d3 --- /dev/null +++ b/rmmod.c @@ -0,0 +1,34 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include + +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s \n", argv0); +} + +int +main(int argc, char *argv[]) +{ + char *module; + + ARGBEGIN { + default: + usage(); + } ARGEND + + if (argc != 1) { + weprintf("Expecting exactly one 'module' to remove\n"); + usage(); + } + module = argv[0]; + + if (syscall(__NR_delete_module, module, O_NONBLOCK) < 0) + eprintf("delete_module:"); + + return 0; +} -- cgit v1.2.3-54-g00ecf