version 1.3, 2009/11/04 20:50:11 |
version 1.4, 2009/11/04 22:02:38 |
|
|
*/ |
*/ |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <sys/socket.h> |
|
|
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
|
|
|
|
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *); |
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 = { |
const struct cmd_entry cmd_pipe_pane_entry = { |
"pipe-pane", "pipep", |
"pipe-pane", "pipep", |
CMD_TARGET_PANE_USAGE "[-o] [command]", |
CMD_TARGET_PANE_USAGE "[-o] [command]", |
|
|
/* Destroy the old pipe. */ |
/* Destroy the old pipe. */ |
old_fd = wp->pipe_fd; |
old_fd = wp->pipe_fd; |
if (wp->pipe_fd != -1) { |
if (wp->pipe_fd != -1) { |
buffer_destroy(wp->pipe_buf); |
bufferevent_free(wp->pipe_event); |
close(wp->pipe_fd); |
close(wp->pipe_fd); |
wp->pipe_fd = -1; |
wp->pipe_fd = -1; |
} |
} |
|
|
return (0); |
return (0); |
|
|
/* Open the new pipe. */ |
/* Open the new pipe. */ |
if (pipe(pipe_fd) != 0) { |
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) { |
ctx->error(ctx, "pipe error: %s", strerror(errno)); |
ctx->error(ctx, "socketpair error: %s", strerror(errno)); |
return (-1); |
return (-1); |
} |
} |
|
|
|
|
close(pipe_fd[1]); |
close(pipe_fd[1]); |
|
|
wp->pipe_fd = pipe_fd[0]; |
wp->pipe_fd = pipe_fd[0]; |
wp->pipe_buf = buffer_create(BUFSIZ); |
|
wp->pipe_off = BUFFER_USED(wp->in); |
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) |
if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1) |
fatal("fcntl failed"); |
fatal("fcntl failed"); |
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1) |
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1) |
|
|
} |
} |
|
|
return (0); |
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; |
} |
} |