... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
* 2003-03-19 replaced all malloc/frees w/ pkg_malloc/pkg_free (andrei) |
32 | 32 |
* 2003-03-29 pkg cleaners for fifo and script callbacks introduced (jiri) |
33 | 33 |
* 2003-03-31 removed snmp part (obsolete & no place in core) (andrei) |
34 |
+ * 2003-04-06 child_init called in all processes (janakj) |
|
34 | 35 |
* |
35 | 36 |
*/ |
36 | 37 |
|
... | ... |
@@ -640,6 +641,10 @@ int main_loop() |
640 | 641 |
/* child */ |
641 | 642 |
/* timer!*/ |
642 | 643 |
/* process_bit = 0; */ |
644 |
+ if (init_child(PROC_TIMER) < 0) { |
|
645 |
+ LOG(L_ERR, "timer: init_child failed\n"); |
|
646 |
+ goto error; |
|
647 |
+ } |
|
643 | 648 |
for(;;){ |
644 | 649 |
sleep(TIMER_TICK); |
645 | 650 |
timer_ticker(); |
... | ... |
@@ -664,11 +669,12 @@ int main_loop() |
664 | 669 |
|
665 | 670 |
|
666 | 671 |
/* We will call child_init even if we |
667 |
- * do not fork |
|
672 |
+ * do not fork - and it will be called with rank 1 because |
|
673 |
+ * in fact we behave like a child, not like main process |
|
668 | 674 |
*/ |
669 | 675 |
|
670 |
- if (init_child(0) < 0) { |
|
671 |
- LOG(L_ERR, "init_child failed\n"); |
|
676 |
+ if (init_child(1) < 0) { |
|
677 |
+ LOG(L_ERR, "main_dontfork: init_child failed\n"); |
|
672 | 678 |
goto error; |
673 | 679 |
} |
674 | 680 |
|
... | ... |
@@ -729,7 +735,7 @@ int main_loop() |
729 | 735 |
#endif |
730 | 736 |
bind_address=&sock_info[r]; /* shortcut */ |
731 | 737 |
bind_idx=r; |
732 |
- if (init_child(i) < 0) { |
|
738 |
+ if (init_child(i + 1) < 0) { |
|
733 | 739 |
LOG(L_ERR, "init_child failed\n"); |
734 | 740 |
goto error; |
735 | 741 |
} |
... | ... |
@@ -817,6 +823,10 @@ int main_loop() |
817 | 823 |
}else if (pid==0){ |
818 | 824 |
/* child */ |
819 | 825 |
/* is_main=0; */ |
826 |
+ if (init_child(PROC_TCP_MAIN) < 0) { |
|
827 |
+ LOG(L_ERR, "tcp_main: error in init_child\n"); |
|
828 |
+ goto error; |
|
829 |
+ } |
|
820 | 830 |
tcp_main_loop(); |
821 | 831 |
}else{ |
822 | 832 |
pt[process_no].pid=pid; |
... | ... |
@@ -847,6 +857,10 @@ int main_loop() |
847 | 857 |
/* process_bit = 0; */ |
848 | 858 |
is_main=1; |
849 | 859 |
|
860 |
+ if (init_child(PROC_MAIN) < 0) { |
|
861 |
+ LOG(L_ERR, "main: error in init_child\n"); |
|
862 |
+ goto error; |
|
863 |
+ } |
|
850 | 864 |
for(;;){ |
851 | 865 |
pause(); |
852 | 866 |
handle_sigs(); |
... | ... |
@@ -306,6 +306,17 @@ int init_modules(void) |
306 | 306 |
int init_child(int rank) |
307 | 307 |
{ |
308 | 308 |
struct sr_module* t; |
309 |
+ char* type; |
|
310 |
+ |
|
311 |
+ switch(rank) { |
|
312 |
+ case PROC_MAIN: type = "PROC_MAIN"; break; |
|
313 |
+ case PROC_TIMER: type = "PROC_TIMER"; break; |
|
314 |
+ case PROC_FIFO: type = "PROC_FIFO"; break; |
|
315 |
+ case PROC_TCP_MAIN: type = "PROC_TCP_MAIN"; break; |
|
316 |
+ default: type = "CHILD"; break; |
|
317 |
+ } |
|
318 |
+ DBG("init_child: initializing %s with rank %d\n", type, rank); |
|
319 |
+ |
|
309 | 320 |
|
310 | 321 |
for(t = modules; t; t = t->next) { |
311 | 322 |
if (t->exports->init_child_f) { |
... | ... |
@@ -55,10 +55,15 @@ typedef enum { |
55 | 55 |
INT_PARAM, /* Integer parameter type */ |
56 | 56 |
} modparam_t; /* Allowed types of parameters */ |
57 | 57 |
|
58 |
- |
|
59 | 58 |
#define REQUEST_ROUTE 1 /* Function can be used in request route blocks */ |
60 | 59 |
#define REPLY_ROUTE 2 /* Function can be used in reply route blocks */ |
61 | 60 |
|
61 |
+/* Macros - used as rank in child_init function */ |
|
62 |
+#define PROC_MAIN 0 /* Main ser process */ |
|
63 |
+#define PROC_TIMER -1 /* Timer attendant process */ |
|
64 |
+#define PROC_FIFO -2 /* FIFO attendant process */ |
|
65 |
+#define PROC_TCP_MAIN -4 /* TCP main process */ |
|
66 |
+ |
|
62 | 67 |
struct cmd_export_ { |
63 | 68 |
char* name; /* null terminated command name */ |
64 | 69 |
cmd_function function; /* pointer to the corresponding function */ |
... | ... |
@@ -947,8 +947,8 @@ int tcp_init_children() |
947 | 947 |
bind_address=0; /* force a SEGFAULT if someone uses a non-init. |
948 | 948 |
bind address on tcp */ |
949 | 949 |
bind_idx=0; |
950 |
- if (init_child(r+children_no) < 0) { |
|
951 |
- LOG(L_ERR, "init_child failed\n"); |
|
950 |
+ if (init_child(r+children_no+1) < 0) { |
|
951 |
+ LOG(L_ERR, "init_children failed\n"); |
|
952 | 952 |
goto error; |
953 | 953 |
} |
954 | 954 |
tcp_receive_loop(sockfd[1]); |