mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-13 05:33:51 -04:00
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
This commit is contained in:
parent
646314469a
commit
ccfb953bb0
3 changed files with 24 additions and 13 deletions
|
|
@ -51,8 +51,11 @@
|
||||||
* `name` capability to `XTGETTCAP`.
|
* `name` capability to `XTGETTCAP`.
|
||||||
* String values in `foot.ini` may now be quoted. This can be used to
|
* String values in `foot.ini` may now be quoted. This can be used to
|
||||||
set a value to the empty string, for example.
|
set a value to the empty string, for example.
|
||||||
|
* Environment variables can now be **unset**, by setting
|
||||||
|
`[environment].<variable>=""` (quotes are required) ([#1225][1225])
|
||||||
|
|
||||||
[1136]: https://codeberg.org/dnkl/foot/issues/1136
|
[1136]: https://codeberg.org/dnkl/foot/issues/1136
|
||||||
|
[1225]: https://codeberg.org/dnkl/foot/issues/1225
|
||||||
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
||||||
23
config.c
23
config.c
|
|
@ -2295,21 +2295,22 @@ parse_section_environment(struct context *ctx)
|
||||||
{
|
{
|
||||||
struct config *conf = ctx->conf;
|
struct config *conf = ctx->conf;
|
||||||
const char *key = ctx->key;
|
const char *key = ctx->key;
|
||||||
const char *value = ctx->value;
|
|
||||||
|
|
||||||
|
/* Check for pre-existing env variable */
|
||||||
tll_foreach(conf->env_vars, it) {
|
tll_foreach(conf->env_vars, it) {
|
||||||
if (strcmp(it->item.name, key) == 0) {
|
if (strcmp(it->item.name, key) == 0)
|
||||||
free(it->item.value);
|
return value_to_str(ctx, &it->item.value);
|
||||||
it->item.value = xstrdup(value);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct env_var var = {
|
/*
|
||||||
.name = xstrdup(key),
|
* No pre-existing variable - allocate a new one
|
||||||
.value = xstrdup(value),
|
*/
|
||||||
};
|
|
||||||
tll_push_back(conf->env_vars, var);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
11
slave.c
11
slave.c
|
|
@ -359,8 +359,15 @@ slave_spawn(int ptmx, int argc, const char *cwd, char *const *argv,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (extra_env_vars != NULL) {
|
if (extra_env_vars != NULL) {
|
||||||
tll_foreach(*extra_env_vars, it)
|
tll_foreach(*extra_env_vars, it) {
|
||||||
setenv(it->item.name, it->item.value, 1);
|
const char *name = it->item.name;
|
||||||
|
const char *value = it->item.value;
|
||||||
|
|
||||||
|
if (strlen(value) == 0)
|
||||||
|
unsetenv(name);
|
||||||
|
else
|
||||||
|
setenv(name, value, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char **_shell_argv = NULL;
|
char **_shell_argv = NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue