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