1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#include "libbb.h"
40#include "unicode.h"
41
42#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
43enum {
44 TAINT_PROPRIETORY_MODULE = (1 << 0),
45 TAINT_FORCED_MODULE = (1 << 1),
46 TAINT_UNSAFE_SMP = (1 << 2),
47};
48
49static void check_tainted(void)
50{
51 int tainted = 0;
52 char *buf = xmalloc_open_read_close("/proc/sys/kernel/tainted", NULL);
53 if (buf) {
54 tainted = atoi(buf);
55 if (ENABLE_FEATURE_CLEAN_UP)
56 free(buf);
57 }
58
59 if (tainted) {
60 printf(" Tainted: %c%c%c\n",
61 tainted & TAINT_PROPRIETORY_MODULE ? 'P' : 'G',
62 tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
63 tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
64 } else {
65 puts(" Not tainted");
66 }
67}
68#else
69static void check_tainted(void) { putchar('\n'); }
70#endif
71
72int lsmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
73int lsmod_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
74{
75#if ENABLE_FEATURE_LSMOD_PRETTY_2_6_OUTPUT
76 char *token[4];
77 parser_t *parser = config_open("/proc/modules");
78 init_unicode();
79
80 printf("%-24sSize Used by", "Module");
81 check_tainted();
82
83 if (ENABLE_FEATURE_2_4_MODULES
84 && get_linux_version_code() < KERNEL_VERSION(2,6,0)
85 ) {
86 while (config_read(parser, token, 4, 3, "# \t", PARSE_NORMAL)) {
87 if (token[3] != NULL && token[3][0] == '[') {
88 token[3]++;
89 token[3][strlen(token[3])-1] = '\0';
90 } else
91 token[3] = (char *) "";
92# if ENABLE_UNICODE_SUPPORT
93 {
94 uni_stat_t uni_stat;
95 char *uni_name = unicode_conv_to_printable(&uni_stat, token[0]);
96 unsigned pad_len = (uni_stat.unicode_width > 19) ? 0 : 19 - uni_stat.unicode_width;
97 printf("%s%*s %8s %2s %s\n", uni_name, pad_len, "", token[1], token[2], token[3]);
98 free(uni_name);
99 }
100# else
101 printf("%-19s %8s %2s %s\n", token[0], token[1], token[2], token[3]);
102# endif
103 }
104 } else {
105 while (config_read(parser, token, 4, 4, "# \t", PARSE_NORMAL & ~PARSE_GREEDY)) {
106
107
108
109 if (token[3][0])
110 token[3][strlen(token[3]) - 1] = '\0';
111# if ENABLE_UNICODE_SUPPORT
112 {
113 uni_stat_t uni_stat;
114 char *uni_name = unicode_conv_to_printable(&uni_stat, token[0]);
115 unsigned pad_len = (uni_stat.unicode_width > 19) ? 0 : 19 - uni_stat.unicode_width;
116 printf("%s%*s %8s %2s %s\n", uni_name, pad_len, "", token[1], token[2], token[3]);
117 free(uni_name);
118 }
119# else
120 printf("%-19s %8s %2s %s\n", token[0], token[1], token[2], token[3]);
121# endif
122 }
123 }
124 if (ENABLE_FEATURE_CLEAN_UP)
125 config_close(parser);
126#else
127 check_tainted();
128 xprint_and_close_file(xfopen_for_read("/proc/modules"));
129#endif
130 return EXIT_SUCCESS;
131}
132