From: Tobias Ulmer Date: Wed, 13 Feb 2019 18:24:56 +0000 (+0100) Subject: e2lib: close unused sync pipe ends before reading from child X-Git-Tag: e2factory-2.3.18rc1~49 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=6d9f66d2fdfb670dabd55b78207a8db1d378df67;p=e2factory.git e2lib: close unused sync pipe ends before reading from child Otherwise we could end up in a situation where we wait for a faulty child, but hang reading our own pipe. Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 75efc4f..ac9cfcb 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1427,6 +1427,14 @@ function e2lib.callcmd(argv, fdctv, workdir, envdict, nowait) local function sync_child(sync_pipes) local rc, re + -- close unused ends early + for _,fd in ipairs({2, 3}) do + rc, re = eio.close(sync_pipes[fd]) + if not rc then + return false, re + end + end + -- ping parent rc, re = eio.write(sync_pipes[4], "c") if not rc then @@ -1444,8 +1452,8 @@ function e2lib.callcmd(argv, fdctv, workdir, envdict, nowait) end -- cleanup - for _,fd in ipairs(sync_pipes) do - rc, re = eio.close(fd) + for _,fd in ipairs({4, 1}) do + rc, re = eio.close(sync_pipes[fd]) if not rc then return false, re end @@ -1457,6 +1465,18 @@ function e2lib.callcmd(argv, fdctv, workdir, envdict, nowait) local function sync_parent(sync_pipes) local rc, re + -- close unused ends + -- note: don't start reading/writing before all unused ends + -- are closed. If anything goes wrong with the child, we will + -- otherwise block forever trying to read from ourselves. + -- comment also applies to sync_child() + for _,fd in ipairs({1, 4}) do + rc, re = eio.close(sync_pipes[fd]) + if not rc then + return false, re + end + end + -- ping child rc, re = eio.write(sync_pipes[2], "p") if not rc then @@ -1474,8 +1494,8 @@ function e2lib.callcmd(argv, fdctv, workdir, envdict, nowait) end -- cleanup - for _,fd in ipairs(sync_pipes) do - rc, re = eio.close(fd) + for _,fd in ipairs({2, 3}) do + rc, re = eio.close(sync_pipes[fd]) if not rc then return false, re end