See title.

Maarten.
>From c7b7f32da7041f6c5251b78611f6c817df6b59fc Mon Sep 17 00:00:00 2001
From: Maarten Maathuis <[email protected]>
Date: Thu, 11 Dec 2008 22:14:07 +0100
Subject: [PATCH] completion, util: Check for io.popen failure.

Signed-off-by: Maarten Maathuis <[email protected]>
---
 lib/awful/completion.lua.in |   39 ++++++++++++++++++++++++---------------
 lib/awful/util.lua.in       |   12 ++++++++----
 2 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/lib/awful/completion.lua.in b/lib/awful/completion.lua.in
index 740d195..9812557 100644
--- a/lib/awful/completion.lua.in
+++ b/lib/awful/completion.lua.in
@@ -9,6 +9,7 @@
 local io = io
 local table = table
 local math = math
+local print = print
 
 --- Completion module for awful
 module("awful.completion")
@@ -26,16 +27,20 @@ keywords = {}
 -- @param src The bash completion source file, /etc/bash_completion by default.
 function bashcomp_load(src)
     if src then bashcomp_src = src end
-    local c = io.popen("/usr/bin/env bash -c 'source " .. bashcomp_src .. "; 
complete -p'")
-    while true do
-        local line = c:read("*line")
-        if not line then break end
-        -- if a bash function is used for completion, register it
-        if line:match(".* -F .*") then
-            bashcomp_funcs[line:gsub(".* (%S+)$","%1")] = line:gsub(".*-F 
+(%S+) .*$", "%1")
+    local c, err = io.popen("/usr/bin/env bash -c 'source " .. bashcomp_src .. 
"; complete -p'")
+    if c then
+        while true do
+            local line = c:read("*line")
+            if not line then break end
+            -- if a bash function is used for completion, register it
+            if line:match(".* -F .*") then
+                bashcomp_funcs[line:gsub(".* (%S+)$","%1")] = line:gsub(".*-F 
+(%S+) .*$", "%1")
+            end
         end
+        c:close()
+    else
+        print(err)
     end
-    c:close()
 end
 
 --- Use bash completion system to complete command and filename.
@@ -88,16 +93,20 @@ function bash(command, cur_pos, ncomp)
     else
         bash_cmd = "/usr/bin/env bash -c 'compgen -A " .. comptype .. " " .. 
words[cword_index] .. "'"
     end
-    local c = io.popen(bash_cmd)
+    local c, err = io.popen(bash_cmd)
     local output = {}
     i = 0
-    while true do
-        local line = c:read("*line")
-        if not line then break end
-        table.insert(output, line)
-    end
+    if c then
+        while true do
+            local line = c:read("*line")
+            if not line then break end
+            table.insert(output, line)
+        end
 
-    c:close()
+        c:close()
+    else
+        print(err)
+    end
 
     -- no completion, return
     if #output == 0 then
diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in
index d72ff41..6d7e61d 100644
--- a/lib/awful/util.lua.in
+++ b/lib/awful/util.lua.in
@@ -73,10 +73,14 @@ end
 -- @return A string with the program output.
 function pread(cmd)
     if cmd and cmd ~= "" then
-        local f = io.popen(cmd, 'r')
-        local s = f:read("*all")
-        f:close()
-        return s
+        local f, err = io.popen(cmd, 'r')
+        if f then
+            local s = f:read("*all")
+            f:close()
+            return s
+        else
+            print(err)
+        end
     end
 end
 
-- 
1.6.0.4

Reply via email to