From 0b15555da3548298aae356278229a76671382417 Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 11 Apr 1995 05:19:34 +0000 Subject: [PATCH] Fix bug in OS2_receive_message. It's possible to arrive here with a closed qid due to race conditions when the sending thread closes the qid while the reading thread is about to read from it. This was happening under some circumstances when sending mail: the sendmail program doesn't generate any output, and if it terminates before the input thread's first read, the qid will be closed. --- v7/src/microcode/os2msg.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/v7/src/microcode/os2msg.c b/v7/src/microcode/os2msg.c index a1e809d95..6cf4b4306 100644 --- a/v7/src/microcode/os2msg.c +++ b/v7/src/microcode/os2msg.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2msg.c,v 1.5 1995/02/07 23:54:09 cph Exp $ +$Id: os2msg.c,v 1.6 1995/04/11 05:19:34 cph Exp $ Copyright (c) 1994-95 Massachusetts Institute of Technology @@ -324,6 +324,19 @@ OS2_receive_message (qid_t qid, int blockp, int interruptp) { tqueue_t * tqueue = (QID_TQUEUE (qid)); msg_t * message; + if (tqueue == 0) + { + if ((OS2_current_tid ()) != OS2_scheme_tid) + /* This behavior is a little random, but it's based on the + idea that if an inferior thread is reading from a closed + channel, this is due to a race condition, and the fact that + the channel is closed means that the thread is no longer + needed. So far this has only happened under one + circumstance, and in that case, this is the correct action. */ + OS2_endthread (); + else + OS2_error_anonymous (); + } while (1) { while ((read_tqueue (tqueue, 0)) != 0) @@ -346,6 +359,8 @@ msg_avail_t OS2_message_availablep (qid_t qid, int blockp) { tqueue_t * tqueue = (QID_TQUEUE (qid)); + if (tqueue == 0) + return (mat_not_available); while (1) { while ((read_tqueue (tqueue, 0)) != 0) @@ -379,7 +394,7 @@ msg_t * OS2_message_transaction (qid_t qid, msg_t * request, msg_type_t reply_type) { OS2_send_message (qid, request); - OS2_wait_for_message (qid, reply_type); + return (OS2_wait_for_message (qid, reply_type)); } static void -- 2.25.1