From: Tobias Ulmer Date: Fri, 17 Jun 2016 15:18:21 +0000 (+0200) Subject: e2lib.callcmd(): allow multiple descriptors to use a pipe X-Git-Tag: e2factory-2.3.15rc1~149 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=55097757f288f61dfed0e128da02db8ca5b568a3;p=e2factory.git e2lib.callcmd(): allow multiple descriptors to use a pipe Stdout and stderr used to get out of sync due to using a pipe each. Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 3f5cd14..3ddd34e 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1045,8 +1045,9 @@ end --- File descriptor configuration table. -- @table fdct --- @field dup File descriptor in the child process that should be replaced by --- this configuration. +-- @field dup File descriptor(s) in the child process that should be replaced by +-- this configuration. Can be a single descriptor number or a +-- vector of descriptors (the later works with "writefunc" only). -- @field istype Describes the type of fdct. Can be either "readfo" or -- "writefunc". For details, check their respective pseudo-tables. -- @see fdct_readfo @@ -1124,9 +1125,19 @@ function e2lib.callcmd(argv, fdctv, workdir, envdict) e2lib.abort(re) end - rc, re = eio.dup2(fdct._p.wfd, fdct.dup) - if not rc then - e2lib.abort(re) + local duptable + if type(fdct.dup) == "table" then + duptable = fdct.dup + else + duptable = {} + table.insert(duptable, fdct.dup) + end + + for _,todup in ipairs(duptable) do + rc, re = eio.dup2(fdct._p.wfd, todup) + if not rc then + e2lib.abort(re) + end end elseif fdct.istype == "readfo" then rc, re = eio.dup2(eio.fileno(fdct.file), fdct.dup) @@ -1434,10 +1445,8 @@ function e2lib.callcmd_capture(cmd, capture, workdir, envdict) local fdctv = { { dup = eio.STDIN, istype = "readfo", file = devnull }, - { dup = eio.STDOUT, istype = "writefunc", - linebuffer = true, callfn=capture }, - { dup = eio.STDERR, istype = "writefunc", - linebuffer = true, callfn=capture }, + { dup = { [1] = eio.STDOUT, [2] = eio.STDERR }, istype = "writefunc", + linebuffer = true, callfn = capture }, } rc, re = e2lib.callcmd(cmd, fdctv, workdir, envdict)