Revision 9b9a7143 conf/conf.c

View differences:

conf/conf.c
20 20
 *
21 21
 * There can exist up to four different configurations at one time: an active
22 22
 * one (pointed to by @config), configuration we are just switching from
23
 * (@old_config), one queued for the next reconfiguration (@future_config;
24
 * if there is one and the user wants to reconfigure once again, we just
25
 * free the previous queued config and replace it with the new one) and
26
 * finally a config being parsed (@new_config). The stored @old_config 
27
 * is also used for undo reconfiguration, which works in a similar way.
28
 * Reconfiguration could also have timeout (using @config_timer) and undo
29
 * is automatically called if the new configuration is not confirmed later.
23
 * (@old_config), one queued for the next reconfiguration (@future_config; if
24
 * there is one and the user wants to reconfigure once again, we just free the
25
 * previous queued config and replace it with the new one) and finally a config
26
 * being parsed (@new_config). The stored @old_config is also used for undo
27
 * reconfiguration, which works in a similar way. Reconfiguration could also
28
 * have timeout (using @config_timer) and undo is automatically called if the
29
 * new configuration is not confirmed later. The new config (@new_config) and
30
 * associated linear pool (@cfg_mem) is non-NULL only during parsing.
30 31
 *
31
 * Loading of new configuration is very simple: just call config_alloc()
32
 * to get a new &config structure, then use config_parse() to parse a
33
 * configuration file and fill all fields of the structure
34
 * and finally ask the config manager to switch to the new
35
 * config by calling config_commit().
32
 * Loading of new configuration is very simple: just call config_alloc() to get
33
 * a new &config structure, then use config_parse() to parse a configuration
34
 * file and fill all fields of the structure and finally ask the config manager
35
 * to switch to the new config by calling config_commit().
36 36
 *
37 37
 * CLI commands are parsed in a very similar way -- there is also a stripped-down
38 38
 * &config structure associated with them and they are lex-ed and parsed by the
......
91 91
  linpool *l = lp_new(p, 4080);
92 92
  struct config *c = lp_allocz(l, sizeof(struct config));
93 93

  
94
  /* Duplication of name string in local linear pool */
95
  uint nlen = strlen(name) + 1;
96
  char *ndup = lp_allocu(l, nlen);
97
  memcpy(ndup, name, nlen);
98

  
94 99
  c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */
95 100
  c->pool = p;
96
  cfg_mem = c->mem = l;
97
  c->file_name = cfg_strdup(name);
101
  c->mem = l;
102
  c->file_name = ndup;
98 103
  c->load_time = now;
99 104
  c->tf_route = c->tf_proto = (struct timeformat){"%T", "%F", 20*3600};
100 105
  c->tf_base = c->tf_log = (struct timeformat){"%F %T", NULL, 0};
......
119 124
int
120 125
config_parse(struct config *c)
121 126
{
127
  int done = 0;
122 128
  DBG("Parsing configuration file `%s'\n", c->file_name);
123 129
  new_config = c;
124 130
  cfg_mem = c->mem;
125 131
  if (setjmp(conf_jmpbuf))
126
    return 0;
132
    goto cleanup;
133

  
127 134
  cf_lex_init(0, c);
128 135
  sysdep_preconfig(c);
129 136
  protos_preconfig(c);
......
137 144
  if (!c->router_id)
138 145
    cf_error("Router ID must be configured manually on IPv6 routers");
139 146
#endif
140
  return 1;
147
  done = 1;
148

  
149
cleanup:
150
  new_config = NULL;
151
  cfg_mem = NULL;
152
  return done;
141 153
}
142 154

  
143 155
/**
......
150 162
int
151 163
cli_parse(struct config *c)
152 164
{
153
  new_config = c;
165
  int done = 0;
154 166
  c->sym_fallback = config->sym_hash;
167
  new_config = c;
155 168
  cfg_mem = c->mem;
156 169
  if (setjmp(conf_jmpbuf))
157
    return 0;
170
    goto cleanup;
171

  
158 172
  cf_lex_init(1, c);
159 173
  cf_parse();
160
  return 1;
174
  done = 1;
175

  
176
cleanup:
177
  c->sym_fallback = NULL;
178
  new_config = NULL;
179
  cfg_mem = NULL;
180
  return done;
161 181
}
162 182

  
163 183
/**
......
237 257
  if (old_config && !config->shutdown)
238 258
    log(L_INFO "Reconfiguring");
239 259

  
240
  /* This should not be necessary, but it seems there are some
241
     functions that access new_config instead of config */
242
  new_config = config;
243

  
244 260
  if (old_config)
245 261
    old_config->obstacle_count++;
246 262

  
......
254 270
  DBG("protos_commit\n");
255 271
  protos_commit(c, old_config, force_restart, type);
256 272

  
257
  /* Just to be sure nobody uses that now */
258
  new_config = NULL;
259

  
260 273
  int obs = 0;
261 274
  if (old_config)
262 275
    obs = --old_config->obstacle_count;

Also available in: Unified diff