diff options
author | David Timber <mieabby@gmail.com> | 2020-09-08 19:46:44 +0930 |
---|---|---|
committer | David Timber <mieabby@gmail.com> | 2020-09-08 20:10:57 +0930 |
commit | 0e512e6ae3146fcf3ce2427c8c36937d708d149b (patch) | |
tree | 40a6ad8c64b419e2f8d0bcc289e9608852ff76ae /src/pth.c | |
parent | 550d2eec27a42254b26139208765022fffe7c775 (diff) |
* Fix bug in pth_poll: wrong use of FD_SET()
causing undefined behaviour
* Fix bug in proone: loading ns pool from dvault for resolv
* Fix bug in htbt: improper handling of stream in htbt_relay_child()
* Switch back to _POSIX_C_SOURCE=200112L
Diffstat (limited to 'src/pth.c')
-rw-r--r-- | src/pth.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -26,6 +26,49 @@ void prne_fin_worker (prne_worker_t *w) { } } +int prne_pth_poll ( + struct pollfd *pfd, + const nfds_t nfs, + const int timeout, + pth_event_t ev) +{ + struct pollfd my_pfd[nfs]; + nfds_t p; + int ret; + + p = 0; + for (nfds_t i = 0; i < nfs; i += 1) { + if (pfd[i].fd >= FD_SETSIZE) { + errno = EINVAL; + return -1; + } + if (0 <= pfd[i].fd) { + my_pfd[p].fd = pfd[i].fd; + my_pfd[p].events = pfd[i].events; + p += 1; + } + } + if (p == 0) { + return 0; + } + + ret = pth_poll_ev(my_pfd, p, timeout, ev); + if (ret >= 0) { + p = 0; + for (nfds_t i = 0; i < nfs; i += 1) { + if (0 <= pfd[i].fd) { + pfd[i].revents = my_pfd[p].revents; + p += 1; + } + else { + pfd[i].revents = 0; + } + } + } + + return ret; +} + void prne_pth_cv_notify (pth_mutex_t *lock, pth_cond_t *cond, bool broadcast) { prne_dbgtrap(pth_mutex_acquire(lock, FALSE, NULL)); prne_dbgtrap(pth_cond_notify(cond, broadcast)); |