]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] Fix a race condition in pty.c
authorZou Nanhai <nanhai.zou@intel.com>
Sat, 18 Dec 2004 09:17:31 +0000 (01:17 -0800)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sat, 18 Dec 2004 09:17:31 +0000 (01:17 -0800)
There is a race condition int pty.c when pty_close wakes up waiter on its
pair device before set TTY_OTHER_CLOSED flag.

It is possible on SMP or preempt kernel, waiter wakes up too early that it
will not get TTY_OTHER_CLOSED flag then fall into sleep again - missed wakeup.

hjl reports that this bug will hang some expect scripts on SMP machines.

Signed-off-by: Zou Nan hai <Nanhai.zou@intel.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/char/pty.c

index 92a13643812c5b612228829e644fc86e0b433209..a47386427eb2c152cc3a8c73c59f5cc2850a841b 100644 (file)
@@ -55,9 +55,9 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
        if (!tty->link)
                return;
        tty->link->packet = 0;
+       set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
        wake_up_interruptible(&tty->link->read_wait);
        wake_up_interruptible(&tty->link->write_wait);
-       set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
        if (tty->driver->subtype == PTY_TYPE_MASTER) {
                set_bit(TTY_OTHER_CLOSED, &tty->flags);
 #ifdef CONFIG_UNIX98_PTYS