superrip: check exit status of children
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Sat, 3 Apr 2010 20:58:45 +0000 (13:58 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Sat, 3 Apr 2010 21:02:48 +0000 (14:02 -0700)
Always check the exit status of children to make sure there were no
errors. Also, when handling an exception in the child, print out what it
is before exiting.

superrip.rb

index d9ab7d7..b6c5617 100755 (executable)
@@ -78,18 +78,23 @@ def audiorip(tnum, track)
 
   # If there are too many processes, wait for one of them to terminate
   if ($children.keys.length > $opts.max_children) then
-    pid = Process.wait(-1)
+    pid, status = Process.wait2(-1)
+    if (status.exitstatus != 0) then
+      raise "process #{pid} failed with exitstatus #{status.exitstatus}"
+    end
     $children.delete(pid)
   end
 
   pid = Process.fork
   if (pid == nil) then
+    retcode = 0
     begin
       process_wav(track)
-      Kernel.exit(0)
-    rescue
-      Kernel.exit(1)
+    rescue Exception => e
+      puts "*** FATAL ERROR: #{e}"
+      retcode = 1
     end
+    Kernel.exit(retcode)
   else
     $children[pid] = 1
   end
@@ -200,7 +205,12 @@ class Manifest
       next unless @t.has_key?(tnum)
       audiorip(tnum, @t[tnum])
     end
-    Process.waitall
+    prc = Process.waitall
+    prc.each do |pair|
+      if (pair[1].exitstatus != 0) then
+        raise "process #{pair[0]} failed with exitstatus #{pair[1].exitstatus}"
+      end
+    end
   end
 
   def inspect