summaryrefslogtreecommitdiffstats
path: root/environ.c
diff options
context:
space:
mode:
authornicm <nicm>2017-01-24 20:15:32 +0000
committernicm <nicm>2017-01-24 20:15:32 +0000
commit4b2821ff9861b193226442e9bc5507a9ddffa827 (patch)
tree23450181f40165bdae3648353e15ef064134c27d /environ.c
parentb77dd75b5717d3b95a97c7b60c9e054338d7d85e (diff)
Make update-environment an array as well.
Diffstat (limited to 'environ.c')
-rw-r--r--environ.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/environ.c b/environ.c
index 016d256a..4bb794dd 100644
--- a/environ.c
+++ b/environ.c
@@ -169,25 +169,27 @@ environ_unset(struct environ *env, const char *name)
free(envent);
}
-/*
- * Copy a space-separated list of variables from a destination into a source
- * environment.
- */
+/* Copy variables from a destination into a source * environment. */
void
-environ_update(const char *vars, struct environ *srcenv,
- struct environ *dstenv)
+environ_update(struct options *oo, struct environ *src, struct environ *dst)
{
struct environ_entry *envent;
- char *copyvars, *var, *next;
+ struct options_entry *o;
+ u_int size, idx;
+ const char *value;
- copyvars = next = xstrdup(vars);
- while ((var = strsep(&next, " ")) != NULL) {
- if ((envent = environ_find(srcenv, var)) == NULL)
- environ_clear(dstenv, var);
+ o = options_get(oo, "update-environment");
+ if (o == NULL || options_array_size(o, &size) == -1)
+ return;
+ for (idx = 0; idx < size; idx++) {
+ value = options_array_get(o, idx);
+ if (value == NULL)
+ continue;
+ if ((envent = environ_find(src, value)) == NULL)
+ environ_clear(dst, value);
else
- environ_set(dstenv, envent->name, "%s", envent->value);
+ environ_set(dst, envent->name, "%s", envent->value);
}
- free(copyvars);
}
/* Push environment into the real environment - use after fork(). */