Magellan Linux

Annotation of /tags/mkinitrd-6_3_0/busybox/modutils/lsmod.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1123 - (hide annotations) (download)
Wed Aug 18 21:56:57 2010 UTC (13 years, 9 months ago) by niro
Original Path: trunk/mkinitrd-magellan/busybox/modutils/lsmod.c
File MIME type: text/plain
File size: 2964 byte(s)
-updated to busybox-1.17.1
1 niro 532 /* vi: set sw=4 ts=4: */
2     /*
3     * Mini lsmod implementation for busybox
4     *
5     * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 niro 816 * Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
7 niro 532 *
8     * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9     */
10 niro 816 #include "libbb.h"
11 niro 984 #include "unicode.h"
12 niro 532
13 niro 816 #if ENABLE_FEATURE_CHECK_TAINTED_MODULE
14     enum {
15     TAINT_PROPRIETORY_MODULE = (1 << 0),
16     TAINT_FORCED_MODULE = (1 << 1),
17     TAINT_UNSAFE_SMP = (1 << 2),
18     };
19 niro 532
20     static void check_tainted(void)
21     {
22 niro 816 int tainted = 0;
23     char *buf = xmalloc_open_read_close("/proc/sys/kernel/tainted", NULL);
24     if (buf) {
25     tainted = atoi(buf);
26     if (ENABLE_FEATURE_CLEAN_UP)
27     free(buf);
28     }
29 niro 532
30 niro 816 if (tainted) {
31 niro 532 printf(" Tainted: %c%c%c\n",
32     tainted & TAINT_PROPRIETORY_MODULE ? 'P' : 'G',
33     tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
34     tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
35 niro 816 } else {
36     puts(" Not tainted");
37 niro 532 }
38     }
39 niro 816 #else
40     static void check_tainted(void) { putchar('\n'); }
41 niro 532 #endif
42    
43 niro 816 int lsmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44     int lsmod_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
45 niro 532 {
46 niro 816 #if ENABLE_FEATURE_LSMOD_PRETTY_2_6_OUTPUT
47     char *token[4];
48     parser_t *parser = config_open("/proc/modules");
49 niro 984 init_unicode();
50    
51 niro 816 printf("%-24sSize Used by", "Module");
52 niro 532 check_tainted();
53    
54 niro 816 if (ENABLE_FEATURE_2_4_MODULES
55     && get_linux_version_code() < KERNEL_VERSION(2,6,0)
56     ) {
57     while (config_read(parser, token, 4, 3, "# \t", PARSE_NORMAL)) {
58     if (token[3] != NULL && token[3][0] == '[') {
59     token[3]++;
60     token[3][strlen(token[3])-1] = '\0';
61     } else
62     token[3] = (char *) "";
63 niro 1123 # if ENABLE_UNICODE_SUPPORT
64     {
65     uni_stat_t uni_stat;
66     char *uni_name = unicode_conv_to_printable(&uni_stat, token[0]);
67     unsigned pad_len = (uni_stat.unicode_width > 19) ? 0 : 19 - uni_stat.unicode_width;
68     printf("%s%*s %8s %2s %s\n", uni_name, pad_len, "", token[1], token[2], token[3]);
69     free(uni_name);
70     }
71 niro 984 # else
72 niro 816 printf("%-19s %8s %2s %s\n", token[0], token[1], token[2], token[3]);
73 niro 984 # endif
74 niro 532 }
75 niro 816 } else {
76     while (config_read(parser, token, 4, 4, "# \t", PARSE_NORMAL & ~PARSE_GREEDY)) {
77     // N.B. token[3] is either '-' (module is not used by others)
78     // or comma-separated list ended by comma
79     // so trimming the trailing char is just what we need!
80     token[3][strlen(token[3])-1] = '\0';
81 niro 1123 # if ENABLE_UNICODE_SUPPORT
82     {
83     uni_stat_t uni_stat;
84     char *uni_name = unicode_conv_to_printable(&uni_stat, token[0]);
85     unsigned pad_len = (uni_stat.unicode_width > 19) ? 0 : 19 - uni_stat.unicode_width;
86     printf("%s%*s %8s %2s %s\n", uni_name, pad_len, "", token[1], token[2], token[3]);
87     free(uni_name);
88     }
89 niro 984 # else
90 niro 816 printf("%-19s %8s %2s %s\n", token[0], token[1], token[2], token[3]);
91 niro 984 # endif
92 niro 532 }
93     }
94 niro 816 if (ENABLE_FEATURE_CLEAN_UP)
95     config_close(parser);
96     #else
97     check_tainted();
98     xprint_and_close_file(xfopen_for_read("/proc/modules"));
99 niro 532 #endif
100     return EXIT_SUCCESS;
101     }