From: Stephan Bosch Date: Mon, 22 Jan 2018 22:43:18 +0000 (+0100) Subject: lib-program-client: Flush/finish the output stream after o_stream_send_istream(). X-Git-Tag: 2.3.9~2418 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=824ca2373b872449b6b6ce29707c02c0d810eb74;p=thirdparty%2Fdovecot%2Fcore.git lib-program-client: Flush/finish the output stream after o_stream_send_istream(). There may still be data in the output stream buffer. Failing to flush this leads to truncated output. For the output towards the program o_stream_finish() is used, since there may be an ostream_dot in between (or something else for future features). --- diff --git a/src/lib-program-client/program-client.c b/src/lib-program-client/program-client.c index 4edf38e24b..0fee51214c 100644 --- a/src/lib-program-client/program-client.c +++ b/src/lib-program-client/program-client.c @@ -258,19 +258,17 @@ int program_client_program_output(struct program_client *pclient) } } - if (input == NULL && - output != NULL && - pclient->dot_output != NULL) { - if ((ret = o_stream_finish(pclient->dot_output)) <= 0) { - if (ret < 0) { - i_error("write(%s) failed: %s", - o_stream_get_name(output), - o_stream_get_error(output)); - program_client_fail(pclient, - PROGRAM_CLIENT_ERROR_IO); - } - return ret; + if (input == NULL && output != NULL) { + if ((ret=o_stream_finish(output)) < 0) { + i_error("write(%s) failed: %s", + o_stream_get_name(output), + o_stream_get_error(output)); + program_client_fail(pclient, + PROGRAM_CLIENT_ERROR_IO); + return -1; } + if (ret == 0) + return 0; o_stream_unref(&pclient->dot_output); } @@ -355,6 +353,20 @@ void program_client_program_input(struct program_client *pclient) return; } } + + if (output != NULL) { + if ((ret=o_stream_flush(output)) < 0) { + i_error("write(%s) failed: %s", + o_stream_get_name(output), + o_stream_get_error(output)); + program_client_fail(pclient, + PROGRAM_CLIENT_ERROR_IO); + return; + } + if (ret == 0) + return; + } + if (program_client_input_pending(pclient)) return; }