From: Stephan Bosch Date: Mon, 22 Jan 2018 22:25:34 +0000 (+0100) Subject: lib-program-client: Use reliable means of checking for input stream EOF. X-Git-Tag: 2.2.35~121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b33d78cf5e7b4c4e01e35967f69439f06c40a29d;p=thirdparty%2Fdovecot%2Fcore.git lib-program-client: Use reliable means of checking for input stream EOF. --- diff --git a/src/lib-program-client/program-client-remote.c b/src/lib-program-client/program-client-remote.c index abc418dab0..23d0b241ed 100644 --- a/src/lib-program-client/program-client-remote.c +++ b/src/lib-program-client/program-client-remote.c @@ -320,8 +320,11 @@ void program_client_remote_disconnect(struct program_client *pclient, bool force i_stream_skip(pclient->program_input, size); } - /* Get exit code */ - if (!pclient->program_input->eof) + /* Check for error and EOF. Since we're disconnected, always + mark an internal error when not all input is read. This is + generally unlikely to occur. */ + if (pclient->program_input->stream_errno != 0 || + i_stream_have_bytes_left(pclient->program_input)) pclient->exit_code = -1; } else { pclient->exit_code = 1; diff --git a/src/lib-program-client/program-client.c b/src/lib-program-client/program-client.c index 2ea49e8573..fa910d495a 100644 --- a/src/lib-program-client/program-client.c +++ b/src/lib-program-client/program-client.c @@ -188,7 +188,7 @@ bool program_client_input_pending(struct program_client *pclient) if (pclient->program_input != NULL && !pclient->program_input->closed && - !i_stream_is_eof(pclient->program_input)) { + i_stream_have_bytes_left(pclient->program_input)) { return TRUE; } @@ -197,7 +197,7 @@ bool program_client_input_pending(struct program_client *pclient) for(i = 0; i < count; i++) { if (efds[i].input != NULL && !efds[i].input->closed && - !i_stream_is_eof(efds[i].input)) { + i_stream_have_bytes_left(efds[i].input)) { return TRUE; } } @@ -357,7 +357,7 @@ void program_client_extra_fd_input(struct program_client_extra_fd *efd) i_assert(efd->callback != NULL); efd->callback(efd->context, efd->input); - if (efd->input->closed || i_stream_is_eof(efd->input)) { + if (efd->input->closed || !i_stream_have_bytes_left(efd->input)) { if (!program_client_input_pending(pclient)) program_client_disconnect(pclient, FALSE); }