]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: Flush/finish the output stream after o_stream_send_istream().
authorStephan Bosch <stephan.bosch@dovecot.fi>
Mon, 22 Jan 2018 22:43:18 +0000 (23:43 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Fri, 26 Jan 2018 19:17:11 +0000 (20:17 +0100)
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).

src/lib-program-client/program-client.c

index 4edf38e24b39ffbb2112b7e5769bc017f0c4bc5c..0fee51214c3d6c6bc03ca587f6c6079934ae811f 100644 (file)
@@ -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;
        }