From bc475963131130d6edd617b7dec6e955c0964548 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Mon, 18 Jun 2012 15:25:23 +0000 Subject: [PATCH] Sync OpenBSD patchset 1139: Actually write all the data to stdout/stderr. --- client.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/client.c b/client.c index 3478b999..04b8317c 100644 --- a/client.c +++ b/client.c @@ -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 *); @@ -460,6 +461,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) @@ -504,14 +523,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)