]> git.e2factory.org Git - e2factory.git/commitdiff
set FD_CLOEXEC on dup'ed file descriptors in child
authorTobias Ulmer <tu@emlix.com>
Fri, 9 Oct 2015 17:17:47 +0000 (19:17 +0200)
committerTobias Ulmer <tu@emlix.com>
Fri, 9 Oct 2015 17:21:35 +0000 (19:21 +0200)
Be careful not to close the descriptor we want to pass on (0, 1, 2)

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua

index e36906af670b638ef690f0404ca92a0d177d9d35..5c43b7d43e9eacd60ec8d5448fa801a7741246de 100644 (file)
@@ -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)