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.
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;
}