Mercurial > hg > toybox
annotate toys/lsmod.c @ 562:4d802d438983
Match uint64_t with PRIu64 to avoid warnings on 64 bit builds.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 14 Apr 2012 21:27:00 -0500 |
parents | 9c43d4191337 |
children | 6cafecf34728 |
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 |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
27 xprintf("%-23s Size Used by\n", "Module"); |
485 | 28 |
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
|
29 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
|
30 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
|
31 *refcnt = strtok(NULL, " "), *users = strtok(NULL, " "); |
485 | 32 |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
33 if(users) { |
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
34 int len = strlen(users)-1; |
485 | 35 if (users[len] == ',' || users[len] == '-') |
36 users[len] = 0; | |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
37 xprintf("%-19s %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
|
38 } else perror_exit("unrecognized input"); |
485 | 39 } |
40 fclose(file); | |
41 } |