Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2017-03-09 18:01:16 +00:00
commit c5bdae466e
10 changed files with 89 additions and 99 deletions

View File

@ -61,7 +61,7 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
else
c->identify_callback_data = xstrdup("select-pane -t '%%'");
server_set_identify(c);
server_client_set_identify(c);
return (CMD_RETURN_NORMAL);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -70,11 +70,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') {
@ -147,9 +142,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);
@ -160,8 +159,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;
@ -185,7 +182,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);

View File

@ -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);
}

7
job.c
View File

@ -52,12 +52,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);

View File

@ -47,6 +47,49 @@ static void server_client_dispatch_command(struct client *, struct imsg *);
static void server_client_dispatch_identify(struct client *, struct imsg *);
static void server_client_dispatch_shell(struct client *);
/* Idenfity mode callback. */
static void
server_client_callback_identify(__unused int fd, __unused short events, void *data)
{
server_client_clear_identify(data, NULL);
}
/* Set identify mode on client. */
void
server_client_set_identify(struct client *c)
{
struct timeval tv;
int delay;
delay = options_get_number(c->session->options, "display-panes-time");
tv.tv_sec = delay / 1000;
tv.tv_usec = (delay % 1000) * 1000L;
if (event_initialized(&c->identify_timer))
evtimer_del(&c->identify_timer);
evtimer_set(&c->identify_timer, server_client_callback_identify, c);
evtimer_add(&c->identify_timer, &tv);
c->flags |= CLIENT_IDENTIFY;
c->tty.flags |= (TTY_FREEZE|TTY_NOCURSOR);
server_redraw_client(c);
}
/* Clear identify mode on client. */
void
server_client_clear_identify(struct client *c, struct window_pane *wp)
{
if (~c->flags & CLIENT_IDENTIFY)
return;
c->flags &= ~CLIENT_IDENTIFY;
if (c->identify_callback != NULL)
c->identify_callback(c, wp);
c->tty.flags &= ~(TTY_FREEZE|TTY_NOCURSOR);
server_redraw_client(c);
}
/* Check if this client is inside this server. */
int
server_client_check_nested(struct client *c)
@ -190,7 +233,7 @@ server_client_lost(struct client *c)
c->flags |= CLIENT_DEAD;
server_clear_identify(c, NULL);
server_client_clear_identify(c, NULL);
status_prompt_clear(c);
status_message_clear(c);
@ -758,14 +801,14 @@ server_client_handle_key(struct client *c, key_code key)
wp = window_pane_at_index(w, key - '0');
if (wp != NULL && !window_pane_visible(wp))
wp = NULL;
server_clear_identify(c, wp);
server_client_clear_identify(c, wp);
return;
}
/* Handle status line. */
if (!(c->flags & CLIENT_READONLY)) {
status_message_clear(c);
server_clear_identify(c, NULL);
server_client_clear_identify(c, NULL);
}
if (c->prompt_string != NULL) {
if (c->flags & CLIENT_READONLY)

View File

@ -27,27 +27,8 @@
#include "tmux.h"
static struct session *server_next_session(struct session *);
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)
{
@ -424,46 +405,6 @@ server_check_unattached(void)
}
}
void
server_set_identify(struct client *c)
{
struct timeval tv;
int delay;
delay = options_get_number(c->session->options, "display-panes-time");
tv.tv_sec = delay / 1000;
tv.tv_usec = (delay % 1000) * 1000L;
if (event_initialized(&c->identify_timer))
evtimer_del(&c->identify_timer);
evtimer_set(&c->identify_timer, server_callback_identify, c);
evtimer_add(&c->identify_timer, &tv);
c->flags |= CLIENT_IDENTIFY;
c->tty.flags |= (TTY_FREEZE|TTY_NOCURSOR);
server_redraw_client(c);
}
void
server_clear_identify(struct client *c, struct window_pane *wp)
{
if (~c->flags & CLIENT_IDENTIFY)
return;
c->flags &= ~CLIENT_IDENTIFY;
if (c->identify_callback != NULL)
c->identify_callback(c, wp);
c->tty.flags &= ~(TTY_FREEZE|TTY_NOCURSOR);
server_redraw_client(c);
}
static void
server_callback_identify(__unused int fd, __unused short events, void *data)
{
server_clear_identify(data, NULL);
}
/* Set stdin callback. */
int
server_set_stdin_callback(struct client *c, void (*cb)(struct client *, int,

View File

@ -354,16 +354,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) {
@ -372,8 +368,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);

6
tmux.h
View File

@ -1617,6 +1617,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);
@ -1822,6 +1823,8 @@ void server_update_socket(void);
void server_add_accept(int);
/* server-client.c */
void server_client_set_identify(struct client *);
void server_client_clear_identify(struct client *, struct window_pane *);
void server_client_set_key_table(struct client *, const char *);
const char *server_client_get_key_table(struct client *);
int server_client_is_default_key_table(struct client *);
@ -1842,7 +1845,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 *);
@ -1862,8 +1864,6 @@ void server_unlink_window(struct session *, struct winlink *);
void server_destroy_pane(struct window_pane *, int);
void server_destroy_session(struct session *);
void server_check_unattached(void);
void server_set_identify(struct client *);
void server_clear_identify(struct client *, struct window_pane *);
int server_set_stdin_callback(struct client *, void (*)(struct client *,
int, void *), void *, char **);
void server_unzoom_window(struct window *);