From 075a3004502f4a195354bc8f8332a8336c3c82a1 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 30 Dec 2015 14:01:59 +0000 Subject: Add exception handling to model.get_config (cherry picked from commit ead073ce065f691630cb7a3595dbeb8377b70da3) --- freeradius3-model.lua | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'freeradius3-model.lua') 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 -- cgit v1.2.3