fixup! gluon-core: implement popen3() in gluon/util.lua
This commit is contained in:
		
							parent
							
								
									6aa7d85c12
								
							
						
					
					
						commit
						1acc783a09
					
				@ -190,10 +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.
 | 
					-- Blindly close the file descriptors in an arbitrary amount of given tables.
 | 
				
			||||||
local function close_fds(descriptors)
 | 
					local function close_fds(...)
 | 
				
			||||||
	for _, fd in pairs(descriptors) do
 | 
						for i=1, select("#", ...) do
 | 
				
			||||||
		posix_unistd.close(fd)
 | 
							local descriptor_table = select(i, ...)
 | 
				
			||||||
 | 
							for _, fd in pairs(descriptor_table) do
 | 
				
			||||||
 | 
								posix_unistd.close(fd)
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -228,8 +231,7 @@ 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(childfds, parentfds)
 | 
				
			||||||
		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
 | 
				
			||||||
@ -243,12 +245,9 @@ function M.subprocess.popen(path, argt, options)
 | 
				
			|||||||
			if option == M.subprocess.DEVNULL then
 | 
								if option == M.subprocess.DEVNULL then
 | 
				
			||||||
				posix_unistd.dup2(null, stdiostreams[iostream])
 | 
									posix_unistd.dup2(null, stdiostreams[iostream])
 | 
				
			||||||
			elseif option == M.subprocess.PIPE then
 | 
								elseif option == M.subprocess.PIPE then
 | 
				
			||||||
				-- only close these, if they exist
 | 
					 | 
				
			||||||
				posix_unistd.close(parentfds[iostream])
 | 
					 | 
				
			||||||
				posix_unistd.dup2(childfds[iostream], stdiostreams[iostream])
 | 
									posix_unistd.dup2(childfds[iostream], stdiostreams[iostream])
 | 
				
			||||||
				-- close all the dups
 | 
					 | 
				
			||||||
				posix_unistd.close(childfds[iostream])
 | 
					 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
 | 
								close_fds(childfds, parentfds)
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		-- close potential null
 | 
							-- close potential null
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user