summaryrefslogtreecommitdiffstats
path: root/cmd-pipe-pane.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-11-04 22:02:38 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-11-04 22:02:38 +0000
commit91ad830c8863ab66038226f9e16bc87cbbdb6d95 (patch)
tree46c71a1d7cd642eb7d0ed3ba2fcdda1071a416b4 /cmd-pipe-pane.c
parent7342615c7ddd9b99820bd9c03fda2afe7bc868d3 (diff)
Switch window pane pipe redirect fd over to a bufferevent.
Diffstat (limited to 'cmd-pipe-pane.c')
-rw-r--r--cmd-pipe-pane.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c
index 10cd3323..4565174e 100644
--- a/cmd-pipe-pane.c
+++ b/cmd-pipe-pane.c
@@ -17,6 +17,7 @@
*/
#include <sys/types.h>
+#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
@@ -32,6 +33,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]",
@@ -56,7 +59,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;
}
@@ -75,8 +78,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);
}
@@ -110,9 +113,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)
@@ -124,3 +130,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;
+}