Modify

Opened 4 years ago

Last modified 4 years ago

#14707 new defect

Problem with list when processing UCI file from shell with callbacks

Reported by: csadam Owned by: developers
Priority: low Milestone: Barrier Breaker 14.07
Component: packages Version: Attitude Adjustment 12.09
Keywords: Cc:

Description

Processing an UCI file from shell script using /etc/functions.sh with callback functions does not work well if the config file contains list options.
For each list line not only the list_cb is called, but there are two unnecessary option_cb calls too which should not happen.

See the example below.
Config file:

config system
        option hostname OpenWrt
        option timezone UTC

config timeserver ntp
        list server     0.openwrt.pool.ntp.org
        list server     1.openwrt.pool.ntp.org
        list server     2.openwrt.pool.ntp.org
        list server     3.openwrt.pool.ntp.org
        option enable_server 0

Test script:

#!/bin/sh
. /etc/functions.sh
config_cb() {
    local type="$1"
    local name="$2"
    if [ ! -z $type ] ;then
      echo New section - type: "$type", name: "$name"
    else
      echo "End of configuration"
    fi
    }
 
option_cb() {
    local name="$1"
    local value="$2"
    echo "  new option - name:" "$name", value: "$value", in section: $CONFIG_SECTION
    }
 
list_cb() {
    local name="$1"
    local value="$2"
    echo "  new list element - name:" "$name", value: "$value", in section: $CONFIG_SECTION
    }
 
echo Loading system config:
config_load system

Result:

# ./UCIcallbacktest.sh
Loading system config:
New section - type: system, name: cfg02e48a
  new option - name: hostname, value: OpenWrt, in section: cfg02e48a
  new option - name: timezone, value: UTC, in section: cfg02e48a
New section - type: timeserver, name: ntp
  new option - name: server_ITEM1, value: 0.openwrt.pool.ntp.org, in section: ntp
  new option - name: server_LENGTH, value: 1, in section: ntp
  new list element - name: server, value: 0.openwrt.pool.ntp.org, in section: ntp
  new option - name: server_ITEM2, value: 1.openwrt.pool.ntp.org, in section: ntp
  new option - name: server_LENGTH, value: 2, in section: ntp
  new list element - name: server, value: 1.openwrt.pool.ntp.org, in section: ntp
  new option - name: server_ITEM3, value: 2.openwrt.pool.ntp.org, in section: ntp
  new option - name: server_LENGTH, value: 3, in section: ntp
  new list element - name: server, value: 2.openwrt.pool.ntp.org, in section: ntp
  new option - name: server_ITEM4, value: 3.openwrt.pool.ntp.org, in section: ntp
  new option - name: server_LENGTH, value: 4, in section: ntp
  new list element - name: server, value: 3.openwrt.pool.ntp.org, in section: ntp
  new option - name: enable_server, value: 0, in section: ntp
End of configuration

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by jow

  • Milestone changed from Attitude Adjustment 12.09 to Barrier Breaker 14.07

Milestone Attitude Adjustment 12.09 deleted

Add Comment

Modify Ticket

Action
as new .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.