Reputation: 4843
I wrote a kernel module that creates a entry in /proc/ and does some other tasks. I want to modify an existing kernel module to check if my module is running and execute some sentences depending on it (or execute others in case it is not running)
Any advice on how to do this?
Upvotes: 3
Views: 3540
Reputation: 104110
kernel/module.c
provides a function that will probably do what you need; you first need to lock module_mutex
and then call find_module()
with the name of your module. The result will be a pointer to a struct module
that describes the named module -- or NULL
if the module is not loaded:
/* Search for module by name: must hold module_mutex. */
struct module *find_module(const char *name)
{
struct module *mod;
list_for_each_entry(mod, &modules, list) {
if (strcmp(mod->name, name) == 0)
return mod;
}
return NULL;
}
EXPORT_SYMBOL_GPL(find_module);
Upvotes: 4