Skip to content

Commit

Permalink
common: flush streams before closing them
Browse files Browse the repository at this point in the history
On loaded systems slow tty can give false positive exit failure due pending
bytes.  Flush the streams that hopefully makes these problems less likely.

Reference: iputils@4655ecc#commitcomment-36628770
Signed-off-by: Sami Kerola <[email protected]>
  • Loading branch information
kerolasa committed Jan 6, 2020
1 parent 2705c82 commit 2308234
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion iputils_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ void error(int status, int errnum, const char *format, ...)

int close_stream(FILE *stream)
{
const int flush_status = fflush(stream);
#ifdef HAVE___FPENDING
const int some_pending = (__fpending(stream) != 0);
#endif
const int prev_fail = (ferror(stream) != 0);
const int fclose_fail = (fclose(stream) != 0);

if (prev_fail || (fclose_fail && (
if (flush_status ||
prev_fail || (fclose_fail && (
#ifdef HAVE___FPENDING
some_pending ||
#endif
Expand Down

0 comments on commit 2308234

Please sign in to comment.