child_kill_children(): use method that actually works
it turned out that close()ing an fd behind the back of a thread doesn't actually cause blocking operations to get a read/write event, because the fd will stay valid to in-progress operations.
This commit is contained in:
parent
da1bc1425d
commit
d4ef2cfa62
18
src/child.c
18
src/child.c
@ -222,20 +222,24 @@ oom:
|
|||||||
*/
|
*/
|
||||||
void child_kill_children (int sig)
|
void child_kill_children (int sig)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i, tries = 0;
|
||||||
|
|
||||||
if (sig != SIGTERM) return;
|
if (sig != SIGTERM) return;
|
||||||
|
log_message (LOG_INFO,
|
||||||
|
"trying to bring down %zu threads...",
|
||||||
|
sblist_getsize(childs)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
again:
|
||||||
for (i = 0; i < sblist_getsize(childs); i++) {
|
for (i = 0; i < sblist_getsize(childs); i++) {
|
||||||
struct child *c = *((struct child**)sblist_get(childs, i));
|
struct child *c = *((struct child**)sblist_get(childs, i));
|
||||||
if (!c->done) {
|
if (!c->done) pthread_kill(c->thread, SIGCHLD);
|
||||||
/* interrupt blocking operations.
|
|
||||||
this should cause the threads to shutdown orderly. */
|
|
||||||
close(c->conn.client_fd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
usleep(16);
|
usleep(8192);
|
||||||
collect_threads();
|
collect_threads();
|
||||||
|
if (sblist_getsize(childs) != 0)
|
||||||
|
if(tries++ < 8) goto again;
|
||||||
if (sblist_getsize(childs) != 0)
|
if (sblist_getsize(childs) != 0)
|
||||||
log_message (LOG_CRIT,
|
log_message (LOG_CRIT,
|
||||||
"child_kill_children: %zu threads still alive!",
|
"child_kill_children: %zu threads still alive!",
|
||||||
|
Loading…
Reference in New Issue
Block a user