Mercurial > hg > toybox
annotate toys/lsmod.c @ 649:2364ace48ab1
Bugfix from Avery Pennarun: getpriority() uses a different range than nice(), so follow thenice man page and zero errno then check it if nice returns -1.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 16 Aug 2012 22:24:30 -0500 |
parents | 6cafecf34728 |
children |
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 { | |
632 | 25 char *modfile = "/proc/modules"; |
26 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
|
27 |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
28 xprintf("%-23s 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)) { |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
31 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
|
32 *refcnt = strtok(NULL, " "), *users = strtok(NULL, " "); |
485 | 33 |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
34 if(users) { |
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
35 int len = strlen(users)-1; |
485 | 36 if (users[len] == ',' || users[len] == '-') |
37 users[len] = 0; | |
487
9c43d4191337
Tighten up the source code in largely cosmetic ways.
Rob Landley <rob@landley.net>
parents:
486
diff
changeset
|
38 xprintf("%-19s %8s %s %s\n", name, size, refcnt, users); |
632 | 39 } else perror_exit("bad %s", modfile); |
485 | 40 } |
41 fclose(file); | |
42 } |