comparison toys/other/lsmod.c @ 653:2986aa63a021

Move commands into "posix", "lsb", and "other" menus/directories.
author Rob Landley <rob@landley.net>
date Sat, 25 Aug 2012 14:25:22 -0500
parents toys/lsmod.c@6cafecf34728
children 6df4ccc0acbe
comparison
equal deleted inserted replaced
652:2d7c56913fda 653:2986aa63a021
1 /* vi: set sw=4 ts=4:
2 *
3 * lsmod.c - Show the status of modules in the kernel
4 *
5 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
6 *
7 * Not in SUSv4.
8
9 USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_BIN))
10
11 config LSMOD
12 bool "lsmod"
13 default y
14 help
15 usage: lsmod
16
17 Display the currently loaded modules, their sizes and their
18 dependencies.
19 */
20
21 #include "toys.h"
22
23 void lsmod_main(void)
24 {
25 char *modfile = "/proc/modules";
26 FILE * file = xfopen(modfile, "r");
27
28 xprintf("%-23s Size Used by\n", "Module");
29
30 while (fgets(toybuf, sizeof(toybuf), file)) {
31 char *name = strtok(toybuf, " "), *size = strtok(NULL, " "),
32 *refcnt = strtok(NULL, " "), *users = strtok(NULL, " ");
33
34 if(users) {
35 int len = strlen(users)-1;
36 if (users[len] == ',' || users[len] == '-')
37 users[len] = 0;
38 xprintf("%-19s %8s %s %s\n", name, size, refcnt, users);
39 } else perror_exit("bad %s", modfile);
40 }
41 fclose(file);
42 }