[LTP] [PATCH v1] madvise11.c:Check loadable module before rmmod
Wei Gao
wegao@suse.com
Sun Mar 12 01:47:16 CET 2023
On Fri, Mar 10, 2023 at 09:23:09PM -0500, Wei Gao via ltp wrote:
> 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.
>
I have found modinfo is more stable way to check whether module is builtin or not.
I have update the patch to v3 now.
> >
> > --
> > Cyril Hrubis
> > chrubis@suse.cz
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
More information about the ltp
mailing list