Closes #628 as suggestion was implemented and tested.
Added PID handling function (Fixes https://dev.openwrt.org/ticket/21506).
Signed-off-by: Vladimir Ulrich <admin@evl.su>
o.value = option[3]
else
if option[1] == DynamicList then
o.value = option[3]
else
if option[1] == DynamicList then
function o.cfgvalue(...)
local val = AbstractValue.cfgvalue(...)
return ( val and type(val) ~= "table" ) and { val } or val
function o.cfgvalue(...)
local val = AbstractValue.cfgvalue(...)
return ( val and type(val) ~= "table" ) and { val } or val
o.value = option[3]
else
if option[1] == DynamicList then
o.value = option[3]
else
if option[1] == DynamicList then
function o.cfgvalue(...)
local val = AbstractValue.cfgvalue(...)
return ( val and type(val) ~= "table" ) and { val } or val
function o.cfgvalue(...)
local val = AbstractValue.cfgvalue(...)
return ( val and type(val) ~= "table" ) and { val } or val
-function s.getPID(section)
- return sys.exec("%s | grep -w %s | grep openvpn | grep -v grep | awk '{print $1}'" % { psstring,section} )
+function s.getPID(section) -- Universal function which returns valid pid # or nil
+ local pid = sys.exec("%s | grep -w %s | grep openvpn | grep -v grep | awk '{print $1}'" % { psstring,section} )
+ if pid and #pid > 0 and tonumber(pid) ~= nil then
+ return tonumber(pid)
+ else
+ return nil
+ end
end
function s.parse(self, section)
end
function s.parse(self, section)
local active = s:option( DummyValue, "_active", translate("Started") )
function active.cfgvalue(self, section)
local pid = s.getPID(section)
local active = s:option( DummyValue, "_active", translate("Started") )
function active.cfgvalue(self, section)
local pid = s.getPID(section)
- if pid and #pid > 0 and tonumber(pid) ~= nil then
return (sys.process.signal(pid, 0))
and translatef("yes (%i)", pid)
or translate("no")
return (sys.process.signal(pid, 0))
and translatef("yes (%i)", pid)
or translate("no")
)
function updown.cbid(self, section)
local pid = s.getPID(section)
)
function updown.cbid(self, section)
local pid = s.getPID(section)
- self._state = pid and #pid > 0 and sys.process.signal(pid, 0)
+ self._state = pid ~= nil and sys.process.signal(pid, 0)
self.option = self._state and "stop" or "start"
return AbstractValue.cbid(self, section)
end
self.option = self._state and "stop" or "start"
return AbstractValue.cbid(self, section)
end
function updown.write(self, section, value)
if self.option == "stop" then
local pid = s.getPID(section)
function updown.write(self, section, value)
if self.option == "stop" then
local pid = s.getPID(section)
- sys.process.signal(pid,15)
+ if pid ~= nil then
+ sys.process.signal(pid,15)
+ end
else
luci.sys.call("/etc/init.d/openvpn start %s" % section)
end
else
luci.sys.call("/etc/init.d/openvpn start %s" % section)
end