From: Miroslav Lichvar Date: Thu, 14 Jul 2022 12:51:24 +0000 (+0200) Subject: client: check for stdout errors X-Git-Tag: 4.3-pre1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a73803770586c46cccc7dee7dffc2aa27e9b96c6;p=thirdparty%2Fchrony.git client: check for stdout errors 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. --- diff --git a/client.c b/client.c index 242bd6df..6f78cb1f 100644 --- 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; }