Skip to content

Commit

Permalink
[settings] Avoid duplicate settings block names
Browse files Browse the repository at this point in the history
Automatically unregister any settings with the same name (and position
within the settings tree) as a newly registered settings block.

This functionality is generalised out from dhcp.c.
  • Loading branch information
Michael Brown committed Jan 31, 2009
1 parent b111bdf commit d2b0081
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/settings.c
Expand Up @@ -183,12 +183,17 @@ static void reprioritise_settings ( struct settings *settings ) {
* @ret rc Return status code
*/
int register_settings ( struct settings *settings, struct settings *parent ) {
struct settings *old_settings;

/* NULL parent => add to settings root */
assert ( settings != NULL );
if ( parent == NULL )
parent = &settings_root;

/* Remove any existing settings with the same name */
if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
unregister_settings ( old_settings );

/* Add to list of settings */
ref_get ( settings->refcnt );
ref_get ( parent->refcnt );
Expand Down

0 comments on commit d2b0081

Please sign in to comment.