gsubprocess: Fix up communicate

We weren't closing the streams after we were done reading or writing,
which is kind of essential.  The easy way to fix this is to just use
g_output_stream_splice() to a GMemoryOutputStream rather than
hand-rolling it.  This results in a substantial reduction of code
complexity.

A second serious issue is that we were marking the task as complete when
the process exits, but that's racy - there could still be data to read
from stdout.  Fix this by just refcounting outstanding operations.

This code, not surprisingly, looks a lot like the "multi" test.

Next, because processes output binary data, I'd be forced to annotate
the char*/length pairs as (array) (element-type uint8).  But rather than
doing that, it's *far* simpler to just use GBytes.

We need a version of this that actually validates as UTF-8, that will be
in the next patch.
This commit is contained in:
Colin Walters
2013-10-15 00:12:22 +01:00
committed by Ryan Lortie
parent 5b48dc40cc
commit 0e1a3ee345
5 changed files with 198 additions and 344 deletions

View File

@@ -101,7 +101,7 @@ void g_subprocess_launcher_take_stderr_fd (GSubpro
gint fd);
GLIB_AVAILABLE_IN_2_40
void g_subprocess_launcher_pass_fd (GSubprocessLauncher *self,
void g_subprocess_launcher_take_fd (GSubprocessLauncher *self,
gint source_fd,
gint target_fd);