Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/rpc - add __clnt_sigfillset() that does not blindly...



details:   https://anonhg.NetBSD.org/src/rev/8f8c455a8a2f
branches:  trunk
changeset: 786719:8f8c455a8a2f
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 07 21:08:44 2013 +0000

description:
- 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.

diffstat:

 lib/libc/rpc/clnt_dg.c      |  27 +++++++++++++--------------
 lib/libc/rpc/clnt_generic.c |  21 +++++++++++++++++++--
 lib/libc/rpc/clnt_vc.c      |  35 +++++++++++++++--------------------
 lib/libc/rpc/rpc_internal.h |   4 +++-
 4 files changed, 50 insertions(+), 37 deletions(-)

diffs (281 lines):

diff -r b48eb490d2e9 -r 8f8c455a8a2f lib/libc/rpc/clnt_dg.c
--- a/lib/libc/rpc/clnt_dg.c    Tue May 07 20:42:45 2013 +0000
+++ b/lib/libc/rpc/clnt_dg.c    Tue May 07 21:08:44 2013 +0000
@@ -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 @@
        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 @@
                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 @@
                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 @@
        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 @@
 
        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 @@
        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 @@
 
        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 @@
        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 @@
 
 /* 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) {
diff -r b48eb490d2e9 -r 8f8c455a8a2f lib/libc/rpc/clnt_generic.c
--- a/lib/libc/rpc/clnt_generic.c       Tue May 07 20:42:45 2013 +0000
+++ b/lib/libc/rpc/clnt_generic.c       Tue May 07 21:08:44 2013 +0000
@@ -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 @@
                (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;
+}
diff -r b48eb490d2e9 -r 8f8c455a8a2f lib/libc/rpc/clnt_vc.c
--- a/lib/libc/rpc/clnt_vc.c    Tue May 07 20:42:45 2013 +0000
+++ b/lib/libc/rpc/clnt_vc.c    Tue May 07 21:08:44 2013 +0000
@@ -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  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 @@
                goto fooy;
        }
 
-       sigfillset(&newmask);
+       __clnt_sigfillset(&newmask);
        thr_sigsetmask(SIG_SETMASK, &newmask, &mask);
 #ifdef _REENTRANT
        mutex_lock(&clnt_fd_lock);
@@ -205,9 +205,7 @@
                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 @@
                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 @@
                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 @@
            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 @@
        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 @@
        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 @@
 
        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 @@
        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 @@
 
        /* 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) {
diff -r b48eb490d2e9 -r 8f8c455a8a2f lib/libc/rpc/rpc_internal.h
--- a/lib/libc/rpc/rpc_internal.h       Tue May 07 20:42:45 2013 +0000
+++ b/lib/libc/rpc/rpc_internal.h       Tue May 07 21:08:44 2013 +0000
@@ -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 @@
 
 extern SVCXPRT **__svc_xports;
 extern int __svc_maxrec;
+
+int __clnt_sigfillset(sigset_t *);



Home | Main Index | Thread Index | Old Index