summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2015-12-30 14:01:59 +0000
committerTed Trask <ttrask01@yahoo.com>2015-12-30 14:01:59 +0000
commitead073ce065f691630cb7a3595dbeb8377b70da3 (patch)
tree4318d90e480b613a710cd74ff5f770b920fc53d6
parent2b75899c95c64dda23fdede49e7122b63b699387 (diff)
downloadacf-freeradius3-ead073ce065f691630cb7a3595dbeb8377b70da3.tar.bz2
acf-freeradius3-ead073ce065f691630cb7a3595dbeb8377b70da3.tar.xz
Add exception handling to model.get_config
-rw-r--r--freeradius3-model.lua43
1 files changed, 24 insertions, 19 deletions
diff --git a/freeradius3-model.lua b/freeradius3-model.lua
index cf76e3f..84bd7e5 100644
--- a/freeradius3-model.lua
+++ b/freeradius3-model.lua
@@ -29,27 +29,32 @@ end
local get_config = function(filecontent)
if not filecontent then
- local code, cmdresult = subprocess.call_capture({"radiusd", "-XC"})
- if 0 ~= code then
- return nil, string.match(cmdresult, "([^\n]+)\n$")
- end
- filecontent = {}
- for line in string.gmatch(cmdresult, "[^\n]+") do
- if string.match(line, "^including") then
- elseif string.match(line, "^Using") then
- elseif string.match(line, "^reading") then
- elseif string.match(line, "^Ignoring") then
- --elseif string.match(line, "^Configuration ") then
- elseif string.match(line, "^radiusd: ") then
- elseif string.match(line, "^rlm_passwd: ") then
- elseif string.match(line, "^%[/etc/raddb/") then
- elseif string.match(line, "^%s*#") then
- elseif string.match(line, "^%c") then
- else
- filecontent[#filecontent+1] = line
+ local res, err = pcall(function()
+ local code, cmdresult = subprocess.call_capture({"radiusd", "-XC"})
+ if 0 ~= code then
+ return nil, string.match(cmdresult, "([^\n]+)\n$")
+ end
+ filecontent = {}
+ for line in string.gmatch(cmdresult, "[^\n]+") do
+ if string.match(line, "^including") then
+ elseif string.match(line, "^Using") then
+ elseif string.match(line, "^reading") then
+ elseif string.match(line, "^Ignoring") then
+ --elseif string.match(line, "^Configuration ") then
+ elseif string.match(line, "^radiusd: ") then
+ elseif string.match(line, "^rlm_passwd: ") then
+ elseif string.match(line, "^%[/etc/raddb/") then
+ elseif string.match(line, "^%s*#") then
+ elseif string.match(line, "^%c") then
+ else
+ filecontent[#filecontent+1] = line
+ end
end
+ filecontent[#filecontent] = nil
+ end)
+ if not res or err then
+ return nil, err or "Unknown failure"
end
- filecontent[#filecontent] = nil
end
local config = {}
for i,line in ipairs(filecontent) do