From: Joel Rosdahl Date: Sat, 16 Jul 2011 13:32:24 +0000 (+0200) Subject: config: Correctly interpret boolean environment variables X-Git-Tag: v3.2~236 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ebe6df536d7517516579b7408795f22b03de0857;p=thirdparty%2Fccache.git config: Correctly interpret boolean environment variables --- diff --git a/conf.c b/conf.c index 0ad48b1cb..95cfa2f5e 100644 --- a/conf.c +++ b/conf.c @@ -283,7 +283,7 @@ find_env_to_conf(const char *name) static bool handle_conf_setting(struct conf *conf, const char *key, const char *value, - char **errmsg) + char **errmsg, bool from_env_variable) { const struct conf_item *item; @@ -293,6 +293,16 @@ handle_conf_setting(struct conf *conf, const char *key, const char *value, return false; } + if (from_env_variable && item->parser == parse_bool) { + /* + * Special rule for boolean settings from the environment: any value means + * true. + */ + bool *value = (bool *)((void *)conf + item->offset); + *value = true; + return true; + } + if (!item->parser(value, (void *)conf + item->offset, errmsg)) { return false; } @@ -345,7 +355,7 @@ parse_line(struct conf *conf, const char *line, char **errmsg) #undef SKIP_WS - result = handle_conf_setting(conf, key, value, errmsg); + result = handle_conf_setting(conf, key, value, errmsg, false); free(key); free(value); @@ -516,7 +526,8 @@ conf_update_from_environment(struct conf *conf, char **errmsg) continue; } - if (!handle_conf_setting(conf, env_to_conf_item->conf_name, q, &errmsg2)) { + if (!handle_conf_setting( + conf, env_to_conf_item->conf_name, q, &errmsg2, true)) { *errmsg = format("%s: %s", key, errmsg2); free(errmsg2); free(key);