From 14625346c07a2a66fe77ce578c9423918bec1d97 Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Sat, 31 Dec 2011 00:38:47 +0100 Subject: 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. --- src/librc/librc-misc.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) 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) -- cgit v1.2.3