diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-03-31 17:14:42 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-03-31 17:14:42 +0000 |
commit | 39d0bc77f0ce2c66e52d5bd6228b4ba6543b1c91 (patch) | |
tree | 7a61dcd8012ede9d2759b110a4c755e44456b357 /usr.bin/tmux/environ.c | |
parent | a50cb7ffe73f1e00829305a3b87bced6370b8e48 (diff) |
Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.
Diffstat (limited to 'usr.bin/tmux/environ.c')
-rw-r--r-- | usr.bin/tmux/environ.c | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/usr.bin/tmux/environ.c b/usr.bin/tmux/environ.c index 6c45a205067..323a4025a83 100644 --- a/usr.bin/tmux/environ.c +++ b/usr.bin/tmux/environ.c @@ -1,4 +1,4 @@ -/* $OpenBSD: environ.c,v 1.23 2019/04/25 19:36:59 nicm Exp $ */ +/* $OpenBSD: environ.c,v 1.24 2020/03/31 17:14:40 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -86,8 +86,10 @@ environ_copy(struct environ *srcenv, struct environ *dstenv) RB_FOREACH(envent, environ, srcenv) { if (envent->value == NULL) environ_clear(dstenv, envent->name); - else - environ_set(dstenv, envent->name, "%s", envent->value); + else { + environ_set(dstenv, envent->name, envent->flags, + "%s", envent->value); + } } } @@ -103,18 +105,21 @@ environ_find(struct environ *env, const char *name) /* Set an environment variable. */ void -environ_set(struct environ *env, const char *name, const char *fmt, ...) +environ_set(struct environ *env, const char *name, int flags, const char *fmt, + ...) { struct environ_entry *envent; va_list ap; va_start(ap, fmt); if ((envent = environ_find(env, name)) != NULL) { + envent->flags = flags; free(envent->value); xvasprintf(&envent->value, fmt, ap); } else { envent = xmalloc(sizeof *envent); envent->name = xstrdup(name); + envent->flags = flags; xvasprintf(&envent->value, fmt, ap); RB_INSERT(environ, env, envent); } @@ -133,6 +138,7 @@ environ_clear(struct environ *env, const char *name) } else { envent = xmalloc(sizeof *envent); envent->name = xstrdup(name); + envent->flags = 0; envent->value = NULL; RB_INSERT(environ, env, envent); } @@ -140,7 +146,7 @@ environ_clear(struct environ *env, const char *name) /* Set an environment variable from a NAME=VALUE string. */ void -environ_put(struct environ *env, const char *var) +environ_put(struct environ *env, const char *var, int flags) { char *name, *value; @@ -152,7 +158,7 @@ environ_put(struct environ *env, const char *var) name = xstrdup(var); name[strcspn(name, "=")] = '\0'; - environ_set(env, name, "%s", value); + environ_set(env, name, flags, "%s", value); free(name); } @@ -170,7 +176,7 @@ environ_unset(struct environ *env, const char *name) free(envent); } -/* Copy variables from a destination into a source * environment. */ +/* Copy variables from a destination into a source environment. */ void environ_update(struct options *oo, struct environ *src, struct environ *dst) { @@ -188,7 +194,7 @@ environ_update(struct options *oo, struct environ *src, struct environ *dst) if ((envent = environ_find(src, ov->string)) == NULL) environ_clear(dst, ov->string); else - environ_set(dst, envent->name, "%s", envent->value); + environ_set(dst, envent->name, 0, "%s", envent->value); a = options_array_next(a); } } @@ -201,7 +207,9 @@ environ_push(struct environ *env) environ = xcalloc(1, sizeof *environ); RB_FOREACH(envent, environ, env) { - if (envent->value != NULL && *envent->name != '\0') + if (envent->value != NULL && + *envent->name != '\0' && + (~envent->flags & ENVIRON_HIDDEN)) setenv(envent->name, envent->value, 1); } } @@ -243,14 +251,15 @@ environ_for_session(struct session *s, int no_TERM) if (!no_TERM) { value = options_get_string(global_options, "default-terminal"); - environ_set(env, "TERM", "%s", value); + environ_set(env, "TERM", 0, "%s", value); } if (s != NULL) idx = s->id; else idx = -1; - environ_set(env, "TMUX", "%s,%ld,%d", socket_path, (long)getpid(), idx); + environ_set(env, "TMUX", 0, "%s,%ld,%d", socket_path, (long)getpid(), + idx); return (env); } |