summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-11-14 09:41:08 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-11-14 09:41:08 +0000
commit9b9826957255134c5f7ef1fa9b9d991ec0f5ff6c (patch)
tree5619aef183b2ee1cb62ac784569033e8b69ac87e
parentb4844eaa1fb4ee6018c184b5aa29ece47e00a66b (diff)
Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.
-rw-r--r--usr.bin/tmux/client.c6
-rw-r--r--usr.bin/tmux/cmd-capture-pane.c4
-rw-r--r--usr.bin/tmux/cmd-load-buffer.c4
-rw-r--r--usr.bin/tmux/cmd-queue.c8
-rw-r--r--usr.bin/tmux/cmd-save-buffer.c4
-rw-r--r--usr.bin/tmux/control.c6
-rw-r--r--usr.bin/tmux/server-client.c92
-rw-r--r--usr.bin/tmux/server-fn.c46
-rw-r--r--usr.bin/tmux/server.c4
-rw-r--r--usr.bin/tmux/tmux.c4
-rw-r--r--usr.bin/tmux/tmux.h6
11 files changed, 112 insertions, 72 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c
index 73a46204f78..61a580b730a 100644
--- a/usr.bin/tmux/client.c
+++ b/usr.bin/tmux/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.103 2015/10/31 13:43:38 nicm Exp $ */
+/* $OpenBSD: client.c,v 1.104 2015/11/14 09:41:06 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -289,7 +289,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
*
* "sendfd" is dropped later in client_dispatch_wait().
*/
- if (pledge("stdio unix sendfd proc exec tty", NULL) != 0)
+ if (0 && pledge("stdio unix sendfd proc exec tty", NULL) != 0)
fatal("pledge failed");
/* Free stuff that is not used in the client. */
@@ -541,7 +541,7 @@ client_dispatch_wait(struct imsg *imsg)
* get the first message from the server.
*/
if (!pledge_applied) {
- if (pledge("stdio unix proc exec tty", NULL) != 0)
+ if (0 && pledge("stdio unix proc exec tty", NULL) != 0)
fatal("pledge failed");
pledge_applied = 1;
};
diff --git a/usr.bin/tmux/cmd-capture-pane.c b/usr.bin/tmux/cmd-capture-pane.c
index 378ed74f6e3..808c93db060 100644
--- a/usr.bin/tmux/cmd-capture-pane.c
+++ b/usr.bin/tmux/cmd-capture-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-capture-pane.c,v 1.34 2015/10/16 07:43:29 nicm Exp $ */
+/* $OpenBSD: cmd-capture-pane.c,v 1.35 2015/11/14 09:41:06 nicm Exp $ */
/*
* Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
@@ -203,7 +203,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
free(buf);
if (args_has(args, 'P') && len > 0)
evbuffer_add(c->stdout_data, "\n", 1);
- server_push_stdout(c);
+ server_client_push_stdout(c);
} else {
bufname = NULL;
if (args_has(args, 'b'))
diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c
index a30536e46b0..4b26c338274 100644
--- a/usr.bin/tmux/cmd-load-buffer.c
+++ b/usr.bin/tmux/cmd-load-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-load-buffer.c,v 1.38 2015/11/12 11:10:50 nicm Exp $ */
+/* $OpenBSD: cmd-load-buffer.c,v 1.39 2015/11/14 09:41:06 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -160,7 +160,7 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
free(saved);
}
evbuffer_add_printf(c->stderr_data, "%s", cause);
- server_push_stderr(c);
+ server_client_push_stderr(c);
free(pdata);
free(cause);
}
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index c70ecab8825..ec94f839723 100644
--- a/usr.bin/tmux/cmd-queue.c
+++ b/usr.bin/tmux/cmd-queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-queue.c,v 1.28 2015/11/12 11:10:50 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.29 2015/11/14 09:41:06 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -85,7 +85,7 @@ cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
} else
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
evbuffer_add(c->stdout_data, "\n", 1);
- server_push_stdout(c);
+ server_client_push_stdout(c);
} else {
w = c->session->curw->window;
if (w->active->mode != &window_copy_mode) {
@@ -125,7 +125,7 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
}
evbuffer_add(c->stderr_data, msg, msglen);
evbuffer_add(c->stderr_data, "\n", 1);
- server_push_stderr(c);
+ server_client_push_stderr(c);
c->retval = 1;
} else {
*msg = toupper((u_char) *msg);
@@ -146,7 +146,7 @@ cmdq_guard(struct cmd_q *cmdq, const char *guard, int flags)
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
(long) cmdq->time, cmdq->number, flags);
- server_push_stdout(c);
+ server_client_push_stdout(c);
}
/* Add command list to queue and begin processing if needed. */
diff --git a/usr.bin/tmux/cmd-save-buffer.c b/usr.bin/tmux/cmd-save-buffer.c
index 931840367ee..75cdcc9b31f 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.33 2015/11/10 22:33:47 nicm Exp $ */
+/* $OpenBSD: cmd-save-buffer.c,v 1.34 2015/11/14 09:41:06 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -130,7 +130,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
do_stdout:
evbuffer_add(c->stdout_data, bufdata, bufsize);
- server_push_stdout(c);
+ server_client_push_stdout(c);
return (CMD_RETURN_NORMAL);
do_print:
diff --git a/usr.bin/tmux/control.c b/usr.bin/tmux/control.c
index 99996f4b6f9..dc689bb5352 100644
--- a/usr.bin/tmux/control.c
+++ b/usr.bin/tmux/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.14 2015/04/19 21:34:21 nicm Exp $ */
+/* $OpenBSD: control.c,v 1.15 2015/11/14 09:41:06 nicm Exp $ */
/*
* Copyright (c) 2012 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -37,7 +37,7 @@ control_write(struct client *c, const char *fmt, ...)
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
- server_push_stdout(c);
+ server_client_push_stdout(c);
}
/* Write a buffer, adding a terminal newline. Empties buffer. */
@@ -46,7 +46,7 @@ control_write_buffer(struct client *c, struct evbuffer *buffer)
{
evbuffer_add_buffer(c->stdout_data, buffer);
evbuffer_add(c->stdout_data, "\n", 1);
- server_push_stdout(c);
+ server_client_push_stdout(c);
}
/* Control input callback. Read lines and fire commands. */
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index ce971a62c14..7314a77dc0d 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.168 2015/11/12 11:05:34 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.169 2015/11/14 09:41:06 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1035,9 +1035,6 @@ server_client_dispatch(struct imsg *imsg, void *arg)
server_client_dispatch_shell(c);
break;
}
-
- server_push_stdout(c);
- server_push_stderr(c);
}
/* Handle command message. */
@@ -1214,3 +1211,90 @@ server_client_dispatch_shell(struct client *c)
proc_kill_peer(c->peer);
}
+
+/* Event callback to push more stdout data if any left. */
+static void
+server_client_stdout_cb(unused int fd, unused short events, void *arg)
+{
+ struct client *c = arg;
+
+ if (~c->flags & CLIENT_DEAD)
+ server_client_push_stdout(c);
+ server_client_unref(c);
+}
+
+/* Push stdout to client if possible. */
+void
+server_client_push_stdout(struct client *c)
+{
+ struct msg_stdout_data data;
+ size_t sent, left;
+
+ left = EVBUFFER_LENGTH(c->stdout_data);
+ while (left != 0) {
+ sent = left;
+ if (sent > sizeof data.data)
+ sent = sizeof data.data;
+ memcpy(data.data, EVBUFFER_DATA(c->stdout_data), sent);
+ data.size = sent;
+
+ if (proc_send(c->peer, MSG_STDOUT, -1, &data, sizeof data) != 0)
+ break;
+ evbuffer_drain(c->stdout_data, sent);
+
+ left = EVBUFFER_LENGTH(c->stdout_data);
+ log_debug("%s: client %p, sent %zu, left %zu", __func__, c,
+ sent, left);
+ }
+ if (left != 0) {
+ c->references++;
+ event_once(-1, EV_TIMEOUT, server_client_stdout_cb, c, NULL);
+ log_debug("%s: client %p, queued", __func__, c);
+ }
+}
+
+/* Event callback to push more stderr data if any left. */
+static void
+server_client_stderr_cb(unused int fd, unused short events, void *arg)
+{
+ struct client *c = arg;
+
+ if (~c->flags & CLIENT_DEAD)
+ server_client_push_stderr(c);
+ server_client_unref(c);
+}
+
+/* Push stderr to client if possible. */
+void
+server_client_push_stderr(struct client *c)
+{
+ struct msg_stderr_data data;
+ size_t sent, left;
+
+ if (c->stderr_data == c->stdout_data) {
+ server_client_push_stdout(c);
+ return;
+ }
+
+ left = EVBUFFER_LENGTH(c->stderr_data);
+ while (left != 0) {
+ sent = left;
+ if (sent > sizeof data.data)
+ sent = sizeof data.data;
+ memcpy(data.data, EVBUFFER_DATA(c->stderr_data), sent);
+ data.size = sent;
+
+ if (proc_send(c->peer, MSG_STDERR, -1, &data, sizeof data) != 0)
+ break;
+ evbuffer_drain(c->stderr_data, sent);
+
+ left = EVBUFFER_LENGTH(c->stderr_data);
+ log_debug("%s: client %p, sent %zu, left %zu", __func__, c,
+ sent, left);
+ }
+ if (left != 0) {
+ c->references++;
+ event_once(-1, EV_TIMEOUT, server_client_stderr_cb, c, NULL);
+ log_debug("%s: client %p, queued", __func__, c);
+ }
+}
diff --git a/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c
index d4ba54d6843..dc9edfdf035 100644
--- a/usr.bin/tmux/server-fn.c
+++ b/usr.bin/tmux/server-fn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-fn.c,v 1.91 2015/10/27 15:58:42 nicm Exp $ */
+/* $OpenBSD: server-fn.c,v 1.92 2015/11/14 09:41:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -450,50 +450,6 @@ server_callback_identify(unused int fd, unused short events, void *data)
server_clear_identify(c);
}
-/* Push stdout to client if possible. */
-void
-server_push_stdout(struct client *c)
-{
- struct msg_stdout_data data;
- size_t size;
-
- size = EVBUFFER_LENGTH(c->stdout_data);
- if (size == 0)
- return;
- if (size > sizeof data.data)
- size = sizeof data.data;
-
- memcpy(data.data, EVBUFFER_DATA(c->stdout_data), size);
- data.size = size;
-
- if (proc_send(c->peer, MSG_STDOUT, -1, &data, sizeof data) == 0)
- evbuffer_drain(c->stdout_data, size);
-}
-
-/* Push stderr to client if possible. */
-void
-server_push_stderr(struct client *c)
-{
- struct msg_stderr_data data;
- size_t size;
-
- if (c->stderr_data == c->stdout_data) {
- server_push_stdout(c);
- return;
- }
- size = EVBUFFER_LENGTH(c->stderr_data);
- if (size == 0)
- return;
- if (size > sizeof data.data)
- size = sizeof data.data;
-
- memcpy(data.data, EVBUFFER_DATA(c->stderr_data), size);
- data.size = size;
-
- if (proc_send(c->peer, MSG_STDERR, -1, &data, sizeof data) == 0)
- evbuffer_drain(c->stderr_data, size);
-}
-
/* Set stdin callback. */
int
server_set_stdin_callback(struct client *c, void (*cb)(struct client *, int,
diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c
index 8b2166668f3..137bad27d3d 100644
--- a/usr.bin/tmux/server.c
+++ b/usr.bin/tmux/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.147 2015/11/12 12:19:57 nicm Exp $ */
+/* $OpenBSD: server.c,v 1.148 2015/11/14 09:41:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -175,7 +175,7 @@ server_start(struct event_base *base, int lockfd, char *lockfile)
if (debug_level > 3)
tty_create_log();
- if (pledge("stdio rpath wpath cpath fattr unix recvfd proc exec tty "
+ if (0 && pledge("stdio rpath wpath cpath fattr unix recvfd proc exec tty "
"ps", NULL) != 0)
fatal("pledge failed");
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 55c4b82b981..5cdbd0b56c7 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.152 2015/11/12 11:24:08 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.153 2015/11/14 09:41:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -255,7 +255,7 @@ main(int argc, char **argv)
if (shell_cmd != NULL && argc != 0)
usage();
- if (pledge("stdio rpath wpath cpath flock fattr unix sendfd recvfd "
+ if (0 && pledge("stdio rpath wpath cpath flock fattr unix sendfd recvfd "
"proc exec tty ps", NULL) != 0)
err(1, "pledge");
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index a0792454b50..623e72bc1bc 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.576 2015/11/13 08:09:28 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.577 2015/11/14 09:41:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1781,6 +1781,8 @@ int server_client_open(struct client *, char **);
void server_client_unref(struct client *);
void server_client_lost(struct client *);
void server_client_loop(void);
+void server_client_push_stdout(struct client *);
+void server_client_push_stderr(struct client *);
/* server-fn.c */
void server_fill_environ(struct session *, struct environ *);
@@ -1806,8 +1808,6 @@ void server_destroy_session(struct session *);
void server_check_unattached(void);
void server_set_identify(struct client *);
void server_clear_identify(struct client *);
-void server_push_stdout(struct client *);
-void server_push_stderr(struct client *);
int server_set_stdin_callback(struct client *, void (*)(struct client *,
int, void *), void *, char **);
void server_unzoom_window(struct window *);