Module Name:    src
Committed By:   christos
Date:           Fri Mar  2 17:27:49 UTC 2012

Modified Files:
        src/distrib/sets/lists/comp: mi
        src/include/rpcsvc: ypclnt.h
        src/lib/libc/include: namespace.h
        src/lib/libc/yp: Makefile.inc yp_first.c yp_maplist.c yp_master.c
            yp_match.c yp_order.c ypclnt.3 yplib.c
        src/usr.bin/ypcat: ypcat.1 ypcat.c
        src/usr.bin/ypmatch: ypmatch.1 ypmatch.c

Log Message:
PR/46111: Wolfgang Stukenbrock: Add yp_setbindtries(3) so that yp operations
don't hang forever if requested.


To generate a diff of this commit:
cvs rdiff -u -r1.1743 -r1.1744 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.13 -r1.14 src/include/rpcsvc/ypclnt.h
cvs rdiff -u -r1.150 -r1.151 src/lib/libc/include/namespace.h
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/yp/Makefile.inc \
    src/lib/libc/yp/yp_first.c
cvs rdiff -u -r1.11 -r1.12 src/lib/libc/yp/yp_maplist.c
cvs rdiff -u -r1.13 -r1.14 src/lib/libc/yp/yp_master.c
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/yp/yp_match.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/yp/yp_order.c
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/yp/ypclnt.3
cvs rdiff -u -r1.43 -r1.44 src/lib/libc/yp/yplib.c
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/ypcat/ypcat.1
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/ypcat/ypcat.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/ypmatch/ypmatch.1
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/ypmatch/ypmatch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.1743 src/distrib/sets/lists/comp/mi:1.1744
--- src/distrib/sets/lists/comp/mi:1.1743	Wed Feb 29 15:07:52 2012
+++ src/distrib/sets/lists/comp/mi	Fri Mar  2 12:27:48 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.1743 2012/02/29 20:07:52 tron Exp $
+#	$NetBSD: mi,v 1.1744 2012/03/02 17:27:48 christos Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -9463,6 +9463,7 @@
 ./usr/share/man/cat3/ypclnt.0			comp-c-catman		yp,.cat
 ./usr/share/man/cat3/yperr_string.0		comp-c-catman		yp,.cat
 ./usr/share/man/cat3/ypprot_err.0		comp-c-catman		yp,.cat
+./usr/share/man/cat3/yp_setbindtries.0		comp-c-catman		yp,.cat
 ./usr/share/man/cat3/zlib.0			comp-c-catman		.cat
 ./usr/share/man/cat5/config.0			comp-util-catman	.cat
 ./usr/share/man/cat5/config.samples.0		comp-util-catman	.cat
@@ -15679,6 +15680,7 @@
 ./usr/share/man/html3/ypclnt.html		comp-c-htmlman		yp,html
 ./usr/share/man/html3/yperr_string.html		comp-c-htmlman		yp,html
 ./usr/share/man/html3/ypprot_err.html		comp-c-htmlman		yp,html
+./usr/share/man/html3/yp_setbindtries.html	comp-c-htmlman		yp,html
 ./usr/share/man/html3/zlib.html			comp-c-htmlman		html
 ./usr/share/man/html5/config.html		comp-util-htmlman	html
 ./usr/share/man/html5/config.samples.html	comp-util-htmlman	html
@@ -21971,6 +21973,7 @@
 ./usr/share/man/man3/ypclnt.3			comp-c-man		yp,.man
 ./usr/share/man/man3/yperr_string.3		comp-c-man		yp,.man
 ./usr/share/man/man3/ypprot_err.3		comp-c-man		yp,.man
+./usr/share/man/man3/yp_setbindtries.3		comp-c-man		yp,.man
 ./usr/share/man/man3/zlib.3			comp-c-man		.man
 ./usr/share/man/man5/config.5			comp-util-man		.man
 ./usr/share/man/man5/config.samples.5		comp-util-man		.man

