]> git.e2factory.org Git - e2factory.git/commitdiff
git: wait for pipe children in any order
authorTobias Ulmer <tu@emlix.com>
Thu, 7 Jun 2018 19:24:46 +0000 (21:24 +0200)
committerTobias Ulmer <tu@emlix.com>
Thu, 7 Jun 2018 19:24:46 +0000 (21:24 +0200)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
plugins/git.lua

index b13f684908bebf437c64163e2268b41d10bd4237..7ea6fb78889e7efa327f9e14fe9c8266b1bfe2ab 100644 (file)
@@ -555,8 +555,9 @@ function git.git_source:prepare_source(sourceset, buildpath)
     end
 
     local gitdir, git_argv, git_tool, tar_argv
-    local git_pid, tar_pid, fdctv
+    local pid, status, fdctv
     local writeend, readend, devnull
+    local children = {}
 
     gitdir = e2lib.join(srcdir, ".git")
 
@@ -611,38 +612,54 @@ function git.git_source:prepare_source(sourceset, buildpath)
         { istype = "readfo", dup = eio.STDOUT, file = writeend }
     }
 
-    git_pid, re = e2lib.callcmd(git_argv, fdctv, nil, nil, true)
-    if not git_pid then
+    pid, re = e2lib.callcmd(git_argv, fdctv, nil, nil, true)
+    if not pid then
         return false, e:cat(re)
     end
+    table.insert(children, { pid=pid, name="git" })
 
     fdctv = {
         { istype = "readfo", dup = eio.STDIN, file = readend },
         { istype = "readfo", dup = eio.STDOUT, file = devnull }
     }
 
-    tar_pid, re = e2lib.callcmd(tar_argv, fdctv, nil, nil, true)
-    if not tar_pid then
+    pid, re = e2lib.callcmd(tar_argv, fdctv, nil, nil, true)
+    if not pid then
         return false, e:cat(re)
     end
+    table.insert(children, { pid=pid, name="tar" })
 
-    rc, re = e2lib.wait(git_pid)
-    if not rc then
-        return false, e:cat(re)
-    elseif rc ~= 0 then
-        return false, e:cat("git archive failed with return code %d", rc)
-    end
+    local errors = false
+    while (#children > 0) do
+        local found = false
+        status, pid = e2lib.wait(-1)
+        if not status then
+            return false, e:cat(pid)
+        end
 
-    rc, re = eio.close(writeend)
-    if not rc then
-        return false, e:cat(re)
+        for pos, child in ipairs(children) do
+            if pid == child.pid then
+                found = true
+                if status ~= 0 then
+                    return false, e:cat("%s failed with return code %d",
+                        child.name, status)
+                end
+
+                table.remove(children, pos)
+                break
+            end
+        end
+
+        if not found then
+            -- can this happen? avoid potential infinite loop anyway
+            return false,
+                e:cat("unexpected child with pid=%d status=%d", pid, status)
+        end
     end
 
-    rc, re = e2lib.wait(tar_pid)
+    rc, re = eio.close(writeend)
     if not rc then
         return false, e:cat(re)
-    elseif rc ~= 0 then
-        return false, e:cat("git archive - tar failed with return code %d", rc)
     end
 
     rc, re = eio.close(readend)