summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-09-06 13:51:51 +0000
committerSteven Barth <steven@midlink.org>2008-09-06 13:51:51 +0000
commitdbde0216c29148520226a96a57be20ceb2406f45 (patch)
treeb2db4607952c7361f3f4e093e93b126210da0a76 /libs
parent8e00d27ae72245aa26feebfcf5cc0338ba1167d0 (diff)
Rewrote UCI apply logic
Diffstat (limited to 'libs')
-rw-r--r--libs/cbi/luasrc/cbi.lua2
-rw-r--r--libs/uci/luasrc/model/uci.lua60
-rw-r--r--libs/uci/root/etc/config/ucitrack47
-rw-r--r--libs/uci/root/sbin/luci-reload31
-rw-r--r--libs/web/root/etc/config/luci19
5 files changed, 134 insertions, 25 deletions
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua
index be591a80e..b00ccf8d2 100644
--- a/libs/cbi/luasrc/cbi.lua
+++ b/libs/cbi/luasrc/cbi.lua
@@ -248,11 +248,11 @@ function Map.parse(self, ...)
if luci.http.formvalue("cbi.apply") then
for i, config in ipairs(self.parsechain) do
self.uci:commit(config)
- self.uci:apply(config)
-- Refresh data because commit changes section names
self.uci:load(config)
end
+ self.uci:apply(self.parsechain)
-- Reparse sections
Node.parse(self, ...)
diff --git a/libs/uci/luasrc/model/uci.lua b/libs/uci/luasrc/model/uci.lua
index 659cd6254..8852d1e5f 100644
--- a/libs/uci/luasrc/model/uci.lua
+++ b/libs/uci/luasrc/model/uci.lua
@@ -54,14 +54,17 @@ end
local Cursor = getmetatable(cursor())
---- Applies the new config
--- @param config UCI config
-function Cursor.apply(self, config)
- local conf = require "luci.config"
- return conf.uci_oncommit[config] and
- os.execute(conf.uci_oncommit[config] .. " >/dev/null 2>&1")
+--- Applies UCI configuration changes
+-- @param configlist List of UCI configurations
+-- @param command Don't apply only return the command
+function Cursor.apply(self, configlist, command)
+ configlist = self:_affected(configlist)
+ local reloadcmd = "/sbin/luci-reload " .. table.concat(configlist, " ")
+
+ return command and reloadcmd or os.execute(reloadcmd .. " >/dev/null 2>&1")
end
+
--- Delete all sections of a given type that match certain criteria.
-- @param config UCI config
-- @param type UCI section type
@@ -180,6 +183,51 @@ function Cursor.changes(self, config)
end
+-- Return a list of initscripts affected by configuration changes.
+function Cursor._affected(self, configlist)
+ configlist = type(configlist) == "table" and configlist or {configlist}
+
+ local c = cursor()
+ c:load("ucitrack")
+
+ -- Resolve dependencies
+ local reloadlist = {}
+
+ local function _resolve_deps(name)
+ local reload = {name}
+ local deps = {}
+
+ c:foreach("ucitrack", name,
+ function(section)
+ if section.affects then
+ for i, aff in ipairs(section.affects) do
+ table.insert(deps, aff)
+ end
+ end
+ end)
+
+ for i, dep in ipairs(deps) do
+ for j, add in ipairs(_resolve_deps(dep)) do
+ table.insert(reload, add)
+ end
+ end
+
+ return reload
+ end
+
+ -- Collect initscripts
+ for j, config in ipairs(configlist) do
+ for i, e in ipairs(_resolve_deps(config)) do
+ if not util.contains(reloadlist, e) then
+ table.insert(reloadlist, e)
+ end
+ end
+ end
+
+ return reloadlist
+end
+
+
--- Add an anonymous section.
-- @class function
-- @name Cursor.add
diff --git a/libs/uci/root/etc/config/ucitrack b/libs/uci/root/etc/config/ucitrack
new file mode 100644
index 000000000..cba783d8b
--- /dev/null
+++ b/libs/uci/root/etc/config/ucitrack
@@ -0,0 +1,47 @@
+config network
+ option init network
+ list affects dhcp
+
+config wireless
+ list affects network
+
+config firewall
+ option init firewall
+ list affects luci-splash
+ list affects qos
+
+config olsr
+ option init olsrd
+
+config dhcp
+ option init dnsmasq
+
+config dropbear
+ option init dropbear
+
+config httpd
+ option init httpd
+
+config fstab
+ option init fstab
+
+config qos
+ option init qos
+
+config system
+ option init led
+
+config luci_ethers
+ option init luci_ethers
+
+config luci_splash
+ option init luci_splash
+
+config upnpd
+ option init miniupnpd
+
+config ntpclient
+ option init ntpclient
+
+config samba
+ option init samba \ No newline at end of file
diff --git a/libs/uci/root/sbin/luci-reload b/libs/uci/root/sbin/luci-reload
new file mode 100644
index 000000000..a92c6eb7f
--- /dev/null
+++ b/libs/uci/root/sbin/luci-reload
@@ -0,0 +1,31 @@
+#!/bin/sh
+. /etc/functions.sh
+
+apply_config() {
+ config_get init "$1" init
+ config_get exec "$1" exec
+
+ [ -n "$init" ] && reload_init "$2" "$init"
+ [ -n "$exec" ] && reload_exec "$2" "$exec"
+}
+
+reload_exec() {
+ [ -x $2 ] && {
+ echo -n "Reloading $1... "
+ $2 >/dev/null 2>&1 && echo "done." || echo "failed!"
+ }
+}
+
+reload_init() {
+ [ -x /etc/init.d/$2 ] && /etc/init.d/$2 enabled && {
+ echo -n "Reloading $1... "
+ /etc/init.d/$2 reload >/dev/null 2>&1 && echo "done." || echo "failed!"
+ }
+}
+
+config_load ucitrack
+
+for i in $*
+do
+ config_foreach apply_config $i
+done \ No newline at end of file
diff --git a/libs/web/root/etc/config/luci b/libs/web/root/etc/config/luci
index 8b222aaaa..f78fbb02b 100644
--- a/libs/web/root/etc/config/luci
+++ b/libs/web/root/etc/config/luci
@@ -17,24 +17,7 @@ config extern flash_keep
option ipkg "/etc/ipkg.conf"
option httpd "/etc/httpd.conf"
option firewall "/etc/firewall.user"
-
-config event uci_oncommit
- option network "/sbin/luci-reload network firewall dnsmasq luci_splash"
- option wireless "/sbin/luci-reload network firewall dnsmasq luci_splash"
- option olsr "/sbin/luci-reload olsrd"
- option dhcp "/sbin/luci-reload dnsmasq"
- option dropbear "/sbin/luci-reload dropbear"
- option httpd "/sbin/luci-reload httpd"
- option fstab "/sbin/luci-reload fstab"
- option qos "/sbin/luci-reload qos"
- option system "/sbin/luci-reload led"
- option firewall "/sbin/luci-reload firewall luci_splash"
- option luci_ethers "/sbin/luci-reload luci_ethers dnsmasq"
- option luci_splash "/sbin/luci-reload firewall luci_splash"
- option upnpd "/etc/init.d/miniupnpd enabled && /sbin/luci-reload miniupnpd || /etc/init.d/miniupnpd stop"
- option ntpclient "/sbin/luci-reload ntpclient"
- option samba "/sbin/luci-reload samba"
-
+
config internal languages
config internal sauth