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.
This commit is contained in:
Christian Ruppert 2011-12-31 00:38:47 +01:00
parent c3be42006b
commit 14625346c0

View File

@ -214,6 +214,60 @@ rc_config_list(const char *file)
} }
librc_hidden_def(rc_config_list) 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_STRINGLIST *
rc_config_load(const char *file) rc_config_load(const char *file)
{ {
@ -287,6 +341,10 @@ rc_config_load(const char *file)
} }
rc_stringlist_free(list); rc_stringlist_free(list);
#ifdef __linux__
config = rc_config_override(config);
#endif
return config; return config;
} }
librc_hidden_def(rc_config_load) librc_hidden_def(rc_config_load)