gsubprocess: fix communicate() with empty buffers
authorRyan Lortie <desrt@desrt.ca>
Mon, 3 Mar 2014 02:01:12 +0000 (21:01 -0500)
committerRyan Lortie <desrt@desrt.ca>
Tue, 4 Mar 2014 02:26:24 +0000 (21:26 -0500)
On the splice for stdout or stderr completing, GSubprocess calls
_slice_finish() to collect the result.

We assume that a zero return value here means failure, but in fact this
function returns a gssize -- the number of bytes transferred, or -1 for
an error.

This causes GSubprocess to mistakenly think that it has an error when it
actually just has an empty buffer (as would be the case when collecting
stderr from a successful command).

Check for -1 instead of FALSE to detect the error.

https://bugzilla.gnome.org/show_bug.cgi?id=724916

gio/gsubprocess.c

index c0f8367..19cbf57 100644 (file)
@@ -1420,7 +1420,7 @@ g_subprocess_communicate_made_progress (GObject      *source_object,
       source == state->stdout_buf ||
       source == state->stderr_buf)
     {
-      if (!g_output_stream_splice_finish ((GOutputStream*)source, result, &error))
+      if (g_output_stream_splice_finish ((GOutputStream*) source, result, &error) == -1)
         goto out;
 
       if (source == state->stdout_buf ||