summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-queue.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-12-12 11:39:57 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-12-12 11:39:57 +0000
commit26afc37a415118f304bd257969301773a0bc74fb (patch)
treeb646def5c74316209bf3eeb049cf42a9488bb607 /usr.bin/tmux/cmd-queue.c
parent7ff24f14fc5aa2876f20cae2c52edf2cbb12951a (diff)
Rewrite the code for reading and writing files. Now, if the client is
not attached, the server process asks it to open the file, similar to how works for stdin, stdout, stderr. This makes special files like /dev/fd/X work (used by some shells). stdin, stdout and stderr and control mode are now just special cases of the same mechanism. This will also make it easier to use for other commands that read files such as source-file.
Diffstat (limited to 'usr.bin/tmux/cmd-queue.c')
-rw-r--r--usr.bin/tmux/cmd-queue.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c
index 30f3b8e60b3..a66894a7811 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.75 2019/09/10 07:50:33 nicm Exp $ */
+/* $OpenBSD: cmd-queue.c,v 1.76 2019/12/12 11:39:56 nicm Exp $ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -475,13 +475,11 @@ void
cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
{
struct client *c = item->client;
+ long t = item->time;
+ u_int number = item->number;
- if (c == NULL || !(c->flags & CLIENT_CONTROL))
- return;
-
- evbuffer_add_printf(c->stdout_data, "%%%s %ld %u %d\n", guard,
- (long)item->time, item->number, flags);
- server_client_push_stdout(c);
+ if (c != NULL && (c->flags & CLIENT_CONTROL))
+ file_print(c, "%%%s %ld %u %d\n", guard, t, number, flags);
}
/* Show message from command. */
@@ -495,20 +493,20 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...)
char *tmp, *msg;
va_start(ap, fmt);
+ xvasprintf(&msg, fmt, ap);
+ va_end(ap);
+
+ log_debug("%s: %s", __func__, msg);
if (c == NULL)
/* nothing */;
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
if (~c->flags & CLIENT_UTF8) {
- xvasprintf(&tmp, fmt, ap);
+ tmp = msg;
msg = utf8_sanitize(tmp);
free(tmp);
- evbuffer_add(c->stdout_data, msg, strlen(msg));
- free(msg);
- } else
- evbuffer_add_vprintf(c->stdout_data, fmt, ap);
- evbuffer_add(c->stdout_data, "\n", 1);
- server_client_push_stdout(c);
+ }
+ file_print(c, "%s\n", msg);
} else {
wp = c->session->curw->window->active;
wme = TAILQ_FIRST(&wp->modes);
@@ -517,7 +515,7 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...)
window_copy_vadd(wp, fmt, ap);
}
- va_end(ap);
+ free(msg);
}
/* Show error from command. */
@@ -528,11 +526,10 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
struct cmd *cmd = item->cmd;
va_list ap;
char *msg;
- size_t msglen;
char *tmp;
va_start(ap, fmt);
- msglen = xvasprintf(&msg, fmt, ap);
+ xvasprintf(&msg, fmt, ap);
va_end(ap);
log_debug("%s: %s", __func__, msg);
@@ -544,11 +541,8 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
tmp = msg;
msg = utf8_sanitize(tmp);
free(tmp);
- msglen = strlen(msg);
}
- evbuffer_add(c->stderr_data, msg, msglen);
- evbuffer_add(c->stderr_data, "\n", 1);
- server_client_push_stderr(c);
+ file_error(c, "%s\n", msg);
c->retval = 1;
} else {
*msg = toupper((u_char) *msg);