From c86539f56cbacfb13162f7274802c573fe52db04 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 25 Dec 2012 01:45:58 +0000 Subject: Replace io.popen with modelfunctions.run_executable calls --- awall-model.lua | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/awall-model.lua b/awall-model.lua index 4b2bff8..479fd3d 100644 --- a/awall-model.lua +++ b/awall-model.lua @@ -84,20 +84,20 @@ function startstop_service(self, startstop, action) if not action then startstop.errtxt = "Invalid Action" else - local cmd + local cmd = {"awall"} if action == "Verify" then - cmd = path.."awall translate -V 2>&1" + cmd[#cmd+1] = "translate" + cmd[#cmd+1] = "-V" elseif action == "Translate" then - cmd = path.."awall translate 2>&1" + cmd[#cmd+1] = "translate" else - cmd = path.."awall activate -f 2>&1" + cmd[#cmd+1] = "activate" + cmd[#cmd+1] = "-f" end - local f = io.popen(cmd) - startstop.descr = f:read("*a") - if startstop.descr == "" then + startstop.descr, startstop.errtxt = modelfunctions.run_executable(cmd, true) + if not startstop.errtxt and startstop.descr == "" then startstop.descr = "Success" end - f:close() end return startstop end @@ -107,9 +107,8 @@ function list_policies() local policies = {} local reversepolicies = {} local errtxt - local cmd = path.."awall list 2>&1" - local f = io.popen(cmd) - for l in f:lines() do + local f = modelfunctions.run_executable({"awall", "list"}, true) + for l in string.match(f, "[^\n]+") do local a,b,c = string.match(l, "(%S+)%s+(%S+)%s*(.*)") if a and a == "/usr/bin/lua:" then errtxt = b.." "..c @@ -120,7 +119,6 @@ function list_policies() reversepolicies[a] = #policies end end - f:close() -- Since awall seems to crash (and not give results) when there is any error -- Let's show the actual files too local addfiles = function(files, editable, mandatory) @@ -245,23 +243,10 @@ function get_enablepolicy(self, clientdata) end function enable_policy(self, enable) - local cmd = path.."awall enable "..format.escapespecialcharacters(enable.value.name.value).." 2>&1" - local f = io.popen(cmd) - local result = f:read("*a") - f:close() - if result ~= "" then - enable.errtxt = result - end + enable.descr, enable.errtxt = modelfunctions.run_executable({"awall", "enable", enable.value.name.value}, true) return enable end function disable_policy(self, disable) - local cmd = path.."awall disable "..format.escapespecialcharacters(disable.value.name.value).." 2>&1" - local f = io.popen(cmd) - local result = f:read("*a") - f:close() - if result ~= "" then - disable.errtxt = result - end - return disable + disable.descr, disable.errtxt = modelfunctions.run_executable({"awall", "disable", disable.value.name.value}, true) end -- cgit v1.2.3