From: Tobias Ulmer Date: Fri, 9 Oct 2015 17:17:47 +0000 (+0200) Subject: set FD_CLOEXEC on dup'ed file descriptors in child X-Git-Tag: e2factory-2.3.14p1~8 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=e1152cee49ece1c3e6956654679098a72d8b33b3;p=e2factory.git set FD_CLOEXEC on dup'ed file descriptors in child Be careful not to close the descriptor we want to pass on (0, 1, 2) Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index e36906a..5c43b7d 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -902,12 +902,21 @@ function e2lib.callcmd(infile, outfile, errfile, cmd) -- redirect stdin io.stdin:close() luafile.dup2(infile:fileno(), 0) + if infile:fileno() ~= 0 then + infile:cloexec() + end -- redirect stdout io.stdout:close() luafile.dup2(outfile:fileno(), 1) + if outfile:fileno() ~= 1 then + outfile:cloexec() + end -- redirect stderr io.stderr:close() luafile.dup2(errfile:fileno(), 2) + if errfile:fileno() ~= 2 then + errfile:cloexec() + end -- run the command local rc = os.execute(cmd) return (rc/256)