Spawn.vala
[gitlive] / Spawn.vala
index c9e392c..1601af1 100644 (file)
@@ -241,7 +241,7 @@ public class Spawn : Object
             stdout.printf("PID: %d" ,this.pid);
         }
         
-        this.ref();
+        this.ref(); // additional ref - cleared on tidyup...
         
         this.in_ch = new GLib.IOChannel.unix_new(standard_input);
         this.out_ch = new GLib.IOChannel.unix_new(standard_output);
@@ -294,7 +294,7 @@ public class Spawn : Object
         this.out_src = (int) this.out_ch.add_watch (
             IOCondition.OUT | IOCondition.IN  | IOCondition.PRI |  IOCondition.HUP |  IOCondition.ERR  ,
             (channel, condition) => {
-               return this.read(this.out_ch);
+                return this.out_ch != null ? this.read(this.out_ch) : true;
             }
         );
         this.err_src = (int) this.err_ch.add_watch (
@@ -426,7 +426,7 @@ public class Spawn : Object
     {
         string prop = (ch == this.out_ch) ? "output" : "stderr";
        // print("prop: " + prop);
-
+        
         
         //print(JSON.stringify(ch, null,4));
         while (true) {
@@ -434,6 +434,11 @@ public class Spawn : Object
             size_t term_pos;
             size_t len;
             IOStatus status;
+            
+            if (this.pid < 0) {
+                return false; // spawn complete + closed... can't read any more.
+            }
+            
             try {
                                var cond = ch.get_buffer_condition();
                                if ((cond & GLib.IOCondition.ERR) > 0) {