From 94f8d3fceed31e6b6f99b50c6c120811f2746f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 2 Apr 2006 12:52:33 +0000 Subject: [PATCH] A TTY now refuses read/write requests while the other end is dead; it also notified the other end when it has been closed. This fixes bug #388. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16965 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/drivers/tty/tty.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/drivers/tty/tty.cpp b/src/add-ons/kernel/drivers/tty/tty.cpp index 09eac2339c..42b8fea1ee 100644 --- a/src/add-ons/kernel/drivers/tty/tty.cpp +++ b/src/add-ons/kernel/drivers/tty/tty.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2004-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -136,7 +136,7 @@ public: { MutexLocker _(gTTYCookieLock); - if (cookie->closed) + if (cookie->closed || cookie->other_tty->open_count == 0) return false; cookie->thread_count++; @@ -915,11 +915,16 @@ tty_close_cookie(struct tty_cookie *cookie) // We do this by first notifying all queued requests of the error // condition. We then clear the line buffer for the TTY and queue // an own request. + + // Notify the other TTY first; it doesn't accept any read/writes + // while there is only one end. + cookie->other_tty->reader_queue.NotifyError(B_FILE_ERROR); + cookie->other_tty->writer_queue.NotifyError(B_FILE_ERROR); + RecursiveLocker requestLocker(gTTYRequestLock); // we only need to do all this, if the writer queue is not empty if (!cookie->tty->writer_queue.IsEmpty()) { - // notify the blocking writers cookie->tty->writer_queue.NotifyError(B_FILE_ERROR);