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.3.9~2422 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23a7a07d4d7cab538509ceef21a280dcc243362f;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 35a35b4ca5..56707e4040 100644 --- a/src/lib-program-client/program-client-remote.c +++ b/src/lib-program-client/program-client-remote.c @@ -555,8 +555,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 61e577b21c..5221c1d4cb 100644 --- a/src/lib-program-client/program-client.c +++ b/src/lib-program-client/program-client.c @@ -186,7 +186,7 @@ bool program_client_input_pending(struct program_client *pclient) if (pclient->program_input != NULL && !pclient->program_input->closed && - !i_stream_read_eof(pclient->program_input)) { + i_stream_have_bytes_left(pclient->program_input)) { return TRUE; } @@ -195,7 +195,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_read_eof(efds[i].input)) { + i_stream_have_bytes_left(efds[i].input)) { return TRUE; } } @@ -381,7 +381,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_read_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); }