mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Do not close panes until process has exited and any outstanding data
has been written to the pipe-pane event if there is one. GitHub issue 991.
This commit is contained in:
parent
42285ac989
commit
28687f2d55
@ -35,6 +35,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 = {
|
||||
@ -68,6 +69,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. */
|
||||
@ -131,8 +137,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);
|
||||
@ -142,13 +149,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);
|
||||
}
|
||||
|
7
server.c
7
server.c
@ -406,7 +406,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;
|
||||
}
|
||||
}
|
||||
|
4
tmux.h
4
tmux.h
@ -768,6 +768,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;
|
||||
@ -2133,6 +2135,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 **);
|
||||
@ -2154,7 +2157,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 *);
|
||||
|
19
window.c
19
window.c
@ -388,6 +388,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)
|
||||
{
|
||||
@ -1000,7 +1013,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
|
||||
|
Loading…
Reference in New Issue
Block a user