Currently one can open multiple instances of /dev/ttyU* since ucom(4)
just checks 'TS_ISOPEN' against /dev/cuaU* access.  There are quiet a
lot of flags in ucom.c so it's a bit difficult to understand what the
initial idea was.  But moving the 'TS_ISOPEN' check before the UCOMCUA
branch makes /dev/ttyU* access also return EBUSY if already opened.

Ok?  Or better ideas to fix this?


Index: ucom.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ucom.c,v
retrieving revision 1.65
diff -u -p -u -p -r1.65 ucom.c
--- ucom.c      14 Mar 2015 03:38:49 -0000      1.65
+++ ucom.c      11 Jun 2016 12:08:20 -0000
@@ -474,12 +474,13 @@ ucom_do_open(dev_t dev, int flag, int mo
        else
                s = spltty();
 
+       if (ISSET(tp->t_state, TS_ISOPEN)) {
+               /* Someone is already dialed in */
+               splx(s);
+               return (EBUSY);
+       }
+
        if (UCOMCUA(dev)) {
-               if (ISSET(tp->t_state, TS_ISOPEN)) {
-                       /* Someone is already dialed in */
-                       splx(s);
-                       return (EBUSY);
-               }
                sc->sc_cua = 1;
        } else {
                /* tty (not cua) device, wait for carrier */

Reply via email to