NEXT:
+ * Provide io.open/io.popen wrappers that set FD_CLOEXEC
* On startup, close all file descriptors except for stdin, stdout, and stderr
as a precautionary measure.
* luafile.open() sets FD_CLOEXEC by default
e2util.closefrom(3)
-- ignore errors, no /proc should not prevent factory from working
+ -- Overwrite io functions that create a file descriptor to set the
+ -- CLOEXEC flag by default.
+ local realopen = io.open
+ local realpopen = io.popen
+
+ function io.open(...)
+ local ret = {realopen(...)} -- closure
+ if ret[1] then
+ if not luafile.cloexec(ret[1]) then
+ return nil, "Setting CLOEXEC failed"
+ end
+ end
+ return unpack(ret)
+ end
+
+ function io.popen(...)
+ local ret = {realpopen(...)} -- closure
+ if ret[1] then
+ if not luafile.cloexec(ret[1]) then
+ return nil, "Setting CLOEXEC failed"
+ end
+ end
+ return unpack(ret)
+ end
+
e2lib.globals.warn_category = {
WDEFAULT = false,
WDEPRECATED = false,