Author: ed
Date: Sun May 24 12:32:03 2009
New Revision: 192682
URL: http://svn.freebsd.org/changeset/base/192682

Log:
  Block when initially opening a TTY multiple times.
  
  In the original MPSAFE TTY code, I changed the behaviour by returning
  EBUSY. I thought this made more sense, because it's basically a race to
  see who gets the TTY first.
  
  It turns out this is not a good change, because it also causes EBUSY to
  be returned when another process is closing the TTY. This can happen
  during startup, when /etc/rc (or one of its children) is still busy
  draining its data and /sbin/init is attempting to open the TTY to spawn
  a getty.
  
  Reported by:  bz
  Tested by:    bz

Modified:
  head/sys/kern/tty.c

Modified: head/sys/kern/tty.c
==============================================================================
--- head/sys/kern/tty.c Sun May 24 12:28:38 2009        (r192681)
+++ head/sys/kern/tty.c Sun May 24 12:32:03 2009        (r192682)
@@ -206,6 +206,7 @@ ttydev_leave(struct tty *tp)
                ttydevsw_close(tp);
 
        tp->t_flags &= ~TF_OPENCLOSE;
+       cv_broadcast(&tp->t_dcdwait);
        tty_rel_free(tp);
 }
 
@@ -231,13 +232,17 @@ ttydev_open(struct cdev *dev, int oflags
                tty_unlock(tp);
                return (ENXIO);
        }
+
        /*
-        * Prevent the TTY from being opened when being torn down or
-        * built up by unrelated processes.
+        * Block when other processes are currently opening or closing
+        * the TTY.
         */
-       if (tp->t_flags & TF_OPENCLOSE) {
-               tty_unlock(tp);
-               return (EBUSY);
+       while (tp->t_flags & TF_OPENCLOSE) {
+               error = tty_wait(tp, &tp->t_dcdwait);
+               if (error != 0) {
+                       tty_unlock(tp);
+                       return (error);
+               }
        }
        tp->t_flags |= TF_OPENCLOSE;
 
@@ -299,6 +304,7 @@ ttydev_open(struct cdev *dev, int oflags
                tp->t_flags |= TF_OPENED_IN;
 
 done:  tp->t_flags &= ~TF_OPENCLOSE;
+       cv_broadcast(&tp->t_dcdwait);
        ttydev_leave(tp);
 
        return (error);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to