diff options
author | wpaul <wpaul@FreeBSD.org> | 1999-04-29 20:24:00 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 1999-04-29 20:24:00 +0000 |
commit | bcdf933fad0276458853d00c92945926de3b1381 (patch) | |
tree | 129833c0be36d80e1276a9a68011ffd8e7af8173 /usr.sbin/ypserv/yp_server.c | |
parent | 7634f5f76b08db127fd33f5f3285d870f9d640a0 (diff) | |
download | FreeBSD-src-bcdf933fad0276458853d00c92945926de3b1381.zip FreeBSD-src-bcdf933fad0276458853d00c92945926de3b1381.tar.gz |
Add some extra checks to make sure that a child ypserv process doesn't
try to fork() a child of its own, which could result in several children
ypservs running at once. I'm still not sure exactly what leads to this
condition, but these fixes should stop it from causing trouble. A new
function, yp_fork() checks to see if the current process is already a
child of the parent ypserv, and returns failure (and logs an error message)
rather than spawning another child.
Diffstat (limited to 'usr.sbin/ypserv/yp_server.c')
-rw-r--r-- | usr.sbin/ypserv/yp_server.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/usr.sbin/ypserv/yp_server.c b/usr.sbin/ypserv/yp_server.c index 76cb5ea..b771468 100644 --- a/usr.sbin/ypserv/yp_server.c +++ b/usr.sbin/ypserv/yp_server.c @@ -33,7 +33,7 @@ #ifndef lint static const char rcsid[] = - "$Id: yp_server.c,v 1.26 1998/02/11 19:15:32 wpaul Exp $"; + "$Id: yp_server.c,v 1.27 1999/02/10 16:16:14 wpaul Exp $"; #endif /* not lint */ #include "yp.h" @@ -49,7 +49,6 @@ static const char rcsid[] = #include <arpa/inet.h> #include <rpc/rpc.h> -int forked = 0; int children = 0; #define MASTER_STRING "YP_MASTER_NAME" @@ -57,6 +56,17 @@ int children = 0; #define ORDER_STRING "YP_LAST_MODIFIED" #define ORDER_SZ sizeof(ORDER_STRING) - 1 +static pid_t yp_fork() +{ + if (yp_pid != getpid()) { + yp_error("child %d trying to fork!", getpid()); + errno = EEXIST; + return(-1); + } + + return(fork()); +} + /* * NIS v2 support. This is where most of the action happens. */ @@ -350,7 +360,7 @@ ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) YPXFR_RETURN(YPXFR_REFUSED) } - switch(fork()) { + switch(yp_fork()) { case 0: { char g[11], t[11], p[11]; @@ -380,7 +390,6 @@ ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) p, argp->map_parms.map, NULL); } - forked++; yp_error("ypxfr execl(%s): %s", ypxfr_command, strerror(errno)); YPXFR_RETURN(YPXFR_XFRERR) break; @@ -392,7 +401,6 @@ ypproc_xfr_2_svc(ypreq_xfr *argp, struct svc_req *rqstp) default: result.xfrstat = YPXFR_SUCC; children++; - forked = 0; break; } @@ -507,9 +515,8 @@ ypproc_all_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) * async socket I/O?) */ if (!debug) { - switch(fork()) { + switch(yp_fork()) { case 0: - forked++; break; case -1: yp_error("ypall fork(): %s", strerror(errno)); @@ -518,7 +525,6 @@ ypproc_all_2_svc(ypreq_nokey *argp, struct svc_req *rqstp) break; default: children++; - forked = 0; return (NULL); break; } |