From cb0bf6a043377974bb40ace3c9782822c63b7ded Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Sun, 8 Nov 2009 22:59:53 +0000 Subject: [PATCH] Sync OpenBSD patchset 496: Switch window pane pipe redirect fd over to a bufferevent. --- cmd-pipe-pane.c | 27 ++++++++++++++++++++++----- server-window.c | 20 +------------------- tmux.h | 5 ++--- window.c | 9 ++++----- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index 3492d083..b33086d3 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-pipe-pane.c,v 1.4 2009-11-08 22:40:36 tcunha Exp $ */ +/* $Id: cmd-pipe-pane.c,v 1.5 2009-11-08 22:59:53 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -31,6 +32,8 @@ int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *); +void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *); + const struct cmd_entry cmd_pipe_pane_entry = { "pipe-pane", "pipep", CMD_TARGET_PANE_USAGE "[-o] [command]", @@ -55,7 +58,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) /* Destroy the old pipe. */ old_fd = wp->pipe_fd; if (wp->pipe_fd != -1) { - buffer_destroy(wp->pipe_buf); + bufferevent_free(wp->pipe_event); close(wp->pipe_fd); wp->pipe_fd = -1; } @@ -74,8 +77,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) return (0); /* Open the new pipe. */ - if (pipe(pipe_fd) != 0) { - ctx->error(ctx, "pipe error: %s", strerror(errno)); + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) { + ctx->error(ctx, "socketpair error: %s", strerror(errno)); return (-1); } @@ -109,9 +112,12 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) close(pipe_fd[1]); wp->pipe_fd = pipe_fd[0]; - wp->pipe_buf = buffer_create(BUFSIZ); wp->pipe_off = BUFFER_USED(wp->in); + wp->pipe_event = bufferevent_new(wp->pipe_fd, + NULL, NULL, cmd_pipe_pane_error_callback, wp); + bufferevent_enable(wp->pipe_event, EV_WRITE); + if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1) fatal("fcntl failed"); if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1) @@ -123,3 +129,14 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx) return (0); } + +void +cmd_pipe_pane_error_callback( + unused struct bufferevent *bufev, unused short what, void *data) +{ + struct window_pane *wp = data; + + bufferevent_free(wp->pipe_event); + close(wp->pipe_fd); + wp->pipe_fd = -1; +} diff --git a/server-window.c b/server-window.c index b4ebcf0a..6e2be037 100644 --- a/server-window.c +++ b/server-window.c @@ -1,4 +1,4 @@ -/* $Id: server-window.c,v 1.7 2009-11-08 22:58:37 tcunha Exp $ */ +/* $Id: server-window.c,v 1.8 2009-11-08 22:59:53 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -55,16 +55,6 @@ server_window_prepare(void) event_set(&wp->event, wp->fd, events, server_window_callback, wp); event_add(&wp->event, NULL); - - if (wp->pipe_fd == -1) - continue; - events = 0; - if (BUFFER_USED(wp->pipe_buf) > 0) - events |= EV_WRITE; - event_del(&wp->pipe_event); - event_set(&wp->pipe_event, - wp->pipe_fd, events, server_window_callback, wp); - event_add(&wp->pipe_event, NULL); } } } @@ -110,14 +100,6 @@ server_window_callback(int fd, short events, void *data) } else window_pane_parse(wp); } - - if (fd == wp->pipe_fd) { - if (buffer_poll(fd, events, NULL, wp->pipe_buf) != 0) { - buffer_destroy(wp->pipe_buf); - close(wp->pipe_fd); - wp->pipe_fd = -1; - } - } } /* Window functions that need to happen every loop. */ diff --git a/tmux.h b/tmux.h index bbba4c3c..a6664ce3 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.499 2009-11-08 22:58:37 tcunha Exp $ */ +/* $Id: tmux.h,v 1.500 2009-11-08 22:59:53 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -804,8 +804,7 @@ struct window_pane { struct input_ctx ictx; int pipe_fd; - struct event pipe_event; - struct buffer *pipe_buf; + struct bufferevent *pipe_event; size_t pipe_off; struct screen *screen; diff --git a/window.c b/window.c index a9995399..15a2293d 100644 --- a/window.c +++ b/window.c @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.118 2009-11-08 22:40:36 tcunha Exp $ */ +/* $Id: window.c,v 1.119 2009-11-08 22:59:53 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -424,8 +424,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp->sy = sy; wp->pipe_fd = -1; - wp->pipe_buf = NULL; wp->pipe_off = 0; + wp->pipe_event = NULL; wp->saved_grid = NULL; @@ -451,9 +451,8 @@ window_pane_destroy(struct window_pane *wp) grid_destroy(wp->saved_grid); if (wp->pipe_fd != -1) { - buffer_destroy(wp->pipe_buf); close(wp->pipe_fd); - event_del(&wp->pipe_event); + bufferevent_free(wp->pipe_event); } buffer_destroy(wp->in); @@ -646,7 +645,7 @@ window_pane_parse(struct window_pane *wp) new_size = BUFFER_USED(wp->in) - wp->pipe_off; if (wp->pipe_fd != -1 && new_size > 0) - buffer_write(wp->pipe_buf, BUFFER_OUT(wp->in), new_size); + bufferevent_write(wp->pipe_event, BUFFER_OUT(wp->in), new_size); input_parse(wp);