Package: busybox-cvs Version: 20040415-3 Severity: wishlist Tags: d-i patch
On 2.6 systems, busybox lsmod just says "lsmod: QM_MODULES: Function not implemented". This is because the query_module syscall has been removed from 2.6; you're apparently supposed to parse /proc/module instead, and this is what module-init-tools lsmod does. Here's a fairly straightforward port of the module-init-tools code to busybox. If this is not accepted for some reason, then just printing out the contents of /proc/modules would be an improvement over the current situation. However, I believe this patch is better because it presents a more consistent (even if not quite identical) output format. This adds less than half a KB to the busybox binary on powerpc. diff -u busybox-cvs-20040415/debian/changelog busybox-cvs-20040415/debian/changelog --- busybox-cvs-20040415/debian/changelog +++ busybox-cvs-20040415/debian/changelog @@ -1,3 +1,10 @@ +busybox-cvs (20040415-3.1) UNRELEASED; urgency=low + + * modutils/lsmod.c: + - Add 2.6 support, largely borrowed from module-init-tools. + + -- Colin Watson <[EMAIL PROTECTED]> Thu, 22 Apr 2004 10:26:19 +0100 + busybox-cvs (20040415-3) unstable; urgency=low * modutils: diff -u busybox-cvs-20040415/modutils/lsmod.c busybox-cvs-20040415/modutils/lsmod.c --- busybox-cvs-20040415/modutils/lsmod.c +++ busybox-cvs-20040415/modutils/lsmod.c @@ -8,6 +8,10 @@ * Nicolas Ferre <[EMAIL PROTECTED]> to support pre 2.1 kernels * (which lack the query_module() interface). * + * Modified by Colin Watson <[EMAIL PROTECTED]> based on lsmod from + * module-init-tools (Copyright (C) 2002 Rusty Russell, IBM Corporation) + * to support 2.6 kernels. + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -38,6 +42,7 @@ #include <sys/file.h> #include "busybox.h" +#include "modutils.h" #include "obj/module.h" #ifdef CONFIG_FEATURE_CHECK_TAINTED_MODULE @@ -122,11 +127,54 @@ return( 0); } +#ifdef CONFIG_FEATURE_2_6_MODULES +static inline int query_2_6_modules(void) +{ + char line[4096]; + FILE *file; + + if ((file = fopen("/proc/modules", "r")) == NULL) + bb_perror_msg_and_die("Can't read /proc/modules"); + while (fgets(line, sizeof(line), file)) { + char *mn, *size, *usecount, *deps; + mn = strtok(line, " \t"); + size = strtok(NULL, " \t"); + printf("%-20s%8s", mn, size); + usecount = strtok(NULL, " \t"); + /* NULL if no module unloading support. */ + if (usecount) { + deps = strtok(NULL, "\n"); + if (!deps) + deps = ""; + /* New-style has commas, or -. If so, + * truncate (other fields might follow). */ + else if (strchr(deps, ',')) { + deps = strtok(deps, " \t"); + /* Strip trailing comma. */ + if (deps[strlen(deps) - 1] == ',') + deps[strlen(deps) - 1] = '\0'; + } else if (deps[0] == '-' && + (deps[1] == '\0' || isspace(deps[1]))) + deps = ""; + printf("%4s %s", usecount, deps); + } + putchar('\n'); + } + fclose(file); + return 0; +} +#endif + extern int lsmod_main(int argc, char **argv) { printf("Module Size Used by"); check_tainted(); +#ifdef CONFIG_FEATURE_2_6_MODULES + if (get_kernel_revision() > MODUTILS_MINIMAL_VERSION_2_6) + return query_2_6_modules(); +#endif + #ifdef CONFIG_FEATURE_QUERY_MODULE_INTERFACE if (getuid() != 0) { Thanks, -- Colin Watson [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]