aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-12-01 18:43:38 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-12-06 18:36:15 +0000
commitccfb953bb020a1d229490b8a3e7790ed5c7e1752 (patch)
tree6aa0147074815d1c2caebccd76a4e09e38ecd022 /config.c
parentdoc: foot.ini: add example, and mention string options can be quoted (diff)
slave: unsetenv() env vars that have been set to the empty string
That is, users can now *clear* environment variables by doing: [environment] VAR=”” Note that the quotes are required. Closes #1225
Diffstat (limited to 'config.c')
-rw-r--r--config.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/config.c b/config.c
index cbf64abc..68641647 100644
--- a/config.c
+++ b/config.c
@@ -2295,21 +2295,22 @@ parse_section_environment(struct context *ctx)
{
struct config *conf = ctx->conf;
const char *key = ctx->key;
- const char *value = ctx->value;
+ /* Check for pre-existing env variable */
tll_foreach(conf->env_vars, it) {
- if (strcmp(it->item.name, key) == 0) {
- free(it->item.value);
- it->item.value = xstrdup(value);
- return true;
- }
+ if (strcmp(it->item.name, key) == 0)
+ return value_to_str(ctx, &it->item.value);
}
- struct env_var var = {
- .name = xstrdup(key),
- .value = xstrdup(value),
- };
- tll_push_back(conf->env_vars, var);
+ /*
+ * No pre-existing variable - allocate a new one
+ */
+
+ char *value = NULL;
+ if (!value_to_str(ctx, &value))
+ return false;
+
+ tll_push_back(conf->env_vars, ((struct env_var){xstrdup(key), value}));
return true;
}