fixup! gluon-core: implement popen3() in gluon/util.lua
This commit is contained in:
parent
50ef57f7f5
commit
2502b2c6c0
@ -203,14 +203,14 @@ function M.subprocess.popen(policies, path, ...)
|
|||||||
local parentfds = {}
|
local parentfds = {}
|
||||||
|
|
||||||
for fd, policy in pairs(policies) do
|
for fd, policy in pairs(policies) do
|
||||||
if policy==M.subprocess.PIPE then
|
if policy == M.subprocess.PIPE then
|
||||||
local piper, pipew = posix_unistd.pipe()
|
local piper, pipew = posix_unistd.pipe()
|
||||||
if fd==posix_unistd.STDIN_FILENO then
|
if fd == posix_unistd.STDIN_FILENO then
|
||||||
childfds[fd]=piper
|
childfds[fd] = piper
|
||||||
parentfds[fd]=pipew
|
parentfds[fd] = pipew
|
||||||
else
|
else
|
||||||
childfds[fd]=pipew
|
childfds[fd] = pipew
|
||||||
parentfds[fd]=piper
|
parentfds[fd] = piper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -223,18 +223,18 @@ function M.subprocess.popen(policies, path, ...)
|
|||||||
if pid == nil then
|
if pid == nil then
|
||||||
return nil, errmsg, errnum
|
return nil, errmsg, errnum
|
||||||
elseif pid == 0 then
|
elseif pid == 0 then
|
||||||
local null=-1
|
local null = -1
|
||||||
if M.contains(policies, M.subprocess.DEVNULL) then
|
if M.contains(policies, M.subprocess.DEVNULL) then
|
||||||
-- only open, if there's anything to discard
|
-- only open, if there's anything to discard
|
||||||
null = posix_fcntl.open('/dev/null', posix_fcntl.O_WRONLY)
|
null = posix_fcntl.open('/dev/null', posix_fcntl.O_WRONLY)
|
||||||
end
|
end
|
||||||
|
|
||||||
for fd, policy in pairs(policies) do
|
for fd, policy in pairs(policies) do
|
||||||
if policy==M.subprocess.DEVNULL then
|
if policy == M.subprocess.DEVNULL then
|
||||||
if fd~=posix_unistd.STDIN_FILENO then
|
if fd ~= posix_unistd.STDIN_FILENO then
|
||||||
posix_unistd.dup2(null, fd)
|
posix_unistd.dup2(null, fd)
|
||||||
end
|
end
|
||||||
elseif policy==M.subprocess.PIPE then
|
elseif policy == M.subprocess.PIPE then
|
||||||
-- only close these, if they exist
|
-- only close these, if they exist
|
||||||
posix_unistd.close(parentfds[fd])
|
posix_unistd.close(parentfds[fd])
|
||||||
posix_unistd.dup2(childfds[fd], fd)
|
posix_unistd.dup2(childfds[fd], fd)
|
||||||
|
Loading…
Reference in New Issue
Block a user