[package] base-files: cached state vars after scan_interfaces might be out of sync...
[openwrt.git] / package / base-files / files / usr / share / udhcpc / default.script
index ceabf4b..92e3474 100755 (executable)
@@ -21,9 +21,9 @@ setup_interface () {
        local user_router
 
        [ -n "$ifc" ] && {
        local user_router
 
        [ -n "$ifc" ] && {
-               config_get old_ip        "$ifc" ipaddr
-               config_get old_broadcast "$ifc" broadcast
-               config_get old_subnet    "$ifc" netmask
+               old_ip="$(uci_get_state network "$ifc" ipaddr)"
+               old_broadcast="$(uci_get_state network "$ifc" broadcast)"
+               old_subnet="$(uci_get_state network "$ifc" netmask)"
        }
 
        [ "$ip" != "$old_ip" ] \
        }
 
        [ "$ip" != "$old_ip" ] \
@@ -139,21 +139,21 @@ setup_interface () {
        }
 
        # DNS
        }
 
        # DNS
-       config_get old_dns "$ifc" dns
+       old_dns=$(uci_get_state network "$ifc" dns)
+       old_domain=$(uci_get_state network "$ifc" dnsdomain)
        user_dns=$(uci_get "network.$ifc.dns")
        [ -n "$user_dns" ] && dns="$user_dns"
 
        user_dns=$(uci_get "network.$ifc.dns")
        [ -n "$user_dns" ] && dns="$user_dns"
 
-       [ -n "$dns" ] && [ ! -s "${RESOLV_CONF}" -o "$dns" != "$old_dns" ] && {
+       [ -n "$dns" ] && [ "$dns" != "$old_dns" -o -n "$user_dns" ] && {
                echo "udhcpc: setting dns servers: $dns"
                echo "udhcpc: setting dns servers: $dns"
-               echo -n > "${RESOLV_CONF}.tmp"
-               for i in $dns ; do
-                       echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
-               done
-               ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
-               mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
-
-               change_state network "$ifc" dnsdomain "$domain"
-               change_state network "$ifc" dns "$dns"
+               add_dns "$ifc" $dns
+
+               [ -n "$domain" ] && [ "$domain" != "$old_domain" ] && {
+                       echo "udhcpc: setting dns domain: $domain"
+                       sed -i -e "${old_domain:+/^search $old_domain$/d; }/^search $domain$/d" "${RESOLV_CONF}"
+                       echo "search $domain" >> "${RESOLV_CONF}"
+                       change_state network "$ifc" dnsdomain "$domain"
+               }
        }
 
        [ -n "$ifc" ] || return
        }
 
        [ -n "$ifc" ] || return
This page took 0.027633 seconds and 4 git commands to generate.