1 alias may correspond to more than 1 module. This would cause a
conflict in the hash table when inserting a module there and bad things
could happen.
Now we use 'modname/aliasname' as key, '/aliasname' part being optional.
Internally kmod_module_new_from_alias() will setup a 'modname/aliasname'
string and pass to kmod_module_new_from_name() that will treat the case
with a '/' in the name.
User might call kmod_module_new_from_name() without any slashes, so the
key my not contain it.
- dump configuration
- use softdep, install and remove commands
- dump configuration
- use softdep, install and remove commands
-* With last changes to the hash of kmod module's, if an alias resolves to more
- than one module it will conflict in the table. The proper solution is to use
- 'modname/modalias' as the hash key.
struct kmod_module *m;
size_t namelen;
char name_norm[NAME_MAX];
struct kmod_module *m;
size_t namelen;
char name_norm[NAME_MAX];
if (ctx == NULL || name == NULL)
return -ENOENT;
if (ctx == NULL || name == NULL)
return -ENOENT;
m->ctx = kmod_ref(ctx);
m->name = (char *)m + sizeof(*m);
memcpy(m->name, name_norm, namelen + 1);
m->ctx = kmod_ref(ctx);
m->name = (char *)m + sizeof(*m);
memcpy(m->name, name_norm, namelen + 1);
+ /* set alias later, so m->name is still modname/modalias */
kmod_pool_add_module(ctx, m);
kmod_pool_add_module(ctx, m);
+ namesep = strchr(m->name, '/');
+ if (namesep != NULL) {
+ *namesep = '\0';
+ m->alias = namesep + 1;
+ }
+
const char *name, struct kmod_module **mod)
{
int err;
const char *name, struct kmod_module **mod)
{
int err;
+ char key[NAME_MAX];
+ size_t namelen = strlen(name);
+ size_t aliaslen = strlen(alias);
- err = kmod_module_new_from_name(ctx, alias, mod);
- if (err < 0)
- return err;
+ if (namelen + aliaslen + 2 > NAME_MAX)
+ return -ENAMETOOLONG;
+ memcpy(key, name, namelen);
+ memcpy(key + namelen + 1, alias, aliaslen + 1);
+ key[namelen] = '/';
- /* if module did not came from pool */
- if (m->alias == NULL) {
- m->alias = m->name;
- m->name = strdup(name);
- if (m->name == NULL)
- goto fail_oom;
- }
+ err = kmod_module_new_from_name(ctx, key, mod);
+ if (err < 0)
+ return err;
-
-fail_oom:
- ERR(ctx, "out of memory\n");
- kmod_module_unref(m);
- *mod = NULL;
- return err;
free(mod->install_commands);
free(mod->remove_commands);
free(mod->path);
free(mod->install_commands);
free(mod->remove_commands);
free(mod->path);
- if (mod->alias != NULL)
- free(mod->name);
free(mod);
return NULL;
}
free(mod);
return NULL;
}