diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-01-24 20:15:33 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-01-24 20:15:33 +0000 |
commit | 6feccbfb8530026d713a2a90c60108635fb3abeb (patch) | |
tree | adf1795876b23b248889e990c9c87675a464c0f7 /usr.bin | |
parent | 5e3f53613e55106d6b61636be22cede72866d391 (diff) |
Make update-environment an array as well.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-attach-session.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-new-session.c | 11 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-switch-client.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/environ.c | 30 | ||||
-rw-r--r-- | usr.bin/tmux/options-table.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 12 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
7 files changed, 37 insertions, 55 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index 3a6e24a1351..bfa46113402 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-attach-session.c,v 1.65 2016/10/16 22:06:40 nicm Exp $ */ +/* $OpenBSD: cmd-attach-session.c,v 1.66 2017/01/24 20:15:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -54,7 +54,6 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, struct client *c = item->client, *c_loop; struct winlink *wl = item->state.tflag.wl; struct window_pane *wp = item->state.tflag.wp; - const char *update; char *cause, *cwd; struct format_tree *ft; @@ -95,12 +94,8 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, server_client_detach(c_loop, MSG_DETACH); } } - - if (!Eflag) { - update = options_get_string(s->options, - "update-environment"); - environ_update(update, c->environ, s->environ); - } + if (!Eflag) + environ_update(s->options, c->environ, s->environ); c->session = s; server_client_set_key_table(c, NULL); @@ -116,7 +111,6 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, free(cause); return (CMD_RETURN_ERROR); } - if (rflag) c->flags |= CLIENT_READONLY; @@ -127,12 +121,8 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag, server_client_detach(c_loop, MSG_DETACH); } } - - if (!Eflag) { - update = options_get_string(s->options, - "update-environment"); - environ_update(update, c->environ, s->environ); - } + if (!Eflag) + environ_update(s->options, c->environ, s->environ); c->session = s; server_client_set_key_table(c, NULL); diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index a122ca0d7c0..b486cce9e4e 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.96 2017/01/13 11:56:43 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.97 2017/01/24 20:15:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -73,7 +73,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) struct window *w; struct environ *env; struct termios tio, *tiop; - const char *newname, *target, *update, *errstr, *template; + const char *newname, *target, *errstr, *template; const char *path, *cmd, *cwd, *to_free = NULL; char **argv, *cause, *cp; int detached, already_attached, idx, argc; @@ -234,11 +234,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) /* Construct the environment. */ env = environ_create(); - if (c != NULL && !args_has(args, 'E')) { - update = options_get_string(global_s_options, - "update-environment"); - environ_update(update, c->environ, env); - } + if (c != NULL && !args_has(args, 'E')) + environ_update(global_s_options, c->environ, env); /* Create the new session. */ idx = -1 - options_get_number(global_s_options, "base-index"); diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index b4680165bef..ffd45dc692f 100644 --- a/usr.bin/tmux/cmd-switch-client.c +++ b/usr.bin/tmux/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-switch-client.c,v 1.45 2017/01/06 13:26:09 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.46 2017/01/24 20:15:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -53,7 +53,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) struct client *c = state->c; struct session *s = item->state.tflag.s; struct window_pane *wp; - const char *tablename, *update; + const char *tablename; struct key_table *table; if (args_has(args, 'r')) @@ -102,10 +102,8 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) } } - if (!args_has(args, 'E')) { - update = options_get_string(s->options, "update-environment"); - environ_update(update, c->environ, s->environ); - } + if (!args_has(args, 'E')) + environ_update(s->options, c->environ, s->environ); if (c->session != NULL && c->session != s) c->last_session = c->session; diff --git a/usr.bin/tmux/environ.c b/usr.bin/tmux/environ.c index 74772c86a46..fea22871d3b 100644 --- a/usr.bin/tmux/environ.c +++ b/usr.bin/tmux/environ.c @@ -1,4 +1,4 @@ -/* $OpenBSD: environ.c,v 1.16 2016/10/10 21:29:23 nicm Exp $ */ +/* $OpenBSD: environ.c,v 1.17 2017/01/24 20:15:32 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -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(). */ diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index 6b7add0ffad..122a713ca43 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.85 2017/01/24 20:05:15 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.86 2017/01/24 20:15:32 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -482,11 +482,10 @@ const struct options_table_entry options_table[] = { }, { .name = "update-environment", - .type = OPTIONS_TABLE_STRING, + .type = OPTIONS_TABLE_ARRAY, .scope = OPTIONS_TABLE_SESSION, .default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID " "SSH_CONNECTION WINDOWID XAUTHORITY" - }, { .name = "visual-activity", diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 0c664f066ca..c9732a3ec64 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.528 2017/01/24 20:05:15 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.529 2017/01/24 20:15:32 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -2869,19 +2869,15 @@ For how to specify see the .Ic message-command-style option. -.It Ic update-environment Ar variables -Set a space-separated string containing a list of environment variables to be -copied into the session environment when a new session is created or an -existing session is attached. +.It Ic update-environment[] Ar variable +Set list of environment variables to be copied into the session environment +when a new session is created or an existing session is attached. Any variables that do not exist in the source environment are set to be removed from the session environment (as if .Fl r was given to the .Ic set-environment command). -The default is -"DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID -XAUTHORITY". .It Xo Ic visual-activity .Op Ic on | off .Xc diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 680f889360c..5d76f8d82b4 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.704 2017/01/24 19:53:37 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.705 2017/01/24 20:15:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1669,7 +1669,7 @@ void printflike(3, 4) environ_set(struct environ *, const char *, const char *, void environ_clear(struct environ *, const char *); void environ_put(struct environ *, const char *); void environ_unset(struct environ *, const char *); -void environ_update(const char *, struct environ *, struct environ *); +void environ_update(struct options *, struct environ *, struct environ *); void environ_push(struct environ *); void environ_log(struct environ *, const char *); |