aboutsummaryrefslogtreecommitdiff
path: root/toys/lsmod.c
diff options
context:
space:
mode:
authorElie De Brauwer <eliedebrauwer@gmail.com>2012-02-18 09:44:53 +0100
committerElie De Brauwer <eliedebrauwer@gmail.com>2012-02-18 09:44:53 +0100
commit9e59c272039097a92cc11a8f248be9b5552b30c7 (patch)
tree490453e472d85f39d0fb1e3a31153ec636d3a6ee /toys/lsmod.c
parentfcf188ffdba160303c1e8e59819239d3bf9f31ad (diff)
downloadtoybox-9e59c272039097a92cc11a8f248be9b5552b30c7.tar.gz
Adding lsmod
Diffstat (limited to 'toys/lsmod.c')
-rw-r--r--toys/lsmod.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/toys/lsmod.c b/toys/lsmod.c
new file mode 100644
index 00000000..7f588c8a
--- /dev/null
+++ b/toys/lsmod.c
@@ -0,0 +1,49 @@
+/* vi: set sw=4 ts=4:
+ *
+ * lsmod.c - Show the status of modules in the kernel
+ *
+ * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
+ *
+ * Not in SUSv4.
+
+USE_FREE(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)
+{
+ FILE * file = fopen("/proc/modules", "r");
+ char *name, *size, *refcnt, *users;
+ if (!file)
+ perror_exit("cannot open /proc/moduls");
+
+ xprintf("%-24s Size Used by\n", "Module");
+
+ while (fgets(toybuf, sizeof(toybuf), file)) {
+ int len;
+ name = strtok(toybuf, " ");
+ size = strtok(NULL, " ");
+ refcnt = strtok(NULL, " ");
+ users = strtok(NULL, " ");
+ if(name && size && refcnt && users) {
+ len = strlen(users)-1;
+ if (users[len] == ',' || users[len] == '-')
+ users[len] = 0;
+ xprintf("%-20s %8s %s %s\n", name, size, refcnt, users);
+ } else {
+ perror_exit("unrecognized input");
+ break;
+ }
+ }
+ fclose(file);
+}