]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
config: Correctly interpret boolean environment variables
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 16 Jul 2011 13:32:24 +0000 (15:32 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 17 Jul 2011 09:57:51 +0000 (11:57 +0200)
conf.c

diff --git a/conf.c b/conf.c
index 0ad48b1cb32bd038eec5fed5bd268426c2dbc775..95cfa2f5e009b74caa6d1751a6ef36d6db29781a 100644 (file)
--- 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);