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

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

 



On 9/10/09, Andreas Robinson <andr345@xxxxxxxxx> wrote:
> On Thu, 2009-09-10 at 09:21 -0400, Jon Masters wrote:
>> On Thu, 2009-09-10 at 14:19 +0200, Kay Sievers wrote:
>> > On Thu, Sep 10, 2009 at 14:11, Michal Marek <mmarek@xxxxxxx> wrote:
>> > > Andreas Robinson napsal(a):
>>
>> > > My current /lib/modules/`uname -r`/modules.builtin is 129 lines, I'm
>> > > not
>> > > sure I want to see additional 129 lines each time I run lsmod. What
>> > > about some 'lsmod --show-builtin' ?
>> >
>> > Oh well, before we moved all to built-in in the kernel the list was
>> > that long as well. I think "grep is your friend" and we should not
>> > care and just print it. The less difference between built-in and
>> > module the better.
>>
>> I concur. I think you can grep or pass through a pager easy enough.
>>
>> Jon.
>>
>>
>
> A compromise? List the builtins first?
>
> >From bf7242f46c54f2db32fded00af098ec6d872d7d0 Mon Sep 17 00:00:00 2001
> From: Andreas Robinson <andr345@xxxxxxxxx>
> Date: Thu, 10 Sep 2009 15:13:20 +0200
> Subject: [PATCH] lsmod: print built-in modules
>
>
> Signed-off-by: Andreas Robinson <andr345@xxxxxxxxx>
> ---
>  lsmod.c |   25 ++++++++++++++++++++++++-
>  1 files changed, 24 insertions(+), 1 deletions(-)
>
> diff --git a/lsmod.c b/lsmod.c
> index 1fd2ec4..80401b4 100644
> --- a/lsmod.c
> +++ b/lsmod.c
> @@ -26,6 +26,8 @@
>  #include <errno.h>
>  #include <ctype.h>
>  #include <asm/unistd.h>
> +#include <limits.h>
> +#include <sys/utsname.h>
>
>  #include "testing.h"
>
> @@ -37,19 +39,40 @@ static void print_usage(const char *progname)
>
>  int main(int argc, char *argv[])
>  {
> +	char fname[PATH_MAX];
>  	char line[4096];
>  	FILE *file;
> +	struct utsname buf;
>
>  	if (argc != 1)
>  		print_usage("lsmod");
>
> +	printf("Module                  Size  Used by\n");
> +
> +	uname(&buf);
> +	snprintf(fname, sizeof(fname), "/lib/modules/%s/modules.builtin",
> +		buf.release);

This would be simpler using asprintf_nofail().  Also, you need to take
"modprobe -b /dir" and "modprobe -s kernel-version" into account.

> +	file = fopen(fname, "r");
> +	while (file && fgets(line, sizeof(line), file)) {
> +		char *modname, *ext;
> +
> +		modname = strrchr(line, '/');
> +		if (modname) {
> +			ext = strrchr(modname, '.');
> +			if (ext)
> +				*ext = '\0';

filename2modname() ?

> +			printf("%-19s        -  - [builtin]\n", modname+1);
> +		}
> +	}
> +	if (file)
> +		fclose(file);
> +
>  	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;

Thanks
Alan
--
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