diff options
author | Christian Ruppert <idl0r@gentoo.org> | 2011-12-31 00:38:47 +0100 |
---|---|---|
committer | Christian Ruppert <idl0r@gentoo.org> | 2012-01-15 01:02:11 +0100 |
commit | 14625346c07a2a66fe77ce578c9423918bec1d97 (patch) | |
tree | 66731bb8b4527ea3609156507542bc7063235da2 | |
parent | c3be42006b78809f1087b6a8262caba01f2c7fc1 (diff) |
Allow overriding of rc.conf options via kernel cmdline
This adds a new function that allows us to override some specific rc.conf
options via the kernel cmdline aka /proc/cmdline.
This makes esp. sense in cases where a rc_parallel enabled system has boot
issues. Simply disable rc_parallel by appending rc_parallel=no to your kernel
cmdline.
-rw-r--r-- | src/librc/librc-misc.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c index cebc9e8c..a5daa07e 100644 --- a/src/librc/librc-misc.c +++ b/src/librc/librc-misc.c @@ -214,6 +214,60 @@ rc_config_list(const char *file) } librc_hidden_def(rc_config_list) +/* + * Override some specific rc.conf options via kernel cmdline + */ +#ifdef __linux__ +static RC_STRINGLIST *rc_config_override(RC_STRINGLIST *config) { + RC_STRINGLIST *overrides; + RC_STRING *cline, *override, *config_np; + char *tmp = NULL; + char *value = NULL; + size_t varlen = 0; + size_t len = 0; + + overrides = rc_stringlist_new(); + + /* A list of variables which may be overriden through cmdline */ + rc_stringlist_add(overrides, "rc_parallel"); + + TAILQ_FOREACH(override, overrides, entries) { + varlen = strlen(override->value); + value = rc_proc_getent(override->value); + + /* No need to continue if there's nothing to override */ + if (!value) { + free(value); + continue; + } + + if (value != NULL) { + len = (varlen + strlen(value) + 2); + tmp = xmalloc(sizeof(char) * len); + snprintf(tmp, len, "%s=%s", override->value, value); + } + + /* Whenever necessary remove the old config entry first to prevent duplicates */ + TAILQ_FOREACH_SAFE(cline, config, entries, config_np) { + if (strncmp(override->value, cline->value, varlen) == 0 && cline->value[varlen] == '=') { + rc_stringlist_delete(config, cline->value); + break; + } + } + + /* Add the option (var/value) to the current config */ + rc_stringlist_add(config, tmp); + + free(tmp); + free(value); + } + + rc_stringlist_free(overrides); + + return config; +} +#endif + RC_STRINGLIST * rc_config_load(const char *file) { @@ -287,6 +341,10 @@ rc_config_load(const char *file) } rc_stringlist_free(list); +#ifdef __linux__ + config = rc_config_override(config); +#endif + return config; } librc_hidden_def(rc_config_load) |