]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: Use reliable means of checking for input stream EOF.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Mon, 22 Jan 2018 22:25:34 +0000 (23:25 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 31 Jan 2018 11:25:17 +0000 (13:25 +0200)
src/lib-program-client/program-client-remote.c
src/lib-program-client/program-client.c

index abc418dab08d8133ec43ad61ac8b0d33d6c9adb3..23d0b241ed6a12d3888ac22e9c2f804b6d151ffb 100644 (file)
@@ -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;
index 2ea49e85733018d20be70b1c2d2643ee1ec661f7..fa910d495a3952d6e2400964cc8a1ccd76c61861 100644 (file)
@@ -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);
        }