put all processes in a new process group
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8687 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -88,6 +88,21 @@ parse_ports(krb5_context context, const char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static pid_t pgrp;
|
||||||
|
int term_flag;
|
||||||
|
|
||||||
|
void
|
||||||
|
wait_term(int sig)
|
||||||
|
{
|
||||||
|
term_flag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
terminate(int sig)
|
||||||
|
{
|
||||||
|
killpg(pgrp, sig);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
wait_for_connection(krb5_context context,
|
wait_for_connection(krb5_context context,
|
||||||
int *socks, int num_socks)
|
int *socks, int num_socks)
|
||||||
@@ -102,6 +117,14 @@ wait_for_connection(krb5_context context,
|
|||||||
FD_SET(socks[i], &orig_read_set);
|
FD_SET(socks[i], &orig_read_set);
|
||||||
max_fd = max(max_fd, socks[i]);
|
max_fd = max(max_fd, socks[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signal(SIGTERM, terminate);
|
||||||
|
|
||||||
|
if(setpgid(0, getpid()) < 0)
|
||||||
|
err(1, "setpgid");
|
||||||
|
|
||||||
|
pgrp = getpid();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
read_set = orig_read_set;
|
read_set = orig_read_set;
|
||||||
e = select(max_fd + 1, &read_set, NULL, NULL, NULL);
|
e = select(max_fd + 1, &read_set, NULL, NULL, NULL);
|
||||||
@@ -139,6 +162,7 @@ wait_for_connection(krb5_context context,
|
|||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
|
signal(SIGTERM, wait_term);
|
||||||
for(i = 0; i < num_socks; i++)
|
for(i = 0; i < num_socks; i++)
|
||||||
close(socks[i]);
|
close(socks[i]);
|
||||||
dup2(s, STDIN_FILENO);
|
dup2(s, STDIN_FILENO);
|
||||||
|
Reference in New Issue
Block a user