summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libc_r/uthread/uthread_select.c27
-rw-r--r--lib/libkse/thread/thr_select.c27
-rw-r--r--lib/libpthread/thread/thr_select.c27
3 files changed, 54 insertions, 27 deletions
diff --git a/lib/libc_r/uthread/uthread_select.c b/lib/libc_r/uthread/uthread_select.c
index 5860efe..8d03bbd 100644
--- a/lib/libc_r/uthread/uthread_select.c
+++ b/lib/libc_r/uthread/uthread_select.c
@@ -52,7 +52,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
struct pthread *curthread = _get_curthread();
struct timespec ts;
int i, ret = 0, f_wait = 1;
- int pfd_index, got_one = 0, fd_count = 0;
+ int pfd_index, got_events = 0, fd_count = 0;
struct pthread_poll_data data;
if (numfds > _thread_dtablesize) {
@@ -166,12 +166,22 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
* this file descriptor from the fdset if
* the requested event wasn't ready.
*/
- got_one = 0;
+
+ /*
+ * First check for invalid descriptor.
+ * If found, set errno and return -1.
+ */
+ if (data.fds[i].revents & POLLNVAL) {
+ errno = EBADF;
+ return -1;
+ }
+
+ got_events = 0;
if (readfds != NULL) {
if (FD_ISSET(data.fds[i].fd, readfds)) {
if (data.fds[i].revents & (POLLIN |
POLLRDNORM))
- got_one = 1;
+ got_events++;
else
FD_CLR(data.fds[i].fd, readfds);
}
@@ -180,7 +190,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
if (FD_ISSET(data.fds[i].fd, writefds)) {
if (data.fds[i].revents & (POLLOUT |
POLLWRNORM | POLLWRBAND))
- got_one = 1;
+ got_events++;
else
FD_CLR(data.fds[i].fd,
writefds);
@@ -189,16 +199,15 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
if (exceptfds != NULL) {
if (FD_ISSET(data.fds[i].fd, exceptfds)) {
if (data.fds[i].revents & (POLLRDBAND |
- POLLPRI | POLLHUP | POLLERR |
- POLLNVAL))
- got_one = 1;
+ POLLPRI))
+ got_events++;
else
FD_CLR(data.fds[i].fd,
exceptfds);
}
}
- if (got_one)
- numfds++;
+ if (got_events != 0)
+ numfds+=got_events;
}
ret = numfds;
}
diff --git a/lib/libkse/thread/thr_select.c b/lib/libkse/thread/thr_select.c
index 5860efe..8d03bbd 100644
--- a/lib/libkse/thread/thr_select.c
+++ b/lib/libkse/thread/thr_select.c
@@ -52,7 +52,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
struct pthread *curthread = _get_curthread();
struct timespec ts;
int i, ret = 0, f_wait = 1;
- int pfd_index, got_one = 0, fd_count = 0;
+ int pfd_index, got_events = 0, fd_count = 0;
struct pthread_poll_data data;
if (numfds > _thread_dtablesize) {
@@ -166,12 +166,22 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
* this file descriptor from the fdset if
* the requested event wasn't ready.
*/
- got_one = 0;
+
+ /*
+ * First check for invalid descriptor.
+ * If found, set errno and return -1.
+ */
+ if (data.fds[i].revents & POLLNVAL) {
+ errno = EBADF;
+ return -1;
+ }
+
+ got_events = 0;
if (readfds != NULL) {
if (FD_ISSET(data.fds[i].fd, readfds)) {
if (data.fds[i].revents & (POLLIN |
POLLRDNORM))
- got_one = 1;
+ got_events++;
else
FD_CLR(data.fds[i].fd, readfds);
}
@@ -180,7 +190,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
if (FD_ISSET(data.fds[i].fd, writefds)) {
if (data.fds[i].revents & (POLLOUT |
POLLWRNORM | POLLWRBAND))
- got_one = 1;
+ got_events++;
else
FD_CLR(data.fds[i].fd,
writefds);
@@ -189,16 +199,15 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
if (exceptfds != NULL) {
if (FD_ISSET(data.fds[i].fd, exceptfds)) {
if (data.fds[i].revents & (POLLRDBAND |
- POLLPRI | POLLHUP | POLLERR |
- POLLNVAL))
- got_one = 1;
+ POLLPRI))
+ got_events++;
else
FD_CLR(data.fds[i].fd,
exceptfds);
}
}
- if (got_one)
- numfds++;
+ if (got_events != 0)
+ numfds+=got_events;
}
ret = numfds;
}
diff --git a/lib/libpthread/thread/thr_select.c b/lib/libpthread/thread/thr_select.c
index 5860efe..8d03bbd 100644
--- a/lib/libpthread/thread/thr_select.c
+++ b/lib/libpthread/thread/thr_select.c
@@ -52,7 +52,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
struct pthread *curthread = _get_curthread();
struct timespec ts;
int i, ret = 0, f_wait = 1;
- int pfd_index, got_one = 0, fd_count = 0;
+ int pfd_index, got_events = 0, fd_count = 0;
struct pthread_poll_data data;
if (numfds > _thread_dtablesize) {
@@ -166,12 +166,22 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
* this file descriptor from the fdset if
* the requested event wasn't ready.
*/
- got_one = 0;
+
+ /*
+ * First check for invalid descriptor.
+ * If found, set errno and return -1.
+ */
+ if (data.fds[i].revents & POLLNVAL) {
+ errno = EBADF;
+ return -1;
+ }
+
+ got_events = 0;
if (readfds != NULL) {
if (FD_ISSET(data.fds[i].fd, readfds)) {
if (data.fds[i].revents & (POLLIN |
POLLRDNORM))
- got_one = 1;
+ got_events++;
else
FD_CLR(data.fds[i].fd, readfds);
}
@@ -180,7 +190,7 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
if (FD_ISSET(data.fds[i].fd, writefds)) {
if (data.fds[i].revents & (POLLOUT |
POLLWRNORM | POLLWRBAND))
- got_one = 1;
+ got_events++;
else
FD_CLR(data.fds[i].fd,
writefds);
@@ -189,16 +199,15 @@ _select(int numfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds,
if (exceptfds != NULL) {
if (FD_ISSET(data.fds[i].fd, exceptfds)) {
if (data.fds[i].revents & (POLLRDBAND |
- POLLPRI | POLLHUP | POLLERR |
- POLLNVAL))
- got_one = 1;
+ POLLPRI))
+ got_events++;
else
FD_CLR(data.fds[i].fd,
exceptfds);
}
}
- if (got_one)
- numfds++;
+ if (got_events != 0)
+ numfds+=got_events;
}
ret = numfds;
}
OpenPOWER on IntegriCloud