Some small signal handling tweaks: be sure to keep wait3()ing until all

children are reaped and make sure to block SIGCHLD delivery during handler
execution when installing SIGCHLD handler with sigaction().
This commit is contained in:
Bill Paul 1995-07-15 23:27:49 +00:00
parent c0837c7e13
commit 1ede0846a7
3 changed files with 9 additions and 11 deletions

View File

@ -24,7 +24,7 @@
** Ported to FreeBSD and hacked all to pieces
** by Bill Paul <wpaul@ctr.columbia.edu>
**
** $Id: server.c,v 1.9 1995/07/14 01:56:49 wpaul Exp $
** $Id: server.c,v 1.7 1995/07/02 18:48:21 wpaul Exp $
**
*/
@ -808,8 +808,8 @@ int sig;
{
int st;
children--;
wait3(&st, WNOHANG, NULL);
while (wait3(&st, WNOHANG, NULL) > 0)
children--;
}
/*
@ -861,7 +861,7 @@ ypresp_xfr *ypproc_xfr_2_svc(ypreq_xfr *xfr,
switch(fork())
{
case 0:
{
{
char g[11], t[11], p[11];
sprintf (ypxfr_command, "%s/ypxfr", INSTDIR);
@ -873,13 +873,10 @@ ypresp_xfr *ypproc_xfr_2_svc(ypreq_xfr *xfr,
inet_ntoa(rqhost->sin_addr), p, xfr->map_parms.map, NULL);
Perror("ypxfr execl(): %s",strerror(errno));
exit(0);
}
}
case -1:
{
Perror("fork(): %s",strerror(errno));
result.xfrstat = YPXFR_XFRERR;
break;
}
default:
{
result.xfrstat = YPXFR_SUCC;

View File

@ -329,6 +329,7 @@ int main(int argc, char **argv)
sigaction(SIGCHLD, NULL, &sa);
sa.sa_flags |= SA_RESTART;
sa.sa_handler = reapchild;
sa.sa_mask = sigmask(SIGCHLD);
sigaction(SIGCHLD, &sa, NULL);
(void) pmap_unset(YPPROG, YPVERS);

View File

@ -28,7 +28,7 @@
*/
#ifndef LINT
static char rcsid[] = "$Id: ypbind.c,v 1.14 1995/05/29 16:39:52 wpaul Exp $";
static char rcsid[] = "$Id: ypbind.c,v 1.15 1995/05/30 03:55:13 rgrimes Exp $";
#endif
#include <sys/param.h>
@ -316,7 +316,8 @@ int sig;
{
int st;
wait3(&st, WNOHANG, NULL);
while(wait3(&st, WNOHANG, NULL) > 0)
children--;
}
void terminate(sig)
@ -462,7 +463,6 @@ char **argv;
for(ypdb=ypbindlist; ypdb; ypdb=ypdb->dom_pnext) {
if (READFD > 0 && FD_ISSET(READFD, &fdsr)) {
handle_children(ypdb);
children--;
if (children == (MAX_CHILDREN - 1))
checkwork();
}