blob: b6656369306b3e44b56775046e27d36250810db6 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Erik Andersen6f23cec1999-12-15 22:14:12 +00002/*
3 * Mini lsmod implementation for busybox
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Denis Vlasenkoba1315d2008-09-13 14:59:38 +00006 * Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
Eric Andersen21adca72000-12-06 18:18:26 +00007 *
Bernhard Reutner-Fischerdeda6a52006-06-03 19:35:15 +00008 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Erik Andersen6f23cec1999-12-15 22:14:12 +00009 */
10
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Eric Andersenbe0dc0d2000-08-21 19:25:16 +000012
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000013#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
14enum {
15 TAINT_PROPRIETORY_MODULE = (1 << 0),
16 TAINT_FORCED_MODULE = (1 << 1),
17 TAINT_UNSAFE_SMP = (1 << 2),
18};
Eric Andersen166fa462002-09-16 05:30:24 +000019
Eric Andersen71ae64b2002-10-10 04:20:21 +000020static void check_tainted(void)
Eric Andersen166fa462002-09-16 05:30:24 +000021{
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000022 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);
Eric Andersen166fa462002-09-16 05:30:24 +000028 }
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000029
Denis Vlasenkob68979a2007-11-02 23:31:10 +000030 if (tainted) {
Eric Andersen52864942002-10-08 09:38:07 +000031 printf(" Tainted: %c%c%c\n",
Eric Andersen166fa462002-09-16 05:30:24 +000032 tainted & TAINT_PROPRIETORY_MODULE ? 'P' : 'G',
33 tainted & TAINT_FORCED_MODULE ? 'F' : ' ',
34 tainted & TAINT_UNSAFE_SMP ? 'S' : ' ');
Denis Vlasenkob68979a2007-11-02 23:31:10 +000035 } else {
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000036 puts(" Not tainted");
Eric Andersen166fa462002-09-16 05:30:24 +000037 }
38}
Rob Landley627814b2005-05-03 22:34:03 +000039#else
Denis Vlasenkoba1315d2008-09-13 14:59:38 +000040static void check_tainted(void) { putchar('\n'); }
41#endif
42
43int lsmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44int lsmod_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
45{
46#if ENABLE_FEATURE_LSMOD_PRETTY_2_6_OUTPUT
47 char *token[4];
48 parser_t *parser = config_open("/proc/modules");
49 printf("Module Size Used by"); //vda!
50 check_tainted();
51
52 if (ENABLE_FEATURE_2_4_MODULES
53 && get_linux_version_code() < KERNEL_VERSION(2,6,0)
54 ) {
55 while (config_read(parser, token, 4, 3, "# \t", PARSE_NORMAL)) {
56 if (token[3] != NULL && token[3][0] == '[') {
57 token[3]++;
58 token[3][strlen(token[3])-1] = '\0';
59 } else
60 token[3] = (char *) "";
61 printf("%-19s %8s %2s %s\n", token[0], token[1], token[2], token[3]);
62 }
63 } else {
64 while (config_read(parser, token, 4, 4, "# \t", PARSE_NORMAL & ~PARSE_GREEDY)) {
65 // N.B. token[3] is either '-' (module is not used by others)
66 // or comma-separated list ended by comma
67 // so trimming the trailing char is just what we need!
68 token[3][strlen(token[3])-1] = '\0';
69 printf("%-19s %8s %2s %s\n", token[0], token[1], token[2], token[3]);
70 }
71 }
72 if (ENABLE_FEATURE_CLEAN_UP)
73 config_close(parser);
74#else
75 check_tainted();
76 xprint_and_close_file(xfopen_for_read("/proc/modules"));
77#endif
Rob Landley86b4d642006-08-03 17:58:17 +000078 return EXIT_SUCCESS;
Eric Andersen21adca72000-12-06 18:18:26 +000079}