working select()
authorBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 12 Sep 1982 04:12:25 +0000 (20:12 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Sun, 12 Sep 1982 04:12:25 +0000 (20:12 -0800)
SCCS-vsn: sys/kern/kern_descrip.c 5.10

usr/src/sys/kern/kern_descrip.c

index 9af2b7c..6b03fe0 100644 (file)
@@ -1,4 +1,4 @@
-/*     kern_descrip.c  5.9     82/09/08        */
+/*     kern_descrip.c  5.10    82/09/11        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -171,8 +171,10 @@ int        nselcoll;
 select()
 {
        register struct uap  {
 select()
 {
        register struct uap  {
-               long    *ibits;
-               long    *obits;
+               int     nd;
+               long    *in;
+               long    *ou;
+               long    *ex;
                struct  timeval *tv;
        } *uap = (struct uap *)u.u_ap;
        int ibits[3], obits[3];
                struct  timeval *tv;
        } *uap = (struct uap *)u.u_ap;
        int ibits[3], obits[3];
@@ -180,6 +182,25 @@ select()
        int s, tsel, ncoll, rem;
        label_t lqsave;
 
        int s, tsel, ncoll, rem;
        label_t lqsave;
 
+       if (uap->nd >= NOFILE) {
+               u.u_error = EINVAL;
+               return;
+       }
+
+#define        getbits(name, x) \
+       if (uap->name) { \
+               if (copyin((caddr_t)uap->name, (caddr_t)&ibits[x], \
+                   sizeof (ibits[x]))) { \
+                       u.u_error = EFAULT; \
+                       return; \
+               } \
+       } else \
+               ibits[x] = 0;
+       getbits(in, 0);
+       getbits(ou, 1);
+       getbits(ex, 2);
+#undef getbits
+
        if (uap->tv) {
                if (copyin((caddr_t)uap->tv, (caddr_t)&atv, sizeof (atv))) {
                        u.u_error = EFAULT;
        if (uap->tv) {
                if (copyin((caddr_t)uap->tv, (caddr_t)&atv, sizeof (atv))) {
                        u.u_error = EFAULT;
@@ -191,10 +212,6 @@ select()
                }
                s = spl7(); timevaladd(&atv, &time); splx(s);
        }
                }
                s = spl7(); timevaladd(&atv, &time); splx(s);
        }
-       if (copyin((caddr_t)uap->ibits, (caddr_t)ibits, sizeof (ibits))) {
-               u.u_error = EFAULT;
-               return;
-       }
 retry:
        ncoll = nselcoll;
        u.u_procp->p_flag |= SSEL;
 retry:
        ncoll = nselcoll;
        u.u_procp->p_flag |= SSEL;
@@ -204,7 +221,7 @@ retry:
        if (u.u_r.r_val1)
                goto done;
        s = spl6();
        if (u.u_r.r_val1)
                goto done;
        s = spl6();
-       if (uap->tv && timercmp(&atv, &time, >=)) {
+       if (uap->tv && timercmp(&time, &atv, >=)) {
                splx(s);
                goto done;
        }
                splx(s);
                goto done;
        }
@@ -232,10 +249,18 @@ retry:
        splx(s);
        goto retry;
 done:
        splx(s);
        goto retry;
 done:
-       if (copyout((caddr_t)obits, (caddr_t)uap->obits, sizeof (obits))) {
-               u.u_error = EFAULT;
-               return;
+#define        putbits(name, x) \
+       if (uap->name) { \
+               if (copyout((caddr_t)obits[x], (caddr_t)uap->name, \
+                   sizeof (obits[x]))) { \
+                       u.u_error = EFAULT; \
+                       return; \
+               } \
        }
        }
+       putbits(in, 0);
+       putbits(ou, 1);
+       putbits(ex, 2);
+#undef putbits
 }
 
 unselect(p)
 }
 
 unselect(p)