Module Name:    src
Committed By:   christos
Date:           Tue May  7 21:08:45 UTC 2013

Modified Files:
        src/lib/libc/rpc: clnt_dg.c clnt_generic.c clnt_vc.c rpc_internal.h

Log Message:
- add __clnt_sigfillset() that does not blindly block all signals but excludes
  the tty generated ones (int, quit, tstp), plus term and hup. This makes
  command line clients behave on connect(2) where before they would need
  to be killed from a different tty. Much easier than making the file
  descriptor non-blocking for the duration of connect and then using
  pselect/pollts to detect when actual connection or timeout occured using
  a different sigmask.
- factor out some of the error paths.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/rpc/clnt_dg.c
cvs rdiff -u -r1.30 -r1.31 src/lib/libc/rpc/clnt_generic.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libc/rpc/clnt_vc.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libc/rpc/rpc_internal.h

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

Modified files:

Index: src/lib/libc/rpc/clnt_dg.c
diff -u src/lib/libc/rpc/clnt_dg.c:1.28 src/lib/libc/rpc/clnt_dg.c:1.29
--- src/lib/libc/rpc/clnt_dg.c:1.28	Mon Mar 11 16:19:28 2013
+++ src/lib/libc/rpc/clnt_dg.c	Tue May  7 17:08:44 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: clnt_dg.c,v 1.28 2013/03/11 20:19:28 tron Exp $	*/
+/*	$NetBSD: clnt_dg.c,v 1.29 2013/05/07 21:08:44 christos Exp $	*/
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)clnt_dg.c 1.19 89/03/16 Copyr 1988 Sun Micro";
 #else
-__RCSID("$NetBSD: clnt_dg.c,v 1.28 2013/03/11 20:19:28 tron Exp $");
+__RCSID("$NetBSD: clnt_dg.c,v 1.29 2013/05/07 21:08:44 christos Exp $");
 #endif
 #endif
 
