diff options
| author | Bill Paul <wpaul@FreeBSD.org> | 1995-05-12 16:52:58 +0000 |
|---|---|---|
| committer | Bill Paul <wpaul@FreeBSD.org> | 1995-05-12 16:52:58 +0000 |
| commit | 97f3a7e6e7b2315a17055166bc138340d6f70017 (patch) | |
| tree | 43667e449cc766d4da3495966dd79e150db0e5be /usr.sbin | |
| parent | dbda9e5ed2ccb5b038c9b02d2ec12edb8a333c64 (diff) | |
Notes
Diffstat (limited to 'usr.sbin')
| -rw-r--r-- | usr.sbin/ypbind/ypbind.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/usr.sbin/ypbind/ypbind.c b/usr.sbin/ypbind/ypbind.c index b95c673df077..21cd202455ba 100644 --- a/usr.sbin/ypbind/ypbind.c +++ b/usr.sbin/ypbind/ypbind.c @@ -28,7 +28,7 @@ */ #ifndef LINT -static char rcsid[] = "$Id: ypbind.c,v 1.9 1995/05/03 18:34:22 wpaul Exp $"; +static char rcsid[] = "$Id: ypbind.c,v 1.11 1995/05/11 00:16:54 wpaul Exp $"; #endif #include <sys/param.h> @@ -65,6 +65,10 @@ static char rcsid[] = "$Id: ypbind.c,v 1.9 1995/05/03 18:34:22 wpaul Exp $"; #define BINDINGDIR "/var/yp/binding" #endif +#ifndef YPBINDLOCK +#define YPBINDLOCK "/var/run/ypbind.lock" +#endif + struct _dom_binding { struct _dom_binding *dom_pnext; char dom_domain[YPMAXDOMAIN + 1]; @@ -115,6 +119,7 @@ int child_fds[FD_SETSIZE]; static int fd[2]; int children = 0; int domains = 0; +int yplockfd; SVCXPRT *udptransp, *tcptransp; @@ -149,7 +154,7 @@ CLIENT *clnt; break; if(ypdb==NULL) { - if (domains == MAX_DOMAINS) { + if (domains >= MAX_DOMAINS) { syslog(LOG_WARNING, "domain limit (%d) exceeded", MAX_DOMAINS); res.ypbind_respbody.ypbind_error = YPBIND_ERR_RESC; @@ -313,6 +318,8 @@ int sig; ypdb->dom_domain, ypdb->dom_vers); unlink(path); } + close(yplockfd); + unlink(YPBINDLOCK); pmap_unset(YPBINDPROG, YPBINDVERS); exit(0); } @@ -329,6 +336,17 @@ char **argv; DIR *dird; struct dirent *dirp; + /* Check that another ypbind isn't already running. */ + if ((yplockfd = (open(YPBINDLOCK, O_RDONLY|O_CREAT, 0444))) == -1) { + perror(YPBINDLOCK); + exit(1); + } + + if(flock(yplockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) { + fprintf (stderr, "Another ypbind is already running. Aborting.\n"); + exit(1); + } + yp_get_default_domain(&domainname); if( domainname[0] == '\0') { fprintf(stderr, "domainname not set. Aborting.\n"); |
