changeset 22783:751eb2d43bc7

lib-program-client: Use reliable means of checking for input stream EOF.
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Mon, 22 Jan 2018 23:25:34 +0100
parents db50f01b8373
children 99acd6d25ad2
files src/lib-program-client/program-client-remote.c src/lib-program-client/program-client.c
diffstat 2 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-program-client/program-client-remote.c	Sat Nov 11 10:07:42 2017 +0200
+++ b/src/lib-program-client/program-client-remote.c	Mon Jan 22 23:25:34 2018 +0100
@@ -320,8 +320,11 @@
 			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;
--- a/src/lib-program-client/program-client.c	Sat Nov 11 10:07:42 2017 +0200
+++ b/src/lib-program-client/program-client.c	Mon Jan 22 23:25:34 2018 +0100
@@ -188,7 +188,7 @@
 
 	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 @@
 		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 @@
 	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);
 	}