Modify

Opened 11 years ago

Closed 11 years ago

#2162 closed enhancement (fixed)

Documentation of config_get

Reported by: b.candler@… Owned by: developers
Priority: low Milestone:
Component: base system Version:
Keywords: Cc:

Description

docs/config.tex describes the configuration system as follows:

"You can access already processed options with the config_get command. Syntax:


config_get <section> <option> # prints the value of the option


config_get <variable> <section> <option> # stores the value inside the variable"

However what it doesn't mention is how the sections are named, and this took me some headscratching to work out. I would like the following information to be added to the documentation.

  • Configuration sections have a heading "config <type> <name>", where the name is optional
  • If you don't provide a name, each config section is named "cfg1", "cfg2", "cfg3" etc.

So, to read the default /etc/config/system, which looks like this:

config system
    option log_ip 1.2.3.4

you need to access a section called "cfg1" as per the following code:

. /etc/functions.sh
config_load system
config_get foo cfg1 log_ip
echo "$foo"

If you try the apparently obvious "config_get foo system log_ip" it reads nothing.

Alternatively, you can scan through all sections of type "system", which is what /etc/init.d/boot does:

. /etc/functions.sh
config_load system
wibble() {
  config_get foo "$1" log_ip
  echo "$foo"
}
# call function 'wibble' for each 'config system' section, passing the section name as $1
config_foreach wibble system

This is because /etc/config/system decided not to name the section. If the config file had said

config system settings
  option log_ip 1.2.3.4

then it could have been read by "config_get foo settings log_ip"

Attachments (0)

Change History (1)

comment:1 Changed 11 years ago by nbd

  • Resolution set to fixed
  • Status changed from new to closed

added in [8342]

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


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

 
Note: See TracTickets for help on using tickets.