diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-06-18 13:34:57 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2012-06-18 13:34:57 +0000 |
commit | 2d0bd71ad9b8541295c2f8acb77f700a3e0c4d65 (patch) | |
tree | fcf26090b33be8cebcf97a7b48d6b041e248cf68 | |
parent | 97020f2615df659c28e493b1a5f7dc6c08eef3b9 (diff) |
Actually write all the data to stdout/stderr.
-rw-r--r-- | usr.bin/tmux/client.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index f76145c6688..435cdc52cb1 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.56 2012/06/18 13:16:42 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.57 2012/06/18 13:34:56 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -58,6 +58,7 @@ void client_write_server(enum msgtype, void *, size_t); void client_update_event(void); void client_signal(int, short, void *); void client_stdin_callback(int, short, void *); +void client_write(int, const char *, size_t); void client_callback(int, short, void *); int client_dispatch_attached(void); int client_dispatch_wait(void *); @@ -458,6 +459,24 @@ client_stdin_callback(unused int fd, unused short events, unused void *data1) client_update_event(); } +/* Force write to file descriptor. */ +void +client_write(int fd, const char *data, size_t size) +{ + ssize_t used; + + while (size != 0) { + used = write(fd, data, size); + if (used == -1) { + if (errno == EINTR || errno == EAGAIN) + continue; + break; + } + data += used; + size -= used; + } +} + /* Dispatch imsgs when in wait state (before MSG_READY). */ int client_dispatch_wait(void *data) @@ -502,14 +521,14 @@ client_dispatch_wait(void *data) fatalx("bad MSG_STDOUT"); memcpy(&stdoutdata, imsg.data, sizeof stdoutdata); - fwrite(stdoutdata.data, stdoutdata.size, 1, stdout); + client_write(STDOUT_FILENO, stdoutdata.data, stdoutdata.size); break; case MSG_STDERR: if (datalen != sizeof stderrdata) fatalx("bad MSG_STDERR"); memcpy(&stderrdata, imsg.data, sizeof stderrdata); - fwrite(stderrdata.data, stderrdata.size, 1, stderr); + client_write(STDERR_FILENO, stderrdata.data, stderrdata.size); break; case MSG_VERSION: if (datalen != 0) |