remove memleak patch because of issues with premature freeing of memory - i will...
[openwrt.git] / package / base-files / files / etc / functions.sh
index 8d11171..ef28015 100755 (executable)
@@ -85,19 +85,32 @@ config_clear() {
 }
 
 config_load() {
-       local file
-       case "$1" in
-               /*) file="$1";;
-               *) file="$UCI_ROOT/etc/config/$1";;
+       local cfg
+       local uci
+       local PACKAGE="$1"
+
+       case "$PACKAGE" in
+               /*)     cfg="$PACKAGE"
+                       uci=""
+               ;;
+               *)      cfg="$UCI_ROOT/etc/config/$PACKAGE"
+                       uci="/tmp/.uci/${PACKAGE}"
+               ;;
        esac
+
+       [ -e "$cfg" ] || cfg=""
+       [ -e "$uci" ] || uci=""
+
+       # no config
+       [ -z "$cfg" -a -z "$uci" ] && return 1
+
        _C=0
        export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
        export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
        export ${NO_EXPORT:+-n} CONFIG_SECTION=
-       
-       [ -e "$file" ] && {
-               . $file
-       } || return 1
+
+       ${cfg:+. "$cfg"}
+       ${uci:+. "$uci"}
        
        ${CONFIG_SECTION:+config_cb}
 }
@@ -114,9 +127,9 @@ config_get_bool() {
        local _tmp
        config_get "_tmp" "$2" "$3"
        case "$_tmp" in
-               1|on|enabled) export ${NO_EXPORT:+-n} "$1=1";;
-               0|off|disabled) export ${NO_EXPORT:+-n} "$1=0";;
-               *) eval "$1=${4:-0}";;
+               1|on|true|enabled) export ${NO_EXPORT:+-n} "$1=1";;
+               0|off|false|disabled) export ${NO_EXPORT:+-n} "$1=0";;
+               *) eval "$1=$4";;
        esac
 }
 
@@ -133,14 +146,16 @@ config_set() {
 
 config_foreach() {
        local function="$1"
-       local type="$2"
+       [ "$#" -ge 1 ] && shift
+       local type="$1"
+       [ "$#" -ge 1 ] && shift
        local section cfgtype
        
        [ -z "$CONFIG_SECTIONS" ] && return 0
        for section in ${CONFIG_SECTIONS}; do
                config_get cfgtype "$section" TYPE
                [ -n "$type" -a "x$cfgtype" != "x$type" ] && continue
-               eval "$function \"\$section\""
+               eval "$function \"\$section\" \"\$@\""
        done
 }
 
@@ -202,3 +217,9 @@ jffs2_mark_erase() {
        }
        echo -e "\xde\xad\xc0\xde" | mtd -qq write - "$1"
 }
+
+uci_set_default() {
+       local PACKAGE="$1"
+       [ -e "/etc/config/$1" ] && return 0
+       cat > "/etc/config/$1"
+}
This page took 0.030778 seconds and 4 git commands to generate.