Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2017-07-03 10:01:14 +01:00
commit 4e01036cb6
5 changed files with 53 additions and 6 deletions

View File

@ -34,6 +34,7 @@
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
static void cmd_pipe_pane_write_callback(struct bufferevent *, void *);
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
const struct cmd_entry cmd_pipe_pane_entry = {
@ -67,6 +68,11 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
bufferevent_free(wp->pipe_event);
close(wp->pipe_fd);
wp->pipe_fd = -1;
if (window_pane_destroy_ready(wp)) {
server_destroy_pane(wp, 1);
return (CMD_RETURN_NORMAL);
}
}
/* If no pipe command, that is enough. */
@ -130,8 +136,9 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
wp->pipe_fd = pipe_fd[0];
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
wp->pipe_event = bufferevent_new(wp->pipe_fd,
NULL, NULL, cmd_pipe_pane_error_callback, wp);
wp->pipe_event = bufferevent_new(wp->pipe_fd, NULL,
cmd_pipe_pane_write_callback, cmd_pipe_pane_error_callback,
wp);
bufferevent_enable(wp->pipe_event, EV_WRITE);
setblocking(wp->pipe_fd, 0);
@ -141,13 +148,28 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
}
}
static void
cmd_pipe_pane_write_callback(__unused struct bufferevent *bufev, void *data)
{
struct window_pane *wp = data;
log_debug("%%%u pipe empty", wp->id);
if (window_pane_destroy_ready(wp))
server_destroy_pane(wp, 1);
}
static void
cmd_pipe_pane_error_callback(__unused struct bufferevent *bufev,
__unused short what, void *data)
{
struct window_pane *wp = data;
log_debug("%%%u pipe error", wp->id);
bufferevent_free(wp->pipe_event);
close(wp->pipe_fd);
wp->pipe_fd = -1;
if (window_pane_destroy_ready(wp))
server_destroy_pane(wp, 1);
}

View File

@ -405,7 +405,12 @@ server_child_exited(pid_t pid, int status)
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp->pid == pid) {
wp->status = status;
server_destroy_pane(wp, 1);
log_debug("%%%u exited", wp->id);
wp->flags |= PANE_EXITED;
if (window_pane_destroy_ready(wp))
server_destroy_pane(wp, 1);
break;
}
}

3
tmux.c
View File

@ -193,7 +193,8 @@ main(int argc, char **argv)
int opt, flags, keys;
const struct options_table_entry *oe;
if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) {
if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL &&
setlocale(LC_CTYPE, "C.UTF-8") == NULL) {
if (setlocale(LC_CTYPE, "") == NULL)
errx(1, "invalid LC_ALL, LC_CTYPE or LANG");
s = nl_langinfo(CODESET);

4
tmux.h
View File

@ -772,6 +772,8 @@ struct window_pane {
#define PANE_FOCUSPUSH 0x20
#define PANE_INPUTOFF 0x40
#define PANE_CHANGED 0x80
#define PANE_ERROR 0x100
#define PANE_EXITED 0x200
int argc;
char **argv;
@ -2137,6 +2139,7 @@ u_int window_count_panes(struct window *);
void window_destroy_panes(struct window *);
struct window_pane *window_pane_find_by_id_str(const char *);
struct window_pane *window_pane_find_by_id(u_int);
int window_pane_destroy_ready(struct window_pane *);
int window_pane_spawn(struct window_pane *, int, char **,
const char *, const char *, const char *, struct environ *,
struct termios *, char **);
@ -2158,7 +2161,6 @@ void window_pane_key(struct window_pane *, struct client *,
int window_pane_outside(struct window_pane *);
int window_pane_visible(struct window_pane *);
u_int window_pane_search(struct window_pane *, const char *);
const char *window_printable_flags(struct winlink *);
struct window_pane *window_pane_find_up(struct window_pane *);
struct window_pane *window_pane_find_down(struct window_pane *);

View File

@ -387,6 +387,19 @@ window_destroy(struct window *w)
free(w);
}
int
window_pane_destroy_ready(struct window_pane *wp)
{
if (wp->pipe_fd != -1 && EVBUFFER_LENGTH(wp->pipe_event->output) != 0)
return (0);
if (~wp->flags & PANE_EXITED)
return (0);
if (~wp->flags & PANE_ERROR)
return (0);
return (1);
}
void
window_add_ref(struct window *w, const char *from)
{
@ -1014,7 +1027,11 @@ window_pane_error_callback(__unused struct bufferevent *bufev,
{
struct window_pane *wp = data;
server_destroy_pane(wp, 1);
log_debug("%%%u error", wp->id);
wp->flags |= PANE_ERROR;
if (window_pane_destroy_ready(wp))
server_destroy_pane(wp, 1);
}
void