Pārlūkot izejas kodu

[settings] Avoid duplicate settings block names

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.
tags/v0.9.7
Michael Brown 16 gadus atpakaļ
vecāks
revīzija
d2b0081740
1 mainītis faili ar 5 papildinājumiem un 0 dzēšanām
  1. 5
    0
      src/core/settings.c

+ 5
- 0
src/core/settings.c Parādīt failu

@@ -183,12 +183,17 @@ static void reprioritise_settings ( struct settings *settings ) {
183 183
  * @ret rc		Return status code
184 184
  */
185 185
 int register_settings ( struct settings *settings, struct settings *parent ) {
186
+	struct settings *old_settings;
186 187
 
187 188
 	/* NULL parent => add to settings root */
188 189
 	assert ( settings != NULL );
189 190
 	if ( parent == NULL )
190 191
 		parent = &settings_root;
191 192
 
193
+	/* Remove any existing settings with the same name */
194
+	if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
195
+		unregister_settings ( old_settings );
196
+
192 197
 	/* Add to list of settings */
193 198
 	ref_get ( settings->refcnt );
194 199
 	ref_get ( parent->refcnt );

Notiek ielāde…
Atcelt
Saglabāt