From e1152cee49ece1c3e6956654679098a72d8b33b3 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Fri, 9 Oct 2015 19:17:47 +0200 Subject: [PATCH] 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 --- generic/e2lib.lua | 9 +++++++++ 1 file changed, 9 insertions(+) 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) -- 2.39.5