mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
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.
This commit is contained in:
parent
bb1cf6eb32
commit
2dfb116a5a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=46186
@ -29,7 +29,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: yp_extern.h,v 1.11 1997/02/22 16:15:11 peter Exp $
|
||||
* $Id: yp_extern.h,v 1.12 1997/10/29 07:25:03 charnier Exp $
|
||||
*/
|
||||
|
||||
#include <db.h>
|
||||
@ -68,6 +68,8 @@ extern int children;
|
||||
extern int resfd;
|
||||
extern char *progname;
|
||||
extern char *yp_dir;
|
||||
extern pid_t yp_pid;
|
||||
|
||||
extern enum ypstat yp_errno;
|
||||
extern void yp_error __P((const char *, ...));
|
||||
#ifdef DB_CACHE
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id: yp_main.c,v 1.18 1998/06/04 15:11:14 wpaul Exp $";
|
||||
"$Id: yp_main.c,v 1.19 1999/02/10 16:16:14 wpaul Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
@ -99,6 +99,8 @@ void _msgout(char* msg)
|
||||
syslog(LOG_ERR, msg);
|
||||
}
|
||||
|
||||
pid_t yp_pid;
|
||||
|
||||
static void
|
||||
yp_svc_run()
|
||||
{
|
||||
@ -108,12 +110,11 @@ yp_svc_run()
|
||||
int readfds;
|
||||
#endif /* def FD_SETSIZE */
|
||||
extern int forked;
|
||||
int pid;
|
||||
int fd_setsize = _rpc_dtablesize();
|
||||
struct timeval timeout;
|
||||
|
||||
/* Establish the identity of the parent ypserv process. */
|
||||
pid = getpid();
|
||||
yp_pid = getpid();
|
||||
|
||||
for (;;) {
|
||||
#ifdef FD_SETSIZE
|
||||
@ -135,16 +136,19 @@ yp_svc_run()
|
||||
warn("svc_run: - select failed");
|
||||
return;
|
||||
case 0:
|
||||
yp_prune_dnsq();
|
||||
if (getpid() == yp_pid)
|
||||
yp_prune_dnsq();
|
||||
break;
|
||||
default:
|
||||
if (FD_ISSET(resfd, &readfds)) {
|
||||
yp_run_dnsq();
|
||||
FD_CLR(resfd, &readfds);
|
||||
if (getpid() == yp_pid) {
|
||||
if (FD_ISSET(resfd, &readfds)) {
|
||||
yp_run_dnsq();
|
||||
FD_CLR(resfd, &readfds);
|
||||
}
|
||||
svc_getreqset(&readfds);
|
||||
}
|
||||
svc_getreqset(&readfds);
|
||||
}
|
||||
if (forked && pid != getpid())
|
||||
if (yp_pid != getpid())
|
||||
_exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user