From 37af8f3e751a7249d9bf180a1a0b413c959ec10c Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Thu, 2 Sep 1999 19:09:25 +0000 Subject: [PATCH] (childhandler): watch for child `wait_on_pid' to die. (recv_conn): set `wait_on_pid' instead of looping on waitpid here also. This should solve the problem of kxd looping which was caused by the signal handler getting invoked before this waitpid and reaping the child leaving this poor loop without any child git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6894 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/kx/kxd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/appl/kx/kxd.c b/appl/kx/kxd.c index 736694836..37059a7b5 100644 --- a/appl/kx/kxd.c +++ b/appl/kx/kxd.c @@ -40,6 +40,9 @@ RCSID("$Id$"); +static pid_t wait_on_pid = -1; +static int done = 0; + /* * Signal handler that justs waits for the children when they die. */ @@ -52,6 +55,8 @@ childhandler (int sig) do { pid = waitpid (-1, &status, WNOHANG|WUNTRACED); + if (pid > 0 && pid == wait_on_pid) + done = 1; } while(pid > 0); signal (SIGCHLD, childhandler); SIGRETURN(0); @@ -204,12 +209,9 @@ recv_conn (int sock, kx_context *kc, cleanup (*nsockets, *sockets); fatal (kc, sock, "fork: %s", strerror(errno)); } else if (pid != 0) { - int status; - - while (waitpid (pid, &status, 0) != pid - && !WIFEXITED(status) - && !WIFSIGNALED(status)) - ; + wait_on_pid = pid; + while (!done) + pause (); cleanup (*nsockets, *sockets); exit (0); }