summaryrefslogtreecommitdiff
path: root/lib/libc/yp/yplib.c
diff options
context:
space:
mode:
authorBill Paul <wpaul@FreeBSD.org>1995-11-05 05:39:04 +0000
committerBill Paul <wpaul@FreeBSD.org>1995-11-05 05:39:04 +0000
commit0f98415ed42fd2b5dd707221fd19037211138ded (patch)
treef0c69a79e92e1b71594eefe682b639522e37d87a /lib/libc/yp/yplib.c
parentdeb0ea412522f9964e3bb35e4a80d0d5871c6a8e (diff)
Notes
Diffstat (limited to 'lib/libc/yp/yplib.c')
-rw-r--r--lib/libc/yp/yplib.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c
index 3d9e2caeadc3..2765a9bd649b 100644
--- a/lib/libc/yp/yplib.c
+++ b/lib/libc/yp/yplib.c
@@ -28,7 +28,7 @@
*/
#ifndef LINT
-static char *rcsid = "$Id: yplib.c,v 1.11 1995/07/05 06:04:20 wpaul Exp $";
+static char *rcsid = "$Id: yplib.c,v 1.12 1995/09/02 04:16:21 wpaul Exp $";
#endif
#include <sys/param.h>
@@ -46,6 +46,10 @@ static char *rcsid = "$Id: yplib.c,v 1.11 1995/07/05 06:04:20 wpaul Exp $";
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
+#ifndef YPBINDLOCK
+#define YPBINDLOCK "/var/run/ypbind.lock"
+#endif
+
#ifndef BINDINGDIR
#define BINDINGDIR "/var/yp/binding"
#endif
@@ -199,7 +203,7 @@ struct dom_binding **ypdb;
struct ypbind_resp ypbr;
struct timeval tv;
struct sockaddr_in clnt_sin;
- int clnt_sock, fd, gpid;
+ int clnt_sock, lfd, fd, gpid;
CLIENT *client;
int new = 0, r;
int retries = 0;
@@ -234,6 +238,21 @@ struct dom_binding **ypdb;
ysd->dom_vers = 0;
new = 1;
}
+
+ if ((lfd = open(YPBINDLOCK, O_RDONLY)) == -1)
+ return(YPERR_YPBIND);
+ errno = 0;
+ switch (flock(lfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
+ case 0:
+ close(lfd);
+ return (YPERR_YPBIND);
+ break;
+ case 1:
+ default:
+ close(lfd);
+ break;
+ }
+
again:
retries++;
if (retries > MAX_RETRIES) {
@@ -865,7 +884,9 @@ char **dom;
if(dom)
*dom = _yp_domain;
- if( yp_bind(_yp_domain)==0 )
+ if( yp_bind(_yp_domain)==0 ) {
+ yp_unbind(_yp_domain);
return 1;
+ }
return 0;
}