diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2014-10-09 10:59:08 -0300 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2014-10-09 11:00:21 -0300 |
commit | 52c9c9905683c781e611a5bf3c61fcdc22ab5429 (patch) | |
tree | 7ff0f6675fcf605feefc29c46469cb6e04f75ed1 /libkmod | |
parent | 2c5bc218bef191504e02a4f1e9071a2b5387f221 (diff) | |
download | kmod-52c9c9905683c781e611a5bf3c61fcdc22ab5429.tar.gz kmod-52c9c9905683c781e611a5bf3c61fcdc22ab5429.tar.bz2 kmod-52c9c9905683c781e611a5bf3c61fcdc22ab5429.zip |
Log error on failed underscores(), moving it to shared/
Move underscores() to shared/. It's the same as alias_normalize(), but
it rather operates in place, with the same string being passed.
The difference now that it's in shared/ is that it's a non-logging
function.
This makes us a little bit more verbose: we don't accept partially
correct module and aliases names in kcmdline and in configuration files.
We log an error instead.
Diffstat (limited to 'libkmod')
-rw-r--r-- | libkmod/libkmod-config.c | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c index 3dbf6c2..9cdc411 100644 --- a/libkmod/libkmod-config.c +++ b/libkmod/libkmod-config.c @@ -111,37 +111,6 @@ const char * const *kmod_softdep_get_post(const struct kmod_list *l, unsigned in return dep->post; } -/* - * Replace dashes with underscores. - * Dashes inside character range patterns (e.g. [0-9]) are left unchanged. - */ -static char *underscores(struct kmod_ctx *ctx, char *s) -{ - unsigned int i; - - if (!s) - return NULL; - - for (i = 0; s[i]; i++) { - switch (s[i]) { - case '-': - s[i] = '_'; - break; - - case ']': - INFO(ctx, "Unmatched bracket in %s\n", s); - break; - - case '[': - i += strcspn(&s[i], "]"); - if (!s[i]) - INFO(ctx, "Unmatched bracket in %s\n", s); - break; - } - } - return s; -} - static int kmod_config_add_command(struct kmod_config *config, const char *modname, const char *command, @@ -516,8 +485,11 @@ static void kcmdline_parse_result(struct kmod_config *config, char *modname, kmod_config_add_blacklist(config, t); } } else { - kmod_config_add_options(config, - underscores(config->ctx, modname), param); + if (underscores(modname) < 0) { + ERR(config->ctx, "Ignoring bad option on kernel command line while parsing module name: '%s'\n", + modname); + } + kmod_config_add_options(config, modname, param); } } @@ -609,62 +581,51 @@ static int kmod_config_parse(struct kmod_config *config, int fd, char *alias = strtok_r(NULL, "\t ", &saveptr); char *modname = strtok_r(NULL, "\t ", &saveptr); - if (alias == NULL || modname == NULL) + if (underscores(alias) < 0 || underscores(modname) < 0) goto syntax_error; - kmod_config_add_alias(config, - underscores(ctx, alias), - underscores(ctx, modname)); + kmod_config_add_alias(config, alias, modname); } else if (streq(cmd, "blacklist")) { char *modname = strtok_r(NULL, "\t ", &saveptr); - if (modname == NULL) + if (underscores(modname) < 0) goto syntax_error; - kmod_config_add_blacklist(config, - underscores(ctx, modname)); + kmod_config_add_blacklist(config, modname); } else if (streq(cmd, "options")) { char *modname = strtok_r(NULL, "\t ", &saveptr); char *options = strtok_r(NULL, "\0", &saveptr); - if (modname == NULL || options == NULL) + if (underscores(modname) < 0 || options == NULL) goto syntax_error; - kmod_config_add_options(config, - underscores(ctx, modname), - options); + kmod_config_add_options(config, modname, options); } else if (streq(cmd, "install")) { char *modname = strtok_r(NULL, "\t ", &saveptr); char *installcmd = strtok_r(NULL, "\0", &saveptr); - if (modname == NULL || installcmd == NULL) + if (underscores(modname) < 0 || installcmd == NULL) goto syntax_error; - kmod_config_add_command(config, - underscores(ctx, modname), - installcmd, + kmod_config_add_command(config, modname, installcmd, cmd, &config->install_commands); } else if (streq(cmd, "remove")) { char *modname = strtok_r(NULL, "\t ", &saveptr); char *removecmd = strtok_r(NULL, "\0", &saveptr); - if (modname == NULL || removecmd == NULL) + if (underscores(modname) < 0 || removecmd == NULL) goto syntax_error; - kmod_config_add_command(config, - underscores(ctx, modname), - removecmd, + kmod_config_add_command(config, modname, removecmd, cmd, &config->remove_commands); } else if (streq(cmd, "softdep")) { char *modname = strtok_r(NULL, "\t ", &saveptr); char *softdeps = strtok_r(NULL, "\0", &saveptr); - if (modname == NULL || softdeps == NULL) + if (underscores(modname) < 0 || softdeps == NULL) goto syntax_error; - kmod_config_add_softdep(config, - underscores(ctx, modname), - softdeps); + kmod_config_add_softdep(config, modname, softdeps); } else if (streq(cmd, "include") || streq(cmd, "config")) { ERR(ctx, "%s: command %s is deprecated and not parsed anymore\n", |