From 710e3e446804957b935cd9fda5aa2f2c2a55a4f4 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 15 Sep 2018 21:07:42 -0700 Subject: core.util: be more resilient when reading command outputs When luarocks.loader runs from within another process, we may end up getting an Interrupted signal when reading from a pipe, which is not handled by Lua. --- src/luarocks/core/util.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 5f5c0fe1..8789851c 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua @@ -12,10 +12,17 @@ local require = nil -- May be used to read more, passing, for instance, "*a". -- @return string: the output of the program. function util.popen_read(cmd, spec) - local fd = io.popen(cmd) + local tmpfile = os.tmpname() + os.execute(cmd .. " > " .. tmpfile) + local fd = io.open(tmpfile, "rb") + if not fd then + os.remove(tmpfile) + return "" + end local out = fd:read(spec or "*l") fd:close() - return out + os.remove(tmpfile) + return out or "" end --- Create a new shallow copy of a table: a new table with -- cgit v1.2.3-55-g6feb