openbsd-ports/x11/awesome/patches/patch-lib_awful_util_lua_in
dcoppa dd2fb2d685 - in awful.util.pread, sync comments with our reality
- while here, add paranoia to the find cmdline
2011-06-22 12:54:03 +00:00

63 lines
1.6 KiB
Plaintext

$OpenBSD: patch-lib_awful_util_lua_in,v 1.3 2011/06/22 12:54:03 dcoppa Exp $
XXX THIS IS A HACK
This is needed to workaround the effects of userland
threads which change I/O operations to non-blocking.
--- lib/awful/util.lua.in.orig Mon May 16 16:35:17 2011
+++ lib/awful/util.lua.in Wed Jun 22 12:59:39 2011
@@ -88,18 +88,46 @@ function spawn_with_shell(cmd, screen)
end
end
+local function read_all(fn)
+ local fd = io.open(fn, _OPEN_RT)
+ if not fd then return nil end
+ local str = fd:read'*a'
+ fd:close()
+ return str
+end
+
--- Read a program output and returns its output as a string.
-- @param cmd The command to run.
--- @return A string with the program output, or the error if one occured.
+-- @return A string with the program output, or nil if an error occurred.
function pread(cmd)
if cmd and cmd ~= "" then
- local f, err = io.popen(cmd, 'r')
- if f then
- local s = f:read("*all")
- f:close()
- return s
+ local rc, sout
+ local tmp1, tmp2
+ local fd_check, serr_check
+
+ tmp1 = os.tmpname()
+ tmp2 = os.tmpname()
+
+ rc = os.execute(cmd.." > "..tmp1.." 2> "..tmp2)
+
+ if rc == 0 then
+ sout = read_all(tmp1)
else
- return err
+ return nil
+ end
+
+ fd_check = io.open(tmp2)
+ if not fd_check then return nil end
+ serr_check = fd_check:read'*l'
+ fd_check:close()
+
+ os.remove(tmp1)
+ os.remove(tmp2)
+
+ if serr_check then
+ return nil
+ else
+ return sout
end
end
end