Browse code

module initialization changed to have the same order as load_module commands (delimited by NO_REVERSE_INIT define)

Jiri Kuthan authored on 15/11/2002 22:54:34
Showing 1 changed files
... ...
@@ -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 278
 		if  ((t->exports)&&(t->exports->destroy_f)) t->exports->destroy_f();
279 279
 }
280 280
 
281
+#ifdef NO_REVERSE_INIT
281 282
 
282 283
 /*
283 284
  * Initialize all loaded modules, the initialization
... ...
@@ -297,3 +278,110 @@ int init_modules(void)
297 297
 	}
298 298
 	return 0;
299 299
 }
300
+
301
+/*
302
+ * per-child initialization
303
+ */
304
+int init_child(int rank)
305
+{
306
+	struct sr_module* t;
307
+
308
+	for(t = modules; t; t = t->next) {
309
+		if (t->exports->init_child_f) {
310
+			if ((t->exports->init_child_f(rank)) < 0) {
311
+				LOG(L_ERR, "init_child(): Initialization of child %d failed\n",
312
+						rank);
313
+				return -1;
314
+			}
315
+		}
316
+	}
317
+	return 0;
318
+}
319
+
320
+#else
321
+
322
+
323
+/* recursive module child initialization; (recursion is used to
324
+   process the module linear list in the same order in
325
+   which modules are loaded in config file
326
+*/
327
+
328
+static int init_mod_child( struct sr_module* m, int rank )
329
+{
330
+	if (m) {
331
+		/* iterate through the list; if error occurs,
332
+		   propagate it up the stack
333
+		 */
334
+		if (init_mod_child(m->next, rank)!=0) return -1;
335
+		if (m->exports && m->exports->init_child_f) {
336
+			DBG("DEBUG: init_mod_child (%d): %s\n", 
337
+					rank, m->exports->name);
338
+			if (m->exports->init_child_f(rank)<0) {
339
+				LOG(L_ERR, "init_mod_child(): Error while initializing"
340
+							" module %s\n", m->exports->name);
341
+				return -1;
342
+			} else {
343
+				/* module correctly initialized */
344
+				return 0;
345
+			}
346
+		}
347
+		/* no init function -- proceed with success */
348
+		return 0;
349
+	} else {
350
+		/* end of list */
351
+		return 0;
352
+	}
353
+}
354
+
355
+
356
+/*
357
+ * per-child initialization
358
+ */
359
+int init_child(int rank)
360
+{
361
+	return init_mod_child(modules, rank);
362
+}
363
+
364
+
365
+
366
+/* recursive module initialization; (recursion is used to
367
+   process the module linear list in the same order in
368
+   which modules are loaded in config file
369
+*/
370
+
371
+static int init_mod( struct sr_module* m )
372
+{
373
+	if (m) {
374
+		/* iterate through the list; if error occurs,
375
+		   propagate it up the stack
376
+		 */
377
+		if (init_mod(m->next)!=0) return -1;
378
+		if (m->exports && m->exports->init_f) {
379
+			DBG("DEBUG: init_mod: %s\n", m->exports->name);
380
+			if (m->exports->init_f()!=0) {
381
+				LOG(L_ERR, "init_mod(): Error while initializing"
382
+							" module %s\n", m->exports->name);
383
+				return -1;
384
+			} else {
385
+				/* module correctly initialized */
386
+				return 0;
387
+			}
388
+		}
389
+		/* no init function -- proceed with success */
390
+		return 0;
391
+	} else {
392
+		/* end of list */
393
+		return 0;
394
+	}
395
+}
396
+
397
+/*
398
+ * Initialize all loaded modules, the initialization
399
+ * is done *AFTER* the configuration file is parsed
400
+ */
401
+int init_modules(void)
402
+{
403
+	return init_mod(modules);
404
+}
405
+
406
+#endif