[LTP] [PATCH v1] madvise11.c:Check loadable module before rmmod

Wei Gao wegao@suse.com
Sat Mar 11 03:23:09 CET 2023


On Fri, Mar 10, 2023 at 03:52:16PM +0100, Cyril Hrubis wrote:
> Hi!
> > +static int is_loadable_module(const char *modname)
> > +{
> > +	char command[MAX_BUF];
> > +	char line[MAX_BUF];
> > +	char *token;
> > +
> > +	sprintf(command, "lsmod | grep '^%s'", modname);
> > +
> > +	FILE *fp = popen(command, "r");
> > +
> > +	if (fp == NULL)
> > +		tst_brk(TBROK, "Popen command %s failed", command);
> > +
> > +	if (fgets(line, MAX_BUF, fp) != NULL) {
> > +		token = strtok(line, " \t\n");
> > +		if (strcmp(token, modname) == 0) {
> > +			pclose(fp);
> > +			return 1;
> > +		}
> > +	}
> > +
> > +	pclose(fp);
> > +	return 0;
> > +}
> 
> The code already has if (!find_in_file("/proc/modules", HW_MODULE)), you
> are reinventing the wheel.
There is an issue happen during our test, the fail happen with following failed msg.
rmmod: ERROR: Module hwpoison_inject is builtin.
madvise11.c:356: TWARN: rmmod failed (1)

So i think before rmmod we should check this module can be rmmod or not.
And every modules which can show in lsmod output, it means the module can be unload.
I am not sure the output of /proc/modules contain ONLY loadable module, it maybe
also can contain the buildin module so this function created.

> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz


More information about the ltp mailing list