1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
Index: pool.c
===================================================================
--- pool.c (revision 1600)
+++ pool.c (revision 1758)
@@ -73,8 +73,10 @@
void scoreboard_new(serverConfig_t * conf)
{
int serr;
- if ((shmid = shmget(IPC_PRIVATE, P_SIZE, 0644 | IPC_CREAT)) == -1)
- trace(TRACE_FATAL, "%s,%s: shmget failed",__FILE__,__func__);
+ if ((shmid = shmget(IPC_PRIVATE, P_SIZE, 0644 | IPC_CREAT)) == -1) {
+ serr = errno;
+ trace(TRACE_FATAL, "%s,%s: shmget failed [%s]",__FILE__,__func__, strerror(serr));
+ }
scoreboard = shmat(shmid, (void *) 0, 0);
serr=errno;
if (scoreboard == (Scoreboard_t *) (-1)) {
@@ -222,7 +236,7 @@
}
scoreboard_unlck();
trace(TRACE_FATAL,
- "%s,%s: pid NOT found on scoreboard [%d]", __FILE__, __FUNCTION__, pid);
+ "%s,%s: pid NOT found on scoreboard [%d]", __FILE__, __func__, pid);
return -1;
}
@@ -238,25 +252,25 @@
{
int i;
trace(TRACE_MESSAGE, "%s,%s: register child [%d]",
- __FILE__, __FUNCTION__, getpid());
+ __FILE__, __func__, getpid());
scoreboard_wrlck();
for (i = 0; i < scoreboard->conf->maxChildren; i++) {
if (scoreboard->child[i].pid == -1)
break;
if (scoreboard->child[i].pid == getpid()) {
- trace(TRACE_ERROR,
+ scoreboard_unlck();
+ trace(TRACE_FATAL,
"%s,%s: child already registered.",
- __FILE__, __FUNCTION__);
- scoreboard_unlck();
+ __FILE__, __func__);
return -1;
}
}
if (i == scoreboard->conf->maxChildren) {
+ scoreboard_unlck();
trace(TRACE_WARNING,
"%s,%s: no empty slot found",
- __FILE__, __FUNCTION__);
- scoreboard_unlck();
+ __FILE__, __func__);
return -1;
}
@@ -264,8 +278,8 @@
scoreboard->child[i].status = STATE_IDLE;
scoreboard_unlck();
- trace(TRACE_INFO, "%s,%s: initializing child_state [%d] using slot [%d]",
- __FILE__, __FUNCTION__, getpid(), i);
+ trace(TRACE_MESSAGE, "%s,%s: initializing child_state [%d] using slot [%d]",
+ __FILE__, __func__, getpid(), i);
return 0;
}
@@ -281,7 +295,7 @@
scoreboard->child[key].status = STATE_CONNECTED;
scoreboard_unlck();
- trace(TRACE_DEBUG, "%s,%s: [%d]", __FILE__, __FUNCTION__,
+ trace(TRACE_DEBUG, "%s,%s: [%d]", __FILE__, __func__,
getpid());
}
@@ -297,7 +311,7 @@
scoreboard->child[key].status = STATE_IDLE;
scoreboard_unlck();
- trace(TRACE_DEBUG, "%s,%s: [%d]", __FILE__, __FUNCTION__,
+ trace(TRACE_DEBUG, "%s,%s: [%d]", __FILE__, __func__,
getpid());
}
@@ -320,7 +334,7 @@
scoreboard_unlck();
trace(TRACE_MESSAGE,
- "%s,%s: child [%d] unregistered", __FILE__, __FUNCTION__,
+ "%s,%s: child [%d] unregistered", __FILE__, __func__,
getpid());
}
@@ -346,7 +360,7 @@
manage_stop_children();
trace(TRACE_FATAL,
"%s,%s: could not create children. Fatal.",
- __FILE__, __FUNCTION__);
+ __FILE__, __func__);
exit(0);
}
}
@@ -360,10 +374,17 @@
if (chpid == -1)
continue;
if (waitpid(chpid, NULL, WNOHANG|WUNTRACED) == chpid) {
+ scoreboard_release(chpid);
trace(TRACE_MESSAGE,"%s,%s: child [%d] exited. Restarting...",
- __FILE__, __FUNCTION__, chpid);
- scoreboard_release(chpid);
- CreateChild(&childinfo);
+ __FILE__, __func__, chpid);
+ if (CreateChild(&childinfo)== -1) {
+ trace(TRACE_ERROR,"%s,%s: createchild failed. Bailout...",
+ __FILE__, __func__);
+ GeneralStopRequested=1;
+ manage_stop_children();
+
+ exit(1);
+ }
}
}
sleep(1);
|