wait for dead children, and then abandon the live ones
This commit is contained in:
@@ -166,14 +166,14 @@ spawn_child(krb5_context context, int *socks,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static void
|
||||||
wait_for_connection(krb5_context context,
|
wait_for_connection(krb5_context context,
|
||||||
krb5_socket_t *socks, unsigned int num_socks)
|
krb5_socket_t *socks, unsigned int num_socks)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int e;
|
int e;
|
||||||
fd_set orig_read_set, read_set;
|
fd_set orig_read_set, read_set;
|
||||||
int max_fd = -1;
|
int status, max_fd = -1;
|
||||||
|
|
||||||
FD_ZERO(&orig_read_set);
|
FD_ZERO(&orig_read_set);
|
||||||
|
|
||||||
@@ -207,23 +207,20 @@ wait_for_connection(krb5_context context,
|
|||||||
for(i = 0; i < num_socks; i++) {
|
for(i = 0; i < num_socks; i++) {
|
||||||
if(FD_ISSET(socks[i], &read_set))
|
if(FD_ISSET(socks[i], &read_set))
|
||||||
if(spawn_child(context, socks, num_socks, i) == 0)
|
if(spawn_child(context, socks, num_socks, i) == 0)
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
signal(SIGCHLD, SIG_IGN);
|
signal(SIGCHLD, SIG_IGN);
|
||||||
while(1) {
|
|
||||||
int status;
|
while ((waitpid(-1, &status, WNOHANG)) > 0)
|
||||||
pid_t pid;
|
;
|
||||||
pid = waitpid(-1, &status, 0);
|
|
||||||
if(pid == -1 && errno == ECHILD)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
void
|
||||||
start_server(krb5_context context, const char *port_str)
|
start_server(krb5_context context, const char *port_str)
|
||||||
{
|
{
|
||||||
int e;
|
int e;
|
||||||
@@ -293,5 +290,5 @@ start_server(krb5_context context, const char *port_str)
|
|||||||
if(num_socks == 0)
|
if(num_socks == 0)
|
||||||
krb5_errx(context, 1, "no sockets to listen to - exiting");
|
krb5_errx(context, 1, "no sockets to listen to - exiting");
|
||||||
|
|
||||||
return wait_for_connection(context, socks, num_socks);
|
wait_for_connection(context, socks, num_socks);
|
||||||
}
|
}
|
||||||
|
@@ -141,7 +141,7 @@ random_password(char *, size_t);
|
|||||||
extern sig_atomic_t term_flag, doing_useful_work;
|
extern sig_atomic_t term_flag, doing_useful_work;
|
||||||
|
|
||||||
void parse_ports(krb5_context, const char*);
|
void parse_ports(krb5_context, const char*);
|
||||||
int start_server(krb5_context, const char*);
|
void start_server(krb5_context, const char*);
|
||||||
|
|
||||||
/* server.c */
|
/* server.c */
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user