X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=applications%2Fluci-app-openvpn%2Fluasrc%2Fmodel%2Fcbi%2Fopenvpn.lua;h=719145b887bd8a1b10f776cae7a54e4175d6ca7c;hp=1a1d33aa25c81b55fd01b2778f1a52e4dc78b6e9;hb=ffcd81aa15bb6edb96108332dd4b3bbd0c8ad701;hpb=2c1777582cf8216a97518c900f511edc44eaa0f6 diff --git a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua index 1a1d33aa2..719145b88 100644 --- a/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua +++ b/applications/luci-app-openvpn/luasrc/model/cbi/openvpn.lua @@ -25,8 +25,13 @@ uci:foreach( "openvpn_recipes", "openvpn_recipe", end ) -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) @@ -73,7 +78,7 @@ s:option( Flag, "enabled", translate("Enabled") ) 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 + if pid ~= nil then return (sys.process.signal(pid, 0)) and translatef("yes (%i)", pid) or translate("no") @@ -88,7 +93,7 @@ updown.redirect = luci.dispatcher.build_url( ) 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 @@ -99,7 +104,9 @@ end 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