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

Cyril Hrubis chrubis@suse.cz
Fri Mar 10 15:52:16 CET 2023


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.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list