Date: Sun, 24 May 2009 12:32:04 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r192682 - head/sys/kern Message-ID: <200905241232.n4OCW4Za089741@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905241232.n4OCW4Za089741>