]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
client: check for stdout errors
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 Jul 2022 12:51:24 +0000 (14:51 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 21 Jul 2022 12:17:11 +0000 (14:17 +0200)
Return with an error code from chronyc if the command is expected to
print some data and fflush() or ferror() indicates an error. This should
make it easier for scripts to detect missing data when redirected to a
file.

client.c

index 242bd6dfae044caec35c87f6832a5480dcedafaf..6f78cb1fb0a339464651d6f9a7f3e845d0653caa 100644 (file)
--- a/client.c
+++ b/client.c
@@ -3238,8 +3238,17 @@ process_line(char *line)
   if (do_normal_submit) {
     ret = request_reply(&tx_message, &rx_message, RPY_NULL, 1);
   }
+
   fflush(stderr);
-  fflush(stdout);
+
+  if (fflush(stdout) != 0 || ferror(stdout) != 0) {
+    LOG(LOGS_ERR, "Could not write to stdout");
+
+    /* Return error for commands that print data */
+    if (!do_normal_submit)
+      return 0;
+  }
+
   return ret;
 }