@@ -175,7 +175,7 @@ clnt_dg_create(
 	struct __rpc_sockinfo si;
 	int one = 1;
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 	if (dg_fd_locks == NULL) {
@@ -188,9 +188,7 @@ clnt_dg_create(
 		fd_allocsz = dtbsize * sizeof (int);
 		dg_fd_locks = mem_alloc(fd_allocsz);
 		if (dg_fd_locks == NULL) {
-			mutex_unlock(&clnt_fd_lock);
-			thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
-			goto err1;
+			goto err0;
 		} else
 			memset(dg_fd_locks, '\0', fd_allocsz);
 
@@ -200,9 +198,7 @@ clnt_dg_create(
 		if (dg_cv == NULL) {
 			mem_free(dg_fd_locks, fd_allocsz);
 			dg_fd_locks = NULL;
-			mutex_unlock(&clnt_fd_lock);
-			thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
-			goto err1;
+			goto err0;
 		} else {
 			int i;
 
@@ -294,6 +290,9 @@ clnt_dg_create(
 	cl->cl_tp = NULL;
 	cl->cl_netid = NULL;
 	return (cl);
+err0:
+	mutex_unlock(&clnt_fd_lock);
+	thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
 err1:
 	warnx(mem_err_clnt_dg);
 	rpc_createerr.cf_stat = RPC_SYSTEMERROR;
@@ -341,7 +340,7 @@ clnt_dg_call(
 
 	cu = (struct cu_data *)cl->cl_private;
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 	while (dg_fd_locks[cu->cu_fd])
@@ -532,7 +531,7 @@ clnt_dg_freeres(CLIENT *cl, xdrproc_t xd
 	cu = (struct cu_data *)cl->cl_private;
 	xdrs = &(cu->cu_outxdrs);
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 	while (dg_fd_locks[cu->cu_fd])
@@ -566,7 +565,7 @@ clnt_dg_control(CLIENT *cl, u_int reques
 
 	cu = (struct cu_data *)cl->cl_private;
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 	while (dg_fd_locks[cu->cu_fd])
@@ -706,7 +705,7 @@ clnt_dg_destroy(CLIENT *cl)
 	cu = (struct cu_data *)cl->cl_private;
 	cu_fd = cu->cu_fd;
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 	while (dg_fd_locks[cu_fd])
@@ -737,7 +736,7 @@ clnt_dg_ops(void)
 
 /* VARIABLES PROTECTED BY ops_lock: ops */
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&ops_lock);
 	if (ops.cl_call == NULL) {

Index: src/lib/libc/rpc/clnt_generic.c
diff -u src/lib/libc/rpc/clnt_generic.c:1.30 src/lib/libc/rpc/clnt_generic.c:1.31
--- src/lib/libc/rpc/clnt_generic.c:1.30	Mon Mar 11 16:19:28 2013
+++ src/lib/libc/rpc/clnt_generic.c	Tue May  7 17:08:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: clnt_generic.c,v 1.30 2013/03/11 20:19:28 tron Exp $	*/
+/*	$NetBSD: clnt_generic.c,v 1.31 2013/05/07 21:08:45 christos Exp $	*/
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)clnt_generic.c 1.32 89/03/16 Copyr 1988 Sun Micro";
 #else
-__RCSID("$NetBSD: clnt_generic.c,v 1.30 2013/03/11 20:19:28 tron Exp $");
+__RCSID("$NetBSD: clnt_generic.c,v 1.31 2013/05/07 21:08:45 christos Exp $");
 #endif
 #endif
 
@@ -381,3 +381,20 @@ err1:	if (madefd)
 		(void) close(fd);
 	return (NULL);
 }
+
+/*
+ * Don't block thse so interactive programs don't get stuck in lalaland.
+ * (easier to do this than making connect(2) non-blocking..)
+ */
+int
+__clnt_sigfillset(sigset_t *ss) {
+	static const int usersig[] = {
+	    SIGHUP, SIGINT, SIGQUIT, SIGTERM, SIGTSTP
+	};
+	if (sigfillset(ss) == -1)
+		return -1;
+	for (size_t i = 0; i < __arraycount(usersig); i++)
+		if (sigdelset(ss, usersig[i]) == -1)
+			return -1;
+	return 0;
+}

Index: src/lib/libc/rpc/clnt_vc.c
diff -u src/lib/libc/rpc/clnt_vc.c:1.22 src/lib/libc/rpc/clnt_vc.c:1.23
--- src/lib/libc/rpc/clnt_vc.c:1.22	Wed Apr 17 12:36:47 2013
+++ src/lib/libc/rpc/clnt_vc.c	Tue May  7 17:08:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: clnt_vc.c,v 1.22 2013/04/17 16:36:47 christos Exp $	*/
+/*	$NetBSD: clnt_vc.c,v 1.23 2013/05/07 21:08:45 christos Exp $	*/
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -38,7 +38,7 @@ static char *sccsid = "@(#)clnt_tcp.c 1.
 static char *sccsid = "@(#)clnt_tcp.c	2.2 88/08/01 4.0 RPCSRC";
 static char sccsid[] = "@(#)clnt_vc.c 1.19 89/03/16 Copyr 1988 Sun Micro";
 #else
-__RCSID("$NetBSD: clnt_vc.c,v 1.22 2013/04/17 16:36:47 christos Exp $");
+__RCSID("$NetBSD: clnt_vc.c,v 1.23 2013/05/07 21:08:45 christos Exp $");
 #endif
 #endif
  
@@ -194,7 +194,7 @@ clnt_vc_create(
 		goto fooy;
 	}
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 #ifdef _REENTRANT
 	mutex_lock(&clnt_fd_lock);
@@ -205,9 +205,7 @@ clnt_vc_create(
 		fd_allocsz = dtbsize * sizeof (int);
 		vc_fd_locks = mem_alloc(fd_allocsz);
 		if (vc_fd_locks == NULL) {
-			mutex_unlock(&clnt_fd_lock);
-			thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
-			goto fooy;
+			goto blooy;
 		} else
 			memset(vc_fd_locks, '\0', fd_allocsz);
 
@@ -217,9 +215,7 @@ clnt_vc_create(
 		if (vc_cv == NULL) {
 			mem_free(vc_fd_locks, fd_allocsz);
 			vc_fd_locks = NULL;
-			mutex_unlock(&clnt_fd_lock);
-			thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
-			goto fooy;
+			goto blooy;
 		} else {
 			int i;
 
@@ -238,16 +234,12 @@ clnt_vc_create(
 		if (errno != ENOTCONN) {
 			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
 			rpc_createerr.cf_error.re_errno = errno;
-			mutex_unlock(&clnt_fd_lock);
-			thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
-			goto fooy;
+			goto blooy;
 		}
 		if (connect(fd, (struct sockaddr *)raddr->buf, raddr->len) < 0){
 			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
 			rpc_createerr.cf_error.re_errno = errno;
-			mutex_unlock(&clnt_fd_lock);
-			thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
-			goto fooy;
+			goto blooy;
 		}
 	}
 	mutex_unlock(&clnt_fd_lock);
@@ -306,6 +298,9 @@ clnt_vc_create(
 	    h->cl_private, read_vc, write_vc);
 	return (h);
 
+blooy:
+	mutex_unlock(&clnt_fd_lock);
+	thr_sigsetmask(SIG_SETMASK, &(mask), NULL);
 fooy:
 	/*
 	 * Something goofed, free stuff and barf
@@ -344,7 +339,7 @@ clnt_vc_call(
 	ct = (struct ct_data *) h->cl_private;
 
 #ifdef _REENTRANT
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 	while (vc_fd_locks[ct->ct_fd])
@@ -483,7 +478,7 @@ clnt_vc_freeres(
 	ct = (struct ct_data *)cl->cl_private;
 	xdrs = &(ct->ct_xdrs);
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 #ifdef _REENTRANT
@@ -524,7 +519,7 @@ clnt_vc_control(
 
 	ct = (struct ct_data *)cl->cl_private;
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 #ifdef _REENTRANT
@@ -652,7 +647,7 @@ clnt_vc_destroy(CLIENT *cl)
 	ct = (struct ct_data *) cl->cl_private;
 	ct_fd = ct->ct_fd;
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&clnt_fd_lock);
 #ifdef _REENTRANT
@@ -753,7 +748,7 @@ clnt_vc_ops(void)
 
 	/* VARIABLES PROTECTED BY ops_lock: ops */
 
-	sigfillset(&newmask);
+	__clnt_sigfillset(&newmask);
 	thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 	mutex_lock(&ops_lock);
 	if (ops.cl_call == NULL) {

Index: src/lib/libc/rpc/rpc_internal.h
diff -u src/lib/libc/rpc/rpc_internal.h:1.6 src/lib/libc/rpc/rpc_internal.h:1.7
--- src/lib/libc/rpc/rpc_internal.h:1.6	Sat Apr  4 11:31:08 2009
+++ src/lib/libc/rpc/rpc_internal.h	Tue May  7 17:08:45 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpc_internal.h,v 1.6 2009/04/04 15:31:08 christos Exp $	*/
+/*	$NetBSD: rpc_internal.h,v 1.7 2013/05/07 21:08:45 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -63,3 +63,5 @@ u_int32_t __rpc_getxid(void);
 
 extern SVCXPRT **__svc_xports;
 extern int __svc_maxrec;
+
+int __clnt_sigfillset(sigset_t *);

Reply via email to