... | ... |
@@ -137,26 +137,6 @@ error: |
137 | 137 |
return ret; |
138 | 138 |
} |
139 | 139 |
|
140 |
-/* |
|
141 |
- * per-child initialization |
|
142 |
- */ |
|
143 |
-int init_child(int rank) |
|
144 |
-{ |
|
145 |
- struct sr_module* t; |
|
146 |
- |
|
147 |
- for(t = modules; t; t = t->next) { |
|
148 |
- if (t->exports->init_child_f) { |
|
149 |
- if ((t->exports->init_child_f(rank)) < 0) { |
|
150 |
- LOG(L_ERR, "init_child(): Initialization of child %d failed\n", |
|
151 |
- rank); |
|
152 |
- return -1; |
|
153 |
- } |
|
154 |
- } |
|
155 |
- } |
|
156 |
- return 0; |
|
157 |
-} |
|
158 |
- |
|
159 |
- |
|
160 | 140 |
|
161 | 141 |
/* returns 0 on success , <0 on error */ |
162 | 142 |
int load_module(char* path) |
... | ... |
@@ -278,6 +258,7 @@ void destroy_modules() |
278 | 258 |
if ((t->exports)&&(t->exports->destroy_f)) t->exports->destroy_f(); |
279 | 259 |
} |
280 | 260 |
|
261 |
+#ifdef NO_REVERSE_INIT |
|
281 | 262 |
|
282 | 263 |
/* |
283 | 264 |
* Initialize all loaded modules, the initialization |
... | ... |
@@ -297,3 +278,110 @@ int init_modules(void) |
297 | 278 |
} |
298 | 279 |
return 0; |
299 | 280 |
} |
281 |
+ |
|
282 |
+/* |
|
283 |
+ * per-child initialization |
|
284 |
+ */ |
|
285 |
+int init_child(int rank) |
|
286 |
+{ |
|
287 |
+ struct sr_module* t; |
|
288 |
+ |
|
289 |
+ for(t = modules; t; t = t->next) { |
|
290 |
+ if (t->exports->init_child_f) { |
|
291 |
+ if ((t->exports->init_child_f(rank)) < 0) { |
|
292 |
+ LOG(L_ERR, "init_child(): Initialization of child %d failed\n", |
|
293 |
+ rank); |
|
294 |
+ return -1; |
|
295 |
+ } |
|
296 |
+ } |
|
297 |
+ } |
|
298 |
+ return 0; |
|
299 |
+} |
|
300 |
+ |
|
301 |
+#else |
|
302 |
+ |
|
303 |
+ |
|
304 |
+/* recursive module child initialization; (recursion is used to |
|
305 |
+ process the module linear list in the same order in |
|
306 |
+ which modules are loaded in config file |
|
307 |
+*/ |
|
308 |
+ |
|
309 |
+static int init_mod_child( struct sr_module* m, int rank ) |
|
310 |
+{ |
|
311 |
+ if (m) { |
|
312 |
+ /* iterate through the list; if error occurs, |
|
313 |
+ propagate it up the stack |
|
314 |
+ */ |
|
315 |
+ if (init_mod_child(m->next, rank)!=0) return -1; |
|
316 |
+ if (m->exports && m->exports->init_child_f) { |
|
317 |
+ DBG("DEBUG: init_mod_child (%d): %s\n", |
|
318 |
+ rank, m->exports->name); |
|
319 |
+ if (m->exports->init_child_f(rank)<0) { |
|
320 |
+ LOG(L_ERR, "init_mod_child(): Error while initializing" |
|
321 |
+ " module %s\n", m->exports->name); |
|
322 |
+ return -1; |
|
323 |
+ } else { |
|
324 |
+ /* module correctly initialized */ |
|
325 |
+ return 0; |
|
326 |
+ } |
|
327 |
+ } |
|
328 |
+ /* no init function -- proceed with success */ |
|
329 |
+ return 0; |
|
330 |
+ } else { |
|
331 |
+ /* end of list */ |
|
332 |
+ return 0; |
|
333 |
+ } |
|
334 |
+} |
|
335 |
+ |
|
336 |
+ |
|
337 |
+/* |
|
338 |
+ * per-child initialization |
|
339 |
+ */ |
|
340 |
+int init_child(int rank) |
|
341 |
+{ |
|
342 |
+ return init_mod_child(modules, rank); |
|
343 |
+} |
|
344 |
+ |
|
345 |
+ |
|
346 |
+ |
|
347 |
+/* recursive module initialization; (recursion is used to |
|
348 |
+ process the module linear list in the same order in |
|
349 |
+ which modules are loaded in config file |
|
350 |
+*/ |
|
351 |
+ |
|
352 |
+static int init_mod( struct sr_module* m ) |
|
353 |
+{ |
|
354 |
+ if (m) { |
|
355 |
+ /* iterate through the list; if error occurs, |
|
356 |
+ propagate it up the stack |
|
357 |
+ */ |
|
358 |
+ if (init_mod(m->next)!=0) return -1; |
|
359 |
+ if (m->exports && m->exports->init_f) { |
|
360 |
+ DBG("DEBUG: init_mod: %s\n", m->exports->name); |
|
361 |
+ if (m->exports->init_f()!=0) { |
|
362 |
+ LOG(L_ERR, "init_mod(): Error while initializing" |
|
363 |
+ " module %s\n", m->exports->name); |
|
364 |
+ return -1; |
|
365 |
+ } else { |
|
366 |
+ /* module correctly initialized */ |
|
367 |
+ return 0; |
|
368 |
+ } |
|
369 |
+ } |
|
370 |
+ /* no init function -- proceed with success */ |
|
371 |
+ return 0; |
|
372 |
+ } else { |
|
373 |
+ /* end of list */ |
|
374 |
+ return 0; |
|
375 |
+ } |
|
376 |
+} |
|
377 |
+ |
|
378 |
+/* |
|
379 |
+ * Initialize all loaded modules, the initialization |
|
380 |
+ * is done *AFTER* the configuration file is parsed |
|
381 |
+ */ |
|
382 |
+int init_modules(void) |
|
383 |
+{ |
|
384 |
+ return init_mod(modules); |
|
385 |
+} |
|
386 |
+ |
|
387 |
+#endif |