summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2013-08-14 10:36:33 -0700
committerRuss Allbery <rra@stanford.edu>2013-08-14 15:09:47 -0700
commit771b253fcd2276dfafde580abee93b17c5580804 (patch)
tree3d6861a3b3590073ed31e1cfe3a3beb81fdf905d /client
parent250e251dad6846a1fb6adb4bb3bd3ca59f5060ad (diff)
Check fwrite status in the client
This is mostly to silence clang builds, but there are some edge cases where this will report an error that otherwise wouldn't have been reported. Change-Id: I85cce8d52cc8569a49c4fdb2f1cf8cfa6398b1a3 Reviewed-on: https://gerrit.stanford.edu/1256 Reviewed-by: Russ Allbery <rra@stanford.edu> Tested-by: Russ Allbery <rra@stanford.edu>
Diffstat (limited to 'client')
-rw-r--r--client/remctl.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/client/remctl.c b/client/remctl.c
index 35ad848..52df8c4 100644
--- a/client/remctl.c
+++ b/client/remctl.c
@@ -7,7 +7,7 @@
*
* Originally written by Anton Ushakov
* Extensive modifications by Russ Allbery <rra@stanford.edu>
- * Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+ * Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013
* The Board of Trustees of the Leland Stanford Junior University
*
* See LICENSE for licensing terms.
@@ -49,6 +49,19 @@ usage(int status)
/*
+ * A wrapper around fwrite that checks the return status and reports an error
+ * if the write failed. This is probably futile for stderr, since reporting
+ * the error will probably also fail, but we can try.
+ */
+static void
+fwrite_checked(const void *data, size_t size, size_t nmemb, FILE *stream)
+{
+ if (fwrite(data, size, nmemb, stream) != nmemb)
+ syswarn("local write of command output failed");
+}
+
+
+/*
* Get the responses back from the server, taking appropriate action on each
* one depending on its type. Sets the errorcode parameter to the exit status
* of the remote command, or to 1 if the remote command failed with an error.
@@ -66,17 +79,17 @@ process_response(struct remctl *r, int *errorcode)
switch (out->type) {
case REMCTL_OUT_OUTPUT:
if (out->stream == 1)
- fwrite(out->data, out->length, 1, stdout);
+ fwrite_checked(out->data, out->length, 1, stdout);
else if (out->stream == 2)
- fwrite(out->data, out->length, 1, stderr);
+ fwrite_checked(out->data, out->length, 1, stderr);
else {
warn("unknown output stream %d", out->stream);
- fwrite(out->data, out->length, 1, stderr);
+ fwrite_checked(out->data, out->length, 1, stderr);
}
break;
case REMCTL_OUT_ERROR:
*errorcode = 255;
- fwrite(out->data, out->length, 1, stderr);
+ fwrite_checked(out->data, out->length, 1, stderr);
fputc('\n', stderr);
return true;
case REMCTL_OUT_STATUS: