From 33e55d9f63f0ba84b892e145f226c16b8f1733e7 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 31 May 2001 04:55:36 +0000 Subject: 2001-05-30 Roland McGrath * users.c (trivfs_S_io_select): Mask out SELECT_READ and/or SELECT_WRITE if those accesses are not allowed by the peropen. Don't keep old bits in AVAILABLE across waits, return only what is true at the moment we return. --- term/users.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'term/users.c') diff --git a/term/users.c b/term/users.c index 9d103013..a987454d 100644 --- a/term/users.c +++ b/term/users.c @@ -2000,44 +2000,37 @@ trivfs_S_io_select (struct trivfs_protid *cred, int *type, int *idtag) { - int available; - if (!cred) return EOPNOTSUPP; if (cred->pi.class == pty_class) return pty_io_select (cred, reply, type, idtag); - /* We don't deal with SELECT_URG here. */ - *type &= (SELECT_READ | SELECT_WRITE); - - available = 0; - if (*type == 0) - return 0; + if ((cred->po->openmodes & O_READ) == 0) + *type &= ~SELECT_READ; + if ((cred->po->openmodes & O_WRITE) == 0) + *type &= ~SELECT_WRITE; mutex_lock (&global_lock); while (1) { + int available = 0; if ((*type & SELECT_READ) && qsize (inputq)) available |= SELECT_READ; if ((*type & SELECT_WRITE) && qavail (outputq)) available |= SELECT_WRITE; - if (available) + if (available == 0) { - *type = available; - mutex_unlock (&global_lock); - return 0; + ports_interrupt_self_on_port_death (cred, reply); + if (hurd_condition_wait (&select_alert, &global_lock) == 0) + continue; } - ports_interrupt_self_on_port_death (cred, reply); - if (hurd_condition_wait (&select_alert, &global_lock)) - { - *type = 0; - mutex_unlock (&global_lock); - return EINTR; - } + *type = available; + mutex_unlock (&global_lock); + return available ? 0 EINTR; } } -- cgit v1.2.3