Mercurial > hg > toybox
annotate toys/lsmod.c @ 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.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 20 Feb 2012 20:20:12 -0600 |
parents | d5d51fd18679 |
children | 9c43d4191337 |
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 * | |
7 * Not in SUSv4. | |
8 | |
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
|
9 USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_BIN)) |
485 | 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 { | |
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 FILE * file = xfopen("/proc/modules", "r"); |
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
|
26 char *name, *size, *refcnt, *users; |
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
|
27 |
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 xprintf("%-24s Size Used by\n", "Module"); |
485 | 29 |
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
|
30 while (fgets(toybuf, sizeof(toybuf), file)) { |
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
|
31 int len; |
485 | 32 |
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
|
33 name = strtok(toybuf, " "); |
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
|
34 size = strtok(NULL, " "); |
485 | 35 refcnt = strtok(NULL, " "); |
36 users = strtok(NULL, " "); | |
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
|
37 |
485 | 38 if(name && size && refcnt && users) { |
39 len = strlen(users)-1; | |
40 if (users[len] == ',' || users[len] == '-') | |
41 users[len] = 0; | |
42 xprintf("%-20s %8s %s %s\n", name, size, refcnt, users); | |
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
|
43 } else perror_exit("unrecognized input"); |
485 | 44 } |
45 fclose(file); | |
46 } |