=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/environ.c,v retrieving revision 1.23 retrieving revision 1.24 diff -c -r1.23 -r1.24 *** src/usr.bin/tmux/environ.c 2019/04/25 19:36:59 1.23 --- src/usr.bin/tmux/environ.c 2020/03/31 17:14:40 1.24 *************** *** 1,4 **** ! /* $OpenBSD: environ.c,v 1.23 2019/04/25 19:36:59 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: environ.c,v 1.24 2020/03/31 17:14:40 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott *************** *** 86,93 **** RB_FOREACH(envent, environ, srcenv) { if (envent->value == NULL) environ_clear(dstenv, envent->name); ! else ! environ_set(dstenv, envent->name, "%s", envent->value); } } --- 86,95 ---- RB_FOREACH(envent, environ, srcenv) { if (envent->value == NULL) environ_clear(dstenv, envent->name); ! else { ! environ_set(dstenv, envent->name, envent->flags, ! "%s", envent->value); ! } } } *************** *** 103,120 **** /* Set an environment variable. */ void ! environ_set(struct environ *env, const char *name, const char *fmt, ...) { struct environ_entry *envent; va_list ap; va_start(ap, fmt); if ((envent = environ_find(env, name)) != NULL) { free(envent->value); xvasprintf(&envent->value, fmt, ap); } else { envent = xmalloc(sizeof *envent); envent->name = xstrdup(name); xvasprintf(&envent->value, fmt, ap); RB_INSERT(environ, env, envent); } --- 105,125 ---- /* Set an environment variable. */ void ! 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,138 **** --- 138,144 ---- } else { envent = xmalloc(sizeof *envent); envent->name = xstrdup(name); + envent->flags = 0; envent->value = NULL; RB_INSERT(environ, env, envent); } *************** *** 140,146 **** /* Set an environment variable from a NAME=VALUE string. */ void ! environ_put(struct environ *env, const char *var) { char *name, *value; --- 146,152 ---- /* Set an environment variable from a NAME=VALUE string. */ void ! environ_put(struct environ *env, const char *var, int flags) { char *name, *value; *************** *** 152,158 **** name = xstrdup(var); name[strcspn(name, "=")] = '\0'; ! environ_set(env, name, "%s", value); free(name); } --- 158,164 ---- name = xstrdup(var); name[strcspn(name, "=")] = '\0'; ! environ_set(env, name, flags, "%s", value); free(name); } *************** *** 170,176 **** free(envent); } ! /* Copy variables from a destination into a source * environment. */ void environ_update(struct options *oo, struct environ *src, struct environ *dst) { --- 176,182 ---- free(envent); } ! /* Copy variables from a destination into a source environment. */ void environ_update(struct options *oo, struct environ *src, struct environ *dst) { *************** *** 188,194 **** if ((envent = environ_find(src, ov->string)) == NULL) environ_clear(dst, ov->string); else ! environ_set(dst, envent->name, "%s", envent->value); a = options_array_next(a); } } --- 194,200 ---- if ((envent = environ_find(src, ov->string)) == NULL) environ_clear(dst, ov->string); else ! environ_set(dst, envent->name, 0, "%s", envent->value); a = options_array_next(a); } } *************** *** 201,207 **** environ = xcalloc(1, sizeof *environ); RB_FOREACH(envent, environ, env) { ! if (envent->value != NULL && *envent->name != '\0') setenv(envent->name, envent->value, 1); } } --- 207,215 ---- environ = xcalloc(1, sizeof *environ); RB_FOREACH(envent, environ, env) { ! if (envent->value != NULL && ! *envent->name != '\0' && ! (~envent->flags & ENVIRON_HIDDEN)) setenv(envent->name, envent->value, 1); } } *************** *** 243,256 **** if (!no_TERM) { value = options_get_string(global_options, "default-terminal"); ! environ_set(env, "TERM", "%s", value); } if (s != NULL) idx = s->id; else idx = -1; ! environ_set(env, "TMUX", "%s,%ld,%d", socket_path, (long)getpid(), idx); return (env); } --- 251,265 ---- if (!no_TERM) { value = options_get_string(global_options, "default-terminal"); ! environ_set(env, "TERM", 0, "%s", value); } if (s != NULL) idx = s->id; else idx = -1; ! environ_set(env, "TMUX", 0, "%s,%ld,%d", socket_path, (long)getpid(), ! idx); return (env); }