Index: src/include/rpcsvc/ypclnt.h
diff -u src/include/rpcsvc/ypclnt.h:1.13 src/include/rpcsvc/ypclnt.h:1.14
--- src/include/rpcsvc/ypclnt.h:1.13	Wed Feb  2 23:39:33 2005
+++ src/include/rpcsvc/ypclnt.h	Fri Mar  2 12:27:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypclnt.h,v 1.13 2005/02/03 04:39:33 perry Exp $	*/
+/*	$NetBSD: ypclnt.h,v 1.14 2012/03/02 17:27:48 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -80,6 +80,7 @@ int	yp_order	(const char *, const char *
 int	yp_all		(const char *, const char *, struct ypall_callback *);
 char *	yperr_string	(int);
 int	ypprot_err	(unsigned int);
+int	yp_setbindtries	(int);
 __END_DECLS
 
 #endif /* _RPCSVC_YPCLNT_H_ */

Index: src/lib/libc/include/namespace.h
diff -u src/lib/libc/include/namespace.h:1.150 src/lib/libc/include/namespace.h:1.151
--- src/lib/libc/include/namespace.h:1.150	Wed Feb 15 10:49:46 2012
+++ src/lib/libc/include/namespace.h	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: namespace.h,v 1.150 2012/02/15 15:49:46 joerg Exp $	*/
+/*	$NetBSD: namespace.h,v 1.151 2012/03/02 17:27:49 christos Exp $	*/
 
 /*-
  * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -801,6 +801,7 @@
 #define yp_unbind		_yp_unbind
 #define yperr_string		_yperr_string
 #define ypprot_err		_ypprot_err
+#define yp_setbindtries		_yp_setbindtries
 #define dlopen			__dlopen
 #define dlclose			__dlclose
 #define dlsym			__dlsym

Index: src/lib/libc/yp/Makefile.inc
diff -u src/lib/libc/yp/Makefile.inc:1.14 src/lib/libc/yp/Makefile.inc:1.15
--- src/lib/libc/yp/Makefile.inc:1.14	Wed Feb 24 10:05:21 1999
+++ src/lib/libc/yp/Makefile.inc	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.14 1999/02/24 15:05:21 drochner Exp $
+#	$NetBSD: Makefile.inc,v 1.15 2012/03/02 17:27:49 christos Exp $
 
 # yp sources
 .PATH: ${ARCHDIR}/yp ${.CURDIR}/yp
@@ -10,4 +10,5 @@ MAN+=	ypclnt.3
 MLINKS+=ypclnt.3 yp_all.3 ypclnt.3 yp_bind.3 ypclnt.3 yp_first.3 \
 	ypclnt.3 yp_get_default_domain.3 ypclnt.3 yp_master.3 \
 	ypclnt.3 yp_match.3 ypclnt.3 yp_next.3 ypclnt.3 yp_order.3 \
-	ypclnt.3 yp_unbind.3 ypclnt.3 yperr_string.3 ypclnt.3 ypprot_err.3
+	ypclnt.3 yp_unbind.3 ypclnt.3 yperr_string.3 ypclnt.3 ypprot_err.3 \
+	ypclnt.3 yp_setbindtries.3
Index: src/lib/libc/yp/yp_first.c
diff -u src/lib/libc/yp/yp_first.c:1.14 src/lib/libc/yp/yp_first.c:1.15
--- src/lib/libc/yp/yp_first.c:1.14	Wed Dec 10 07:06:25 2003
+++ src/lib/libc/yp/yp_first.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: yp_first.c,v 1.14 2003/12/10 12:06:25 agc Exp $	 */
+/*	$NetBSD: yp_first.c,v 1.15 2012/03/02 17:27:49 christos Exp $	 */
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: yp_first.c,v 1.14 2003/12/10 12:06:25 agc Exp $");
+__RCSID("$NetBSD: yp_first.c,v 1.15 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -41,6 +41,7 @@ __RCSID("$NetBSD: yp_first.c,v 1.14 2003
 
 extern struct timeval _yplib_timeout;
 extern int _yplib_nerrs;
+extern int _yplib_bindtries;
 
 #ifdef __weak_alias
 __weak_alias(yp_first,_yp_first)
@@ -84,10 +85,11 @@ again:
 	    (xdrproc_t)xdr_ypreq_nokey,
 	    &yprnk, (xdrproc_t)xdr_ypresp_key_val, &yprkv, _yplib_timeout);
 	if (r != RPC_SUCCESS) {
-		if (++nerrs == _yplib_nerrs) {
+		if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) {
 			clnt_perror(ysd->dom_client, "yp_first: clnt_call");
 			nerrs = 0;
-		}
+		} else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries)
+			return YPERR_YPSERV;
 		ysd->dom_vers = -1;
 		goto again;
 	}
@@ -167,10 +169,11 @@ again:
 	    (xdrproc_t)xdr_ypreq_key,
 	    &yprk, (xdrproc_t)xdr_ypresp_key_val, &yprkv, _yplib_timeout);
 	if (r != RPC_SUCCESS) {
-		if (++nerrs == _yplib_nerrs) {
+		if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) {
 			clnt_perror(ysd->dom_client, "yp_next: clnt_call");
 			nerrs = 0;
-		}
+		} else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries)
+			return YPERR_YPSERV;
 		ysd->dom_vers = -1;
 		goto again;
 	}

Index: src/lib/libc/yp/yp_maplist.c
diff -u src/lib/libc/yp/yp_maplist.c:1.11 src/lib/libc/yp/yp_maplist.c:1.12
--- src/lib/libc/yp/yp_maplist.c:1.11	Wed Dec 10 07:06:25 2003
+++ src/lib/libc/yp/yp_maplist.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: yp_maplist.c,v 1.11 2003/12/10 12:06:25 agc Exp $	 */
+/*	$NetBSD: yp_maplist.c,v 1.12 2012/03/02 17:27:49 christos Exp $	 */
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: yp_maplist.c,v 1.11 2003/12/10 12:06:25 agc Exp $");
+__RCSID("$NetBSD: yp_maplist.c,v 1.12 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -40,6 +40,7 @@ __RCSID("$NetBSD: yp_maplist.c,v 1.11 20
 
 extern struct timeval _yplib_timeout;
 extern int _yplib_nerrs;
+extern int _yplib_bindtries;
 
 #ifdef __weak_alias
 __weak_alias(yp_maplist,_yp_maplist)
@@ -68,10 +69,11 @@ again:
 		   (xdrproc_t)xdr_ypdomain_wrap_string, &indomain,
 		   (xdrproc_t)xdr_ypresp_maplist, &ypml, _yplib_timeout);
 	if (r != RPC_SUCCESS) {
-		if (++nerrs == _yplib_nerrs) {
+		if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) {
 			clnt_perror(ysd->dom_client, "yp_maplist: clnt_call");
 			nerrs = 0;
-		}
+		} else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries)
+			return YPERR_YPSERV;
 		ysd->dom_vers = -1;
 		goto again;
 	}

Index: src/lib/libc/yp/yp_master.c
diff -u src/lib/libc/yp/yp_master.c:1.13 src/lib/libc/yp/yp_master.c:1.14
--- src/lib/libc/yp/yp_master.c:1.13	Wed Dec 10 07:06:25 2003
+++ src/lib/libc/yp/yp_master.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: yp_master.c,v 1.13 2003/12/10 12:06:25 agc Exp $	 */
+/*	$NetBSD: yp_master.c,v 1.14 2012/03/02 17:27:49 christos Exp $	 */
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: yp_master.c,v 1.13 2003/12/10 12:06:25 agc Exp $");
+__RCSID("$NetBSD: yp_master.c,v 1.14 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -41,6 +41,7 @@ __RCSID("$NetBSD: yp_master.c,v 1.13 200
 
 extern struct timeval _yplib_timeout;
 extern int _yplib_nerrs;
+extern int _yplib_bindtries;
 
 #ifdef __weak_alias
 __weak_alias(yp_master,_yp_master)
@@ -80,10 +81,11 @@ again:
 		      (xdrproc_t)xdr_ypreq_nokey, &yprnk,
 		      (xdrproc_t)xdr_ypresp_master, &yprm, _yplib_timeout);
 	if (r != RPC_SUCCESS) {
-		if (++nerrs == _yplib_nerrs) {
+		if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) {
 			clnt_perror(ysd->dom_client, "yp_master: clnt_call");
 			nerrs = 0;
-		}
+		} else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries)
+			return YPERR_YPSERV;
 		ysd->dom_vers = -1;
 		goto again;
 	}

Index: src/lib/libc/yp/yp_match.c
diff -u src/lib/libc/yp/yp_match.c:1.17 src/lib/libc/yp/yp_match.c:1.18
--- src/lib/libc/yp/yp_match.c:1.17	Mon Nov 28 22:12:01 2005
+++ src/lib/libc/yp/yp_match.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: yp_match.c,v 1.17 2005/11/29 03:12:01 christos Exp $	 */
+/*	$NetBSD: yp_match.c,v 1.18 2012/03/02 17:27:49 christos Exp $	 */
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: yp_match.c,v 1.17 2005/11/29 03:12:01 christos Exp $");
+__RCSID("$NetBSD: yp_match.c,v 1.18 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -47,6 +47,7 @@ __RCSID("$NetBSD: yp_match.c,v 1.17 2005
 
 extern struct timeval _yplib_timeout;
 extern int _yplib_nerrs;
+extern int _yplib_bindtries;
 extern char _yp_domain[];
 
 #ifdef __weak_alias
@@ -229,10 +230,13 @@ again:
 		      (xdrproc_t)xdr_ypresp_val, &yprv, 
 		      _yplib_timeout);
 	if (r != RPC_SUCCESS) {
-		if (++nerrs == _yplib_nerrs) {
+		if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) {
 			clnt_perror(ysd->dom_client, "yp_match: clnt_call");
 			nerrs = 0;
 		}
+		else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries) {
+			return YPERR_YPSERV;
+		}
 		ysd->dom_vers = -1;
 		goto again;
 	}

Index: src/lib/libc/yp/yp_order.c
diff -u src/lib/libc/yp/yp_order.c:1.12 src/lib/libc/yp/yp_order.c:1.13
--- src/lib/libc/yp/yp_order.c:1.12	Wed Dec 10 07:06:25 2003
+++ src/lib/libc/yp/yp_order.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: yp_order.c,v 1.12 2003/12/10 12:06:25 agc Exp $	 */
+/*	$NetBSD: yp_order.c,v 1.13 2012/03/02 17:27:49 christos Exp $	 */
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: yp_order.c,v 1.12 2003/12/10 12:06:25 agc Exp $");
+__RCSID("$NetBSD: yp_order.c,v 1.13 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -40,6 +40,7 @@ __RCSID("$NetBSD: yp_order.c,v 1.12 2003
 
 extern struct timeval _yplib_timeout;
 extern int _yplib_nerrs;
+extern int _yplib_bindtries;
 
 #ifdef __weak_alias
 __weak_alias(yp_order,_yp_order)
@@ -78,10 +79,11 @@ again:
 		      (xdrproc_t)xdr_ypresp_order, &ypro, 
 		      _yplib_timeout);
 	if (r != RPC_SUCCESS) {
-		if (++nerrs == _yplib_nerrs) {
+		if (_yplib_bindtries <= 0 && ++nerrs == _yplib_nerrs) {
 			clnt_perror(ysd->dom_client, "yp_order: clnt_call");
 			nerrs = 0;
-		}
+		} else if (_yplib_bindtries > 0 && ++nerrs == _yplib_bindtries)
+			return YPERR_YPSERV;
 	        if (r == RPC_PROCUNAVAIL) {
 			/* Case of NIS+ server in NIS compat mode */
 			r = YPERR_YPERR;

Index: src/lib/libc/yp/ypclnt.3
diff -u src/lib/libc/yp/ypclnt.3:1.24 src/lib/libc/yp/ypclnt.3:1.25
--- src/lib/libc/yp/ypclnt.3:1.24	Mon Mar 22 15:30:55 2010
+++ src/lib/libc/yp/ypclnt.3	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ypclnt.3,v 1.24 2010/03/22 19:30:55 joerg Exp $
+.\"	$NetBSD: ypclnt.3,v 1.25 2012/03/02 17:27:49 christos Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 21, 1997
+.Dd March 2, 2012
 .Dt YPCLNT 3
 .Os
 .Sh NAME
@@ -42,6 +42,7 @@
 .Nm yp_unbind ,
 .Nm yperr_string ,
 .Nm ypprot_err
+.Nm yp_setbindtries
 .Nd Interface to the YP subsystem
 .Sh LIBRARY
 .Lb libc
@@ -72,6 +73,8 @@
 .Fn yperr_string "int incode"
 .Ft int
 .Fn ypprot_err "unsigned int incode"
+.Ft int
+.Fn yp_setbindtries "int ntries"
 .Sh DESCRIPTION
 The
 .Nm ypclnt
@@ -348,6 +351,17 @@ protocol error code to a
 .Nm ypclnt
 error code suitable for
 .Fn yperr_string .
+.It Fn yp_setbindtries
+Set the number of tries to attempt to bind to the domain before returning
+an error.
+The default is
+.Dv 0
+which means wait forever if no ypserver is not found of if the RPC
+communication with the yp server fails.
+If the number passed is negative, the current number of tries is not modified.
+.Pp
+This function is an extention to the client library that allows application
+to catch communication problems with the ypserver without blocking forever.
 .El
 .Sh RETURN VALUES
 All functions in the

Index: src/lib/libc/yp/yplib.c
diff -u src/lib/libc/yp/yplib.c:1.43 src/lib/libc/yp/yplib.c:1.44
--- src/lib/libc/yp/yplib.c:1.43	Fri Nov  3 15:18:49 2006
+++ src/lib/libc/yp/yplib.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: yplib.c,v 1.43 2006/11/03 20:18:49 christos Exp $	 */
+/*	$NetBSD: yplib.c,v 1.44 2012/03/02 17:27:49 christos Exp $	 */
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: yplib.c,v 1.43 2006/11/03 20:18:49 christos Exp $");
+__RCSID("$NetBSD: yplib.c,v 1.44 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include "namespace.h"
@@ -67,11 +67,13 @@ struct timeval _yplib_timeout = { YPLIB_
 struct timeval _yplib_rpc_timeout = { YPLIB_TIMEOUT / YPLIB_RPC_RETRIES,
 	1000000 * (YPLIB_TIMEOUT % YPLIB_RPC_RETRIES) / YPLIB_RPC_RETRIES };
 int _yplib_nerrs = 5;
+int _yplib_bindtries = 0;
 
 #ifdef __weak_alias
 __weak_alias(yp_bind, _yp_bind)
 __weak_alias(yp_unbind, _yp_unbind)
 __weak_alias(yp_get_default_domain, _yp_get_default_domain)
+__weak_alias(yp_setbindtries, _yp_setbindtries)
 #endif
 
 #ifdef _REENTRANT
@@ -84,6 +86,15 @@ static 	mutex_t			_ypmutex = MUTEX_INITI
 #endif
 
 int
+yp_setbindtries(int ntries) {
+	int old_val = _yplib_bindtries;
+
+	if (ntries >= 0)
+		_yplib_bindtries = ntries;
+	return old_val;
+}
+
+int
 _yp_dobind(dom, ypdb)
 	const char     *dom;
 	struct dom_binding **ypdb;
@@ -214,12 +225,18 @@ trynet:
 		    (xdrproc_t)xdr_ypdomain_wrap_string, &dom,
 		    (xdrproc_t)xdr_ypbind_resp, &ypbr, _yplib_timeout);
 		if (r != RPC_SUCCESS) {
-			if (new == 0 && ++nerrs == _yplib_nerrs) {
+			if (_yplib_bindtries <= 0 && new == 0 &&
+			    ++nerrs == _yplib_nerrs) {
 				nerrs = 0;
 				fprintf(stderr,
 		    "YP server for domain %s not responding, still trying\n",
 				    dom);
 			}
+			else if (_yplib_bindtries > 0 &&
+			         ++nerrs == _yplib_bindtries) {
+				free(ysd);
+				return YPERR_YPBIND;
+			}
 			clnt_destroy(client);
 			ysd->dom_vers = -1;
 			goto again;

Index: src/usr.bin/ypcat/ypcat.1
diff -u src/usr.bin/ypcat/ypcat.1:1.19 src/usr.bin/ypcat/ypcat.1:1.20
--- src/usr.bin/ypcat/ypcat.1:1.19	Wed Jan 12 14:55:06 2011
+++ src/usr.bin/ypcat/ypcat.1	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ypcat.1,v 1.19 2011/01/12 19:55:06 wiz Exp $
+.\"	$NetBSD: ypcat.1,v 1.20 2012/03/02 17:27:49 christos Exp $
 .\"
 .\" Copyright (c) 1993 Winning Strategies, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 12, 2011
+.Dd March 2, 2012
 .Dt YPCAT 1
 .Os
 .Sh NAME
@@ -37,6 +37,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl kst
+.Op Fl b Ar num_retry
 .Op Fl d Ar domainname
 .Ar mapname
 .Nm
@@ -51,6 +52,10 @@ which may be a map name or a map nicknam
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl b Ar num_retry
+Do not wait infinite time for ypserver to come up.
+Retry only the specified number times. See 
+.Xr yp_setbindtries 3 for explanation. Valid range is limited from 0 to 65535 by this program. 
 .It Fl d Ar domainname
 Specify a domain other than the default domain.
 .It Fl k
@@ -77,6 +82,7 @@ for details).
 .Xr domainname 1 ,
 .Xr ypmatch 1 ,
 .Xr ypwhich 1 ,
+.Xr yp_setbindtries 3 ,
 .Xr nicknames 5 ,
 .Xr nis 8 ,
 .Xr ypbind 8 ,

Index: src/usr.bin/ypcat/ypcat.c
diff -u src/usr.bin/ypcat/ypcat.c:1.16 src/usr.bin/ypcat/ypcat.c:1.17
--- src/usr.bin/ypcat/ypcat.c:1.16	Wed Jan 12 13:51:42 2011
+++ src/usr.bin/ypcat/ypcat.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: ypcat.c,v 1.16 2011/01/12 18:51:42 christos Exp $	*/
+/* $NetBSD: ypcat.c,v 1.17 2012/03/02 17:27:49 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ypcat.c,v 1.16 2011/01/12 18:51:42 christos Exp $");
+__RCSID("$NetBSD: ypcat.c,v 1.17 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -58,7 +58,7 @@ static int	compressspace;
 int
 main(int argc, char *argv[])
 {
-	char *domainname;
+	char *domainname, b_retry_cnt;
 	struct ypall_callback ypcb;
 	const char *inmap;
 	int notrans;
@@ -68,11 +68,15 @@ main(int argc, char *argv[])
 	int key;
 
 	setprogname(*argv);
-	domainname = NULL;
+	domainname = b_retry_cnt NULL;
 	notrans = key = 0;
 	ypaliases = ypalias_init();
-	while((c = getopt(argc, argv, "d:kstx")) != -1) {
+	while((c = getopt(argc, argv, "bd:kstx")) != -1) {
 		switch (c) {
+		case 'b':
+			b_retry_cnt = optarg;
+			break;
+
 		case 'd':
 			domainname = optarg;
 			break;
@@ -107,6 +111,15 @@ main(int argc, char *argv[])
 	if (argc != 1)
 		usage();
 
+	if (b_retry_cnt != NULL) {
+		char *s;
+		unsigned long l;
+
+		l = strtoul(b_retry_cnt, &s, 10);
+		if (*s != '\0' || l > 0xffff) usage();
+		yp_setbindtries((int)l);
+	}
+
 	if (domainname == NULL)
 		yp_get_default_domain(&domainname);
 
@@ -172,8 +185,8 @@ static void
 usage(void)
 {
 
-	(void)fprintf(stderr, "Usage: %s [-kst] [-d domainname] mapname\n",
-	    getprogname());
+	(void)fprintf(stderr, "Usage: %s [-kst] [-b <num-retry> "
+	    "[-d <domainname>] <mapname>\n", getprogname());
 	(void)fprintf(stderr, "       %s -x\n", getprogname());
 	exit(1);
 }

Index: src/usr.bin/ypmatch/ypmatch.1
diff -u src/usr.bin/ypmatch/ypmatch.1:1.16 src/usr.bin/ypmatch/ypmatch.1:1.17
--- src/usr.bin/ypmatch/ypmatch.1:1.16	Sun Jun 21 10:58:58 2009
+++ src/usr.bin/ypmatch/ypmatch.1	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ypmatch.1,v 1.16 2009/06/21 14:58:58 wiz Exp $
+.\"	$NetBSD: ypmatch.1,v 1.17 2012/03/02 17:27:49 christos Exp $
 .\"
 .\" Copyright (c) 1993 Winning Strategies, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd June 20, 2009
+.Dd March 2, 2012
 .Dt YPMATCH 1
 .Os
 .Sh NAME
@@ -37,6 +37,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl ktz
+.Op Fl b Ar num_retry
 .Op Fl d Ar domainname
 .Ar key ...
 .Ar mapname
@@ -52,6 +53,10 @@ which may be a map name or a map nicknam
 .Pp
 The options are as follows:
 .Bl -tag -width indent
+.It Fl b Ar num_retry
+Do not wait infinite time for ypserver to come up.
+Retry only the specified number times. See
+.Xr yp_setbindtries 3 for explanation. Valid range is limited from 0 to 65535 by this program.
 .It Fl d Ar domainname
 Specify a domain other than the default domain.
 .It Fl k
@@ -78,6 +83,7 @@ the keys.
 .Xr domainname 1 ,
 .Xr ypcat 1 ,
 .Xr ypwhich 1 ,
+.Xr yp_setbindtries 3 ,
 .Xr nicknames 5 ,
 .Xr nis 8 ,
 .Xr ypbind 8 ,

Index: src/usr.bin/ypmatch/ypmatch.c
diff -u src/usr.bin/ypmatch/ypmatch.c:1.19 src/usr.bin/ypmatch/ypmatch.c:1.20
--- src/usr.bin/ypmatch/ypmatch.c:1.19	Sun Jun 21 10:59:53 2009
+++ src/usr.bin/ypmatch/ypmatch.c	Fri Mar  2 12:27:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: ypmatch.c,v 1.19 2009/06/21 14:59:53 wiz Exp $	*/
+/*	$NetBSD: ypmatch.c,v 1.20 2012/03/02 17:27:49 christos Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993 Theo de Raadt <dera...@fsa.ca>
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ypmatch.c,v 1.19 2009/06/21 14:59:53 wiz Exp $");
+__RCSID("$NetBSD: ypmatch.c,v 1.20 2012/03/02 17:27:49 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -53,7 +53,7 @@ static void	usage(void) __attribute__((_
 int
 main(int argc, char *argv[])
 {
-	char *domainname;
+	char *domainname, *b_retry_cnt;
 	char *inkey, *outbuf;
 	const char *inmap;
 	int outbuflen, key, null, notrans;
@@ -63,10 +63,10 @@ main(int argc, char *argv[])
 	const struct ypalias *ypaliases;
 
 	setprogname(*argv);
-	domainname = NULL;
+	domainname = b_retry_cnt = NULL;
 	notrans = key = null = 0;
 	ypaliases = ypalias_init();
-	while ((c = getopt(argc, argv, "xd:ktz")) != -1) {
+	while ((c = getopt(argc, argv, "bd:ktxz")) != -1) {
 		switch (c) {
 		case 'x':
 			for(i = 0; ypaliases[i].alias; i++)
@@ -75,6 +75,10 @@ main(int argc, char *argv[])
 					ypaliases[i].name);
 			return 0;
 
+		case 'b':
+			b_retry_cnt = optarg;
+			break;
+
 		case 'd':
 			domainname = optarg;
 			break;
@@ -102,6 +106,15 @@ main(int argc, char *argv[])
 	if (argc < 2)
 		usage();
 
+	if (b_retry_cnt != NULL) {
+		char *s;
+		unsigned long l;
+
+		l = strtoul(b_retry_cnt, &s, 10);
+		if (*s != '\0' || l > 0xffff) usage();
+		yp_setbindtries((int)l);
+	}
+
 	if (domainname == NULL)
 		yp_get_default_domain(&domainname);
 
@@ -147,8 +160,8 @@ static void
 usage(void)
 {
 
-	(void)fprintf(stderr, "Usage: %s [-ktz] [-d domain] key ... "
-	    "mapname\n", getprogname());
+	(void)fprintf(stderr, "Usage: %s [-ktz] [-b <num-retry>] "
+	    "[-d <domainname>] "<key> ... <mapname>\n", getprogname());
 	(void)fprintf(stderr, "       %s -x\n", getprogname());
 	exit(1);
 }

Reply via email to