From owner-svn-src-head@FreeBSD.ORG Sun May 24 12:32:04 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 371A4106564A; Sun, 24 May 2009 12:32:04 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 25EC58FC08; Sun, 24 May 2009 12:32:04 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n4OCW4qt089742; Sun, 24 May 2009 12:32:04 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n4OCW4Za089741; Sun, 24 May 2009 12:32:04 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200905241232.n4OCW4Za089741@svn.freebsd.org> From: Ed Schouten Date: Sun, 24 May 2009 12:32:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r192682 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 May 2009 12:32:04 -0000 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);