Die after receiving SIGUSR1 and when number of children goes to zero.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@778 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
42
appl/kx/kx.c
42
appl/kx/kx.c
@@ -6,6 +6,42 @@ char *prog;
|
|||||||
|
|
||||||
static u_int32_t display_num;
|
static u_int32_t display_num;
|
||||||
static char xauthfile[MaxPathLen];
|
static char xauthfile[MaxPathLen];
|
||||||
|
static int nchild;
|
||||||
|
static int donep;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Signal handler that justs waits for the children when they die.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static RETSIGTYPE
|
||||||
|
childhandler (int sig)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
do {
|
||||||
|
pid = waitpid (-1, &status, WNOHANG|WUNTRACED);
|
||||||
|
if (pid > 0 && WIFEXITED(status) || WIFSIGNALED(status))
|
||||||
|
if (--nchild == 0 && donep)
|
||||||
|
exit (0);
|
||||||
|
} while(pid > 0);
|
||||||
|
signal (SIGCHLD, childhandler);
|
||||||
|
SIGRETURN(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handler for SIGUSR1.
|
||||||
|
* This signal means that we should wait until there are no children
|
||||||
|
* left and then exit.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static RETSIGTYPE
|
||||||
|
usr1handler (int sig)
|
||||||
|
{
|
||||||
|
donep = 1;
|
||||||
|
|
||||||
|
SIGRETURN(0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Establish authenticated connection
|
* Establish authenticated connection
|
||||||
@@ -267,14 +303,14 @@ doit (char *host, int passivep, int debugp)
|
|||||||
/* close (otherside); */
|
/* close (otherside); */
|
||||||
fn = passive;
|
fn = passive;
|
||||||
if(debugp)
|
if(debugp)
|
||||||
printf ("%d\t%s\n", display_num, xauthfile);
|
printf ("%d\t%d\t%s\n", getpid(), display_num, xauthfile);
|
||||||
else {
|
else {
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
fprintf (stderr, "%s: fork: %s\n", prog, strerror(errno));
|
fprintf (stderr, "%s: fork: %s\n", prog, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
} else if (pid > 0) {
|
} else if (pid > 0) {
|
||||||
printf ("%d\t%s\n", display_num, xauthfile);
|
printf ("%d\t%d\t%s\n", pid, display_num, xauthfile);
|
||||||
exit (0);
|
exit (0);
|
||||||
} else {
|
} else {
|
||||||
fclose(stdout);
|
fclose(stdout);
|
||||||
@@ -300,6 +336,7 @@ doit (char *host, int passivep, int debugp)
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
++nchild;
|
||||||
child = fork ();
|
child = fork ();
|
||||||
if (child < 0) {
|
if (child < 0) {
|
||||||
fprintf (stderr, "%s: fork: %s\n", prog,
|
fprintf (stderr, "%s: fork: %s\n", prog,
|
||||||
@@ -360,5 +397,6 @@ main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
passivep = 1;
|
passivep = 1;
|
||||||
signal (SIGCHLD, childhandler);
|
signal (SIGCHLD, childhandler);
|
||||||
|
signal (SIGUSR1, usr1handler);
|
||||||
return doit (argv[0], passivep, debugp);
|
return doit (argv[0], passivep, debugp);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user