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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
485
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
1 /* vi: set sw=4 ts=4:
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
2 *
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
3 * lsmod.c - Show the status of modules in the kernel
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
4 *
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
5 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
6 *
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
7 * Not in SUSv4.
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
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
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
10
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
11 config LSMOD
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
12 bool "lsmod"
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
13 default y
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
14 help
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
15 usage: lsmod
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
16
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
17 Display the currently loaded modules, their sizes and their
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
18 dependencies.
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
19 */
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
20
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
21 #include "toys.h"
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
22
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
23 void lsmod_main(void)
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
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
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
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
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
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
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
35 if (users[len] == ',' || users[len] == '-')
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
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
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
39 }
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
40 fclose(file);
d5d51fd18679 Adding lsmod
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
41 }