fixup! gluon-core: implement popen3() in gluon/util.lua
This commit is contained in:
parent
a125242f4c
commit
77bf2f9cbf
@ -190,6 +190,13 @@ function M.log(message, verbose)
|
|||||||
posix_syslog.syslog(posix_syslog.LOG_INFO, message)
|
posix_syslog.syslog(posix_syslog.LOG_INFO, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Blindly close the file descriptors in a given table.
|
||||||
|
local function close_fds(descriptors)
|
||||||
|
for _, fd in pairs(descriptors) do
|
||||||
|
posix_unistd.close(fd)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.subprocess = {}
|
M.subprocess = {}
|
||||||
|
|
||||||
M.subprocess.DEVNULL = -1
|
M.subprocess.DEVNULL = -1
|
||||||
@ -221,6 +228,8 @@ function M.subprocess.popen(path, argt, options)
|
|||||||
local pid, errmsg, errnum = posix_unistd.fork()
|
local pid, errmsg, errnum = posix_unistd.fork()
|
||||||
|
|
||||||
if pid == nil then
|
if pid == nil then
|
||||||
|
close_fds(childfds)
|
||||||
|
close_fds(parentfds)
|
||||||
return nil, errmsg, errnum
|
return nil, errmsg, errnum
|
||||||
elseif pid == 0 then
|
elseif pid == 0 then
|
||||||
local null = -1
|
local null = -1
|
||||||
@ -251,9 +260,7 @@ function M.subprocess.popen(path, argt, options)
|
|||||||
posix_unistd._exit(127)
|
posix_unistd._exit(127)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, v in pairs(childfds) do
|
close_fds(childfds)
|
||||||
posix_unistd.close(v)
|
|
||||||
end
|
|
||||||
|
|
||||||
return pid, parentfds
|
return pid, parentfds
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user