diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-03-09 17:02:39 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-03-09 17:02:39 +0000 |
commit | d5cffd6633270052181503e5a2e5b9a10bde251e (patch) | |
tree | bd7078d4d59758517ea0a0020fcbaa848244bd47 /usr.bin/tmux | |
parent | 802e114586ecfa21a8e416ab735849b32b6beeeb (diff) |
Move server_fill_environ into environ.c and move some other common code
into it.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/cmd-respawn-pane.c | 11 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-respawn-window.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-split-window.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/environ.c | 28 | ||||
-rw-r--r-- | usr.bin/tmux/job.c | 9 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
8 files changed, 48 insertions, 60 deletions
diff --git a/usr.bin/tmux/cmd-respawn-pane.c b/usr.bin/tmux/cmd-respawn-pane.c index 4c31d003f8d..fb16ca41759 100644 --- a/usr.bin/tmux/cmd-respawn-pane.c +++ b/usr.bin/tmux/cmd-respawn-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-pane.c,v 1.22 2016/10/16 19:04:05 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-pane.c,v 1.23 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -65,11 +65,6 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_ERROR); } - env = environ_create(); - environ_copy(global_environ, env); - environ_copy(s->environ, env); - server_fill_environ(s, env); - window_pane_reset_mode(wp); screen_reinit(&wp->base); input_init(wp); @@ -82,6 +77,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; + env = environ_for_session(s); if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { cmdq_error(item, "respawn pane failed: %s", cause); @@ -89,9 +85,10 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item) environ_free(env); return (CMD_RETURN_ERROR); } + environ_free(env); + wp->flags |= PANE_REDRAW; server_status_window(w); - environ_free(env); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/cmd-respawn-window.c b/usr.bin/tmux/cmd-respawn-window.c index f398ee47da8..30aaf5e11c2 100644 --- a/usr.bin/tmux/cmd-respawn-window.c +++ b/usr.bin/tmux/cmd-respawn-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-respawn-window.c,v 1.32 2016/10/16 19:04:05 nicm Exp $ */ +/* $OpenBSD: cmd-respawn-window.c,v 1.33 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -66,11 +66,6 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) } } - env = environ_create(); - environ_copy(global_environ, env); - environ_copy(s->environ, env); - server_fill_environ(s, env); - wp = TAILQ_FIRST(&w->panes); TAILQ_REMOVE(&w->panes, wp, entry); layout_free(w); @@ -86,6 +81,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; + env = environ_for_session(s); if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env, s->tio, &cause) != 0) { cmdq_error(item, "respawn window failed: %s", cause); @@ -94,6 +90,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) server_destroy_pane(wp, 0); return (CMD_RETURN_ERROR); } + environ_free(env); layout_init(w, wp); window_pane_reset_mode(wp); screen_reinit(&wp->base); @@ -103,6 +100,5 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item) recalculate_sizes(); server_redraw_window(w); - environ_free(env); return (CMD_RETURN_NORMAL); } diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index cff67bdf0d5..fcf915742cc 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.79 2017/03/08 13:36:12 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.80 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -71,11 +71,6 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) server_unzoom_window(w); - env = environ_create(); - environ_copy(global_environ, env); - environ_copy(s->environ, env); - server_fill_environ(s, env); - if (args->argc == 0) { cmd = options_get_string(s->options, "default-command"); if (cmd != NULL && *cmd != '\0') { @@ -148,9 +143,13 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) if (envent != NULL) path = envent->value; + env = environ_for_session(s); if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, env, - s->tio, &cause) != 0) + s->tio, &cause) != 0) { + environ_free(env); goto error; + } + environ_free(env); server_redraw_window(w); @@ -161,8 +160,6 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) } else server_status_session(s); - environ_free(env); - if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL) template = SPLIT_WINDOW_TEMPLATE; @@ -186,7 +183,6 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_NORMAL); error: - environ_free(env); if (new_wp != NULL) { layout_close_pane(new_wp); window_remove_pane(w, new_wp); diff --git a/usr.bin/tmux/environ.c b/usr.bin/tmux/environ.c index fea22871d3b..eec2a65f30d 100644 --- a/usr.bin/tmux/environ.c +++ b/usr.bin/tmux/environ.c @@ -1,4 +1,4 @@ -/* $OpenBSD: environ.c,v 1.17 2017/01/24 20:15:32 nicm Exp $ */ +/* $OpenBSD: environ.c,v 1.18 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -20,6 +20,7 @@ #include <stdlib.h> #include <string.h> +#include <unistd.h> #include "tmux.h" @@ -218,3 +219,28 @@ environ_log(struct environ *env, const char *prefix) } } } + +/* Create initial environment for new child. */ +struct environ * +environ_for_session(struct session *s) +{ + struct environ *env; + const char *value; + int idx; + + env = environ_create(); + environ_copy(global_environ, env); + if (s != NULL) + environ_copy(s->environ, env); + + 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); +} diff --git a/usr.bin/tmux/job.c b/usr.bin/tmux/job.c index 7f037b295cc..9f50311c40d 100644 --- a/usr.bin/tmux/job.c +++ b/usr.bin/tmux/job.c @@ -1,4 +1,4 @@ -/* $OpenBSD: job.c,v 1.41 2016/10/10 21:29:23 nicm Exp $ */ +/* $OpenBSD: job.c,v 1.42 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -53,12 +53,7 @@ job_run(const char *cmd, struct session *s, const char *cwd, if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0) return (NULL); - env = environ_create(); - environ_copy(global_environ, env); - if (s != NULL) - environ_copy(s->environ, env); - server_fill_environ(s, env); - + env = environ_for_session(s); switch (pid = fork()) { case -1: environ_free(env); diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index f769019f47c..f5957119c8f 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.104 2017/02/09 15:04:53 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.105 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -33,24 +33,6 @@ static void server_callback_identify(int, short, void *); static void server_destroy_session_group(struct session *); void -server_fill_environ(struct session *s, struct environ *env) -{ - const char *term; - u_int idx; - long pid; - - if (s != NULL) { - term = options_get_string(global_options, "default-terminal"); - environ_set(env, "TERM", "%s", term); - - idx = s->id; - } else - idx = (u_int)-1; - pid = getpid(); - environ_set(env, "TMUX", "%s,%ld,%u", socket_path, pid, idx); -} - -void server_redraw_client(struct client *c) { c->flags |= CLIENT_REDRAW; diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index c4ca9b40590..64d3a8988d3 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.72 2017/02/09 15:04:53 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.73 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -355,16 +355,12 @@ session_new(struct session *s, const char *name, int argc, char **argv, } wl->session = s; - env = environ_create(); - environ_copy(global_environ, env); - environ_copy(s->environ, env); - server_fill_environ(s, env); - shell = options_get_string(s->options, "default-shell"); if (*shell == '\0' || areshell(shell)) shell = _PATH_BSHELL; hlimit = options_get_number(s->options, "history-limit"); + env = environ_for_session(s); w = window_create_spawn(name, argc, argv, path, shell, cwd, env, s->tio, s->sx, s->sy, hlimit, cause); if (w == NULL) { @@ -373,8 +369,8 @@ session_new(struct session *s, const char *name, int argc, char **argv, return (NULL); } winlink_set_window(wl, w); - notify_session_window("window-linked", s, w); environ_free(env); + notify_session_window("window-linked", s, w); session_group_synchronize_from(s); return (wl); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 0d628f848f5..cbcea93e27d 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.730 2017/03/08 13:36:12 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.731 2017/03/09 17:02:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1613,6 +1613,7 @@ void environ_unset(struct environ *, const char *); void environ_update(struct options *, struct environ *, struct environ *); void environ_push(struct environ *); void environ_log(struct environ *, const char *); +struct environ *environ_for_session(struct session *); /* tty.c */ void tty_create_log(void); @@ -1838,7 +1839,6 @@ char *server_client_get_path(struct client *, const char *); const char *server_client_get_cwd(struct client *); /* server-fn.c */ -void server_fill_environ(struct session *, struct environ *); void server_redraw_client(struct client *); void server_status_client(struct client *); void server_redraw_session(struct session *); |