Skip to content

Commit

Permalink
lib-program-client: Flush/finish the output stream after o_stream_sen…
Browse files Browse the repository at this point in the history
…d_istream().

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).
  • Loading branch information
stephanbosch authored and villesavolainen committed Jan 31, 2018
1 parent dd15704 commit fcc204a
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/lib-program-client/program-client.c
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit fcc204a

Please sign in to comment.