babeld: Handle ignore options
authorBaptiste Jonglez <baptiste--git@jonglez.org>
Thu, 28 Aug 2014 11:30:08 +0000 (13:30 +0200)
committerBaptiste Jonglez <baptiste--git@jonglez.org>
Wed, 3 Sep 2014 13:01:44 +0000 (15:01 +0200)
babeld/files/babeld.init

index 65cd1cedad5c53ac75ab44d1667fd89a5c66c568..ea4b348f97d7ca35cf3696bd8b2e817f61ca5746 100755 (executable)
@@ -90,7 +90,7 @@ list_cb() {
        option_cb "$@"
 }
 
-config_cb() {
+babel_config_cb() {
        local type="$1"
        local section="$2"
        case "$type" in
@@ -109,9 +109,19 @@ config_cb() {
                        local value="$2"
                        cfg_append "interface $interface ${option//_/-} $value"
                }
-               # Also include an empty "interface $interface" statement, so
-               # that babeld operates on this interface.
-               cfg_append "interface $interface"
+               # Handle ignore options.
+               local _ignored
+               # This works because we loaded the whole configuration
+               # beforehand (see config_load below).
+               config_get_bool _ignored "$section" 'ignore' 0
+               if [ "$_ignored" -eq 1 ]
+               then
+                       option_cb() { return; }
+               else
+                       # Also include an empty "interface $interface" statement,
+                       # so that babeld operates on this interface.
+                       cfg_append "interface $interface"
+               fi
        ;;
        *)
                # Don't use reset_cb, this would also reset config_cb
@@ -124,9 +134,13 @@ start() {
        mkdir -p /var/lib
        # Start by emptying the generated config file
        >"$CONFIGFILE"
+       # First load the whole config file, without callbacks, so that we are
+       # aware of all "ignore" options in the second pass.
+       config_load babeld
        # Parse general and interface sections thanks to the "config_cb()"
        # callback.  This allows to loop over all options without having to
        # know their name in advance.
+       config_cb() { babel_config_cb "$@"; }
        config_load babeld
        # Parse filters separately, since we know which options we expect
        config_foreach babel_filter filter