Re: [PATCH] lsmod: print built-in modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



New try, with asprintf_nofail() and filename2modname().

Not sure what you mean with taking modprobe -b in account though.

As for modprobe -S, shouldn't lsmod simply list the current state of the
system, which implies only looking at /lib/modules/`uname -r`?

>From 543ba3d78f5fd4986a30130c60e8d3fd15d57758 Mon Sep 17 00:00:00 2001
From: Andreas Robinson <andr345@xxxxxxxxx>
Date: Thu, 10 Sep 2009 19:39:55 +0200
Subject: [PATCH] lsmod: print built-in modules

Signed-off-by: Andreas Robinson <andr345@xxxxxxxxx>
---
 lsmod.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/lsmod.c b/lsmod.c
index 1fd2ec4..aa4074a 100644
--- a/lsmod.c
+++ b/lsmod.c
@@ -15,6 +15,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -26,7 +27,11 @@
 #include <errno.h>
 #include <ctype.h>
 #include <asm/unistd.h>
+#include <limits.h>
+#include <sys/utsname.h>
 
+#include "util.h"
+#include "logging.h"
 #include "testing.h"
 
 static void print_usage(const char *progname)
@@ -37,19 +42,36 @@ static void print_usage(const char *progname)
 
 int main(int argc, char *argv[])
 {
+	char *fname;
+	struct utsname buf;
 	char line[4096];
 	FILE *file;
 
 	if (argc != 1)
 		print_usage("lsmod");
 
+	printf("Module                  Size  Used by\n");
+
+	uname(&buf);
+	nofail_asprintf(&fname, "/lib/modules/%s/modules.builtin", buf.release);
+	file = fopen(fname, "r");
+	if (!file && errno != ENOENT)
+		fprintf(stderr, "Opening %s: %s\n", fname, strerror(errno));
+	if (file) {
+		while (fgets(line, sizeof(line), file)) {
+			filename2modname(line, line);
+			printf("%-19s        -  - [builtin]\n", line);
+		}
+		fclose(file);
+	}
+	free(fname);
+
 	file = fopen("/proc/modules", "r");
 	if (!file) {
 		perror("Opening /proc/modules");
 		exit(1);
 	}
 
-	printf("Module                  Size  Used by\n");
 	while (fgets(line, sizeof(line), file)) {
 		char *tok;
 
-- 
1.6.0.4


--
To unsubscribe from this list: send the line "unsubscribe linux-modules" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux