From 3a9241add947cb6d24b5de7a8927517426a78795 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 25 Aug 2012 14:25:22 -0500 Subject: Move commands into "posix", "lsb", and "other" menus/directories. --- toys/other/lsmod.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 toys/other/lsmod.c (limited to 'toys/other/lsmod.c') diff --git a/toys/other/lsmod.c b/toys/other/lsmod.c new file mode 100644 index 00000000..82dbb589 --- /dev/null +++ b/toys/other/lsmod.c @@ -0,0 +1,42 @@ +/* vi: set sw=4 ts=4: + * + * lsmod.c - Show the status of modules in the kernel + * + * Copyright 2012 Elie De Brauwer + * + * Not in SUSv4. + +USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_BIN)) + +config LSMOD + bool "lsmod" + default y + help + usage: lsmod + + Display the currently loaded modules, their sizes and their + dependencies. +*/ + +#include "toys.h" + +void lsmod_main(void) +{ + char *modfile = "/proc/modules"; + FILE * file = xfopen(modfile, "r"); + + xprintf("%-23s Size Used by\n", "Module"); + + while (fgets(toybuf, sizeof(toybuf), file)) { + char *name = strtok(toybuf, " "), *size = strtok(NULL, " "), + *refcnt = strtok(NULL, " "), *users = strtok(NULL, " "); + + if(users) { + int len = strlen(users)-1; + if (users[len] == ',' || users[len] == '-') + users[len] = 0; + xprintf("%-19s %8s %s %s\n", name, size, refcnt, users); + } else perror_exit("bad %s", modfile); + } + fclose(file); +} -- cgit v1.2.3