summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-save-buffer.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2010-07-24 20:11:59 +0000
committernicm <nicm@openbsd.org>2010-07-24 20:11:59 +0000
commit636a2c4a12deeb557e680184cefc52b4c791f1b8 (patch)
tree0198aaf95643915c543180b6199ab8b53c0d28fd /usr.bin/tmux/cmd-save-buffer.c
parentConvert PCI addresses to proper 64-bit physical addresses. (diff)
downloadwireguard-openbsd-636a2c4a12deeb557e680184cefc52b4c791f1b8.tar.xz
wireguard-openbsd-636a2c4a12deeb557e680184cefc52b4c791f1b8.zip
When changing so that the client passes its stdout and stderr as well as
stdin up to the server, I forgot one essential point - the tmux server could now be both the producer and consumer. This happens when tmux is run inside tmux, as well as when piping tmux commands together. So, using stdio(3) was a bad idea - if sufficient data was written, this could block in write(2). When that happened and the server was both producer and consumer, it deadlocks. Change to use libevent bufferevents for the client stdin, stdout and stderr instead. This is trivial enough for output but requires a callback mechanism to trigger when stdin is finished. This relies on the underlying polling mechanism for libevent to work with whatever devices to which the user could redirect stdin, stdout or stderr, hence the change to use poll(2) over kqueue(2) for tmux.
Diffstat (limited to 'usr.bin/tmux/cmd-save-buffer.c')
-rw-r--r--usr.bin/tmux/cmd-save-buffer.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c
index d25f1402f12..318ed522ded 100644
--- a/usr.bin/tmux/cmd-save-buffer.c
+++ b/usr.bin/tmux/cmd-save-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-save-buffer.c,v 1.7 2010/06/28 22:10:42 nicm Exp $ */
+/* $OpenBSD: cmd-save-buffer.c,v 1.8 2010/07/24 20:11:59 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -47,8 +47,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
struct cmd_buffer_data *data = self->data;
struct session *s;
struct paste_buffer *pb;
- mode_t mask;
- FILE *f, *close_f;
+ mode_t mask;
+ FILE *f;
if ((s = cmd_find_session(ctx, data->target)) == NULL)
return (-1);
@@ -70,8 +70,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
ctx->error(ctx, "%s: can't write to stdout", data->arg);
return (-1);
}
- f = ctx->cmdclient->stdout_file;
- close_f = NULL;
+ bufferevent_write(
+ ctx->cmdclient->stdout_event, pb->data, pb->size);
} else {
mask = umask(S_IRWXG | S_IRWXO);
if (cmd_check_flag(data->chflags, 'a'))
@@ -83,17 +83,13 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
return (-1);
}
- close_f = f;
- }
-
- if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
- ctx->error(ctx, "%s: fwrite error", data->arg);
- fclose(f);
- return (-1);
+ if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
+ ctx->error(ctx, "%s: fwrite error", data->arg);
+ fclose(f);
+ return (-1);
+ }
+ fclose(f);
}
- if (close_f != NULL)
- fclose(close_f);
-
return (0);
}