Mercurial > hg > toybox
annotate toys/other/lsmod.c @ 656:6df4ccc0acbe
Regularize command headers, update links to standards documents.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 18:08:51 -0500 |
parents | 2986aa63a021 |
children | 786841fdb1e0 |
rev | line source |
---|---|
485 | 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 | |
486
43be4ef80ffe
Minor cleanups: lsmod should USE_LSMOD() instead of USE_FREE(), use consistent tab/space idents, and doesn't need a break after a function that exits.
Rob Landley <rob@landley.net>
parents:
485
diff
changeset
|
7 USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_BIN)) |
485 | 8 |
9 config LSMOD | |
10 bool "lsmod" | |
11 default y | |
12 help | |
13 usage: lsmod | |
14 | |
15 Display the currently loaded modules, their sizes and their | |
16 dependencies. | |
17 */ | |
18 | |
19 #include "toys.h" | |
20 | |
21 void lsmod_main(void) | |
22 { | |
632 | 23 char *modfile = "/proc/modules"; |
24 FILE * file = xfopen(modfile, "r"); | |
486
43be4ef80ffe
Minor cleanups: lsmod should USE_LSMOD() instead of USE_FREE(), use consistent tab/space idents, and doesn't need a break after a function that exits.
Rob Landley <rob@landley.net>
parents:
485
diff
changeset
|
25 |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
26 xprintf("%-23s Size Used by\n", "Module"); |
485 | 27 |
486
43be4ef80ffe
Minor cleanups: lsmod should USE_LSMOD() instead of USE_FREE(), use consistent tab/space idents, and doesn't need a break after a function that exits.
Rob Landley <rob@landley.net>
parents:
485
diff
changeset
|
28 while (fgets(toybuf, sizeof(toybuf), file)) { |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
29 char *name = strtok(toybuf, " "), *size = strtok(NULL, " "), |
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
30 *refcnt = strtok(NULL, " "), *users = strtok(NULL, " "); |
485 | 31 |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
32 if(users) { |
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
33 int len = strlen(users)-1; |
485 | 34 if (users[len] == ',' || users[len] == '-') |
35 users[len] = 0; | |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
36 xprintf("%-19s %8s %s %s\n", name, size, refcnt, users); |
632 | 37 } else perror_exit("bad %s", modfile); |
485 | 38 } |
39 fclose(file); | |
40 } |