diff options
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/nc/compat/accept4.c | 10 | ||||
| -rw-r--r-- | apps/nc/compat/readpassphrase.c | 2 | ||||
| -rw-r--r-- | apps/openssl/compat/poll_win.c | 35 |
3 files changed, 41 insertions, 6 deletions
diff --git a/apps/nc/compat/accept4.c b/apps/nc/compat/accept4.c index dca42e9..7818bc0 100644 --- a/apps/nc/compat/accept4.c +++ b/apps/nc/compat/accept4.c | |||
| @@ -5,12 +5,18 @@ int | |||
| 5 | accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) | 5 | accept4(int s, struct sockaddr *addr, socklen_t *addrlen, int flags) |
| 6 | { | 6 | { |
| 7 | int rets = accept(s, addr, addrlen); | 7 | int rets = accept(s, addr, addrlen); |
| 8 | int fl; | ||
| 8 | if (rets == -1) | 9 | if (rets == -1) |
| 9 | return rets; | 10 | return rets; |
| 10 | 11 | ||
| 11 | if (flags & SOCK_CLOEXEC) { | 12 | if (flags & SOCK_CLOEXEC) { |
| 12 | flags = fcntl(rets, F_GETFD); | 13 | fl = fcntl(rets, F_GETFD); |
| 13 | fcntl(rets, F_SETFD, flags | FD_CLOEXEC); | 14 | fcntl(rets, F_SETFD, fl | FD_CLOEXEC); |
| 15 | } | ||
| 16 | |||
| 17 | if (flags & SOCK_NONBLOCK) { | ||
| 18 | fl = fcntl(rets, F_GETFL); | ||
| 19 | fcntl(rets, F_SETFL, fl | O_NONBLOCK); | ||
| 14 | } | 20 | } |
| 15 | 21 | ||
| 16 | return rets; | 22 | return rets; |
diff --git a/apps/nc/compat/readpassphrase.c b/apps/nc/compat/readpassphrase.c index f3aa248..2a1e9ef 100644 --- a/apps/nc/compat/readpassphrase.c +++ b/apps/nc/compat/readpassphrase.c | |||
| @@ -94,6 +94,8 @@ restart: | |||
| 94 | } | 94 | } |
| 95 | input = STDIN_FILENO; | 95 | input = STDIN_FILENO; |
| 96 | output = STDERR_FILENO; | 96 | output = STDERR_FILENO; |
| 97 | } else { | ||
| 98 | (void)fcntl(input, F_SETFD, FD_CLOEXEC); | ||
| 97 | } | 99 | } |
| 98 | 100 | ||
| 99 | /* | 101 | /* |
diff --git a/apps/openssl/compat/poll_win.c b/apps/openssl/compat/poll_win.c index 30f6b60..70a7d06 100644 --- a/apps/openssl/compat/poll_win.c +++ b/apps/openssl/compat/poll_win.c | |||
| @@ -73,6 +73,8 @@ compute_select_revents(int fd, short events, | |||
| 73 | rc |= POLLHUP; | 73 | rc |= POLLHUP; |
| 74 | else if (conn_has_oob_data(fd)) | 74 | else if (conn_has_oob_data(fd)) |
| 75 | rc |= POLLRDBAND | POLLPRI; | 75 | rc |= POLLRDBAND | POLLPRI; |
| 76 | else | ||
| 77 | rc |= POLLERR; | ||
| 76 | } | 78 | } |
| 77 | 79 | ||
| 78 | return rc; | 80 | return rc; |
| @@ -152,6 +154,9 @@ wsa_select_errno(int err) | |||
| 152 | case WSAENETDOWN: | 154 | case WSAENETDOWN: |
| 153 | errno = ENOMEM; | 155 | errno = ENOMEM; |
| 154 | break; | 156 | break; |
| 157 | default: | ||
| 158 | errno = EIO; | ||
| 159 | break; | ||
| 155 | } | 160 | } |
| 156 | return -1; | 161 | return -1; |
| 157 | } | 162 | } |
| @@ -166,6 +171,7 @@ poll(struct pollfd *pfds, nfds_t nfds, int timeout_ms) | |||
| 166 | * select machinery | 171 | * select machinery |
| 167 | */ | 172 | */ |
| 168 | fd_set rfds, wfds, efds; | 173 | fd_set rfds, wfds, efds; |
| 174 | fd_set rfds_in, wfds_in, efds_in; | ||
| 169 | int rc; | 175 | int rc; |
| 170 | int num_sockets; | 176 | int num_sockets; |
| 171 | 177 | ||
| @@ -249,15 +255,36 @@ poll(struct pollfd *pfds, nfds_t nfds, int timeout_ms) | |||
| 249 | wait_rc = WAIT_FAILED; | 255 | wait_rc = WAIT_FAILED; |
| 250 | 256 | ||
| 251 | looptime_ms = (timeout_ms > 100 || timeout_ms == -1) ? 100 : timeout_ms; | 257 | looptime_ms = (timeout_ms > 100 || timeout_ms == -1) ? 100 : timeout_ms; |
| 252 | if (timeout_ms == -1) | 258 | |
| 253 | timeout_ms = INFINITE; | 259 | /* |
| 260 | * select() clears every descriptor that is not ready from the | ||
| 261 | * fd_sets, so a pass that times out leaves them empty. Keep a | ||
| 262 | * pristine copy and restore it before each select(), otherwise the | ||
| 263 | * next pass hands select() three empty sets and Windows fails it with | ||
| 264 | * WSAEINVAL instead of waiting out the remaining timeout. | ||
| 265 | */ | ||
| 266 | rfds_in = rfds; | ||
| 267 | wfds_in = wfds; | ||
| 268 | efds_in = efds; | ||
| 254 | 269 | ||
| 255 | do { | 270 | do { |
| 256 | TIMEVAL tv; | 271 | TIMEVAL tv; |
| 272 | |||
| 273 | /* | ||
| 274 | * Cap the wait at the time remaining so the final pass | ||
| 275 | * does not overshoot the requested timeout. | ||
| 276 | */ | ||
| 277 | if (timeout_ms != -1 && timeout_ms - timespent_ms < looptime_ms) | ||
| 278 | looptime_ms = timeout_ms - timespent_ms; | ||
| 279 | |||
| 257 | tv.tv_sec = 0; | 280 | tv.tv_sec = 0; |
| 258 | tv.tv_usec = looptime_ms * 1000; | 281 | tv.tv_usec = looptime_ms * 1000; |
| 259 | int handle_signaled = 0; | 282 | int handle_signaled = 0; |
| 260 | 283 | ||
| 284 | rfds = rfds_in; | ||
| 285 | wfds = wfds_in; | ||
| 286 | efds = efds_in; | ||
| 287 | |||
| 261 | /* | 288 | /* |
| 262 | * Check if any file handles have signaled | 289 | * Check if any file handles have signaled |
| 263 | */ | 290 | */ |
| @@ -280,7 +307,7 @@ poll(struct pollfd *pfds, nfds_t nfds, int timeout_ms) | |||
| 280 | /* | 307 | /* |
| 281 | * If we signaled on a file handle, don't wait on the sockets. | 308 | * If we signaled on a file handle, don't wait on the sockets. |
| 282 | */ | 309 | */ |
| 283 | if (wait_rc >= WAIT_OBJECT_0 && | 310 | if (num_handles && wait_rc >= WAIT_OBJECT_0 && |
| 284 | (wait_rc <= WAIT_OBJECT_0 + num_handles - 1)) { | 311 | (wait_rc <= WAIT_OBJECT_0 + num_handles - 1)) { |
| 285 | tv.tv_usec = 0; | 312 | tv.tv_usec = 0; |
| 286 | handle_signaled = 1; | 313 | handle_signaled = 1; |
| @@ -298,7 +325,7 @@ poll(struct pollfd *pfds, nfds_t nfds, int timeout_ms) | |||
| 298 | 325 | ||
| 299 | timespent_ms += looptime_ms; | 326 | timespent_ms += looptime_ms; |
| 300 | 327 | ||
| 301 | } while (timespent_ms < timeout_ms); | 328 | } while (timeout_ms == -1 || timespent_ms < timeout_ms); |
| 302 | 329 | ||
| 303 | rc = 0; | 330 | rc = 0; |
| 304 | num_handles = 0; | 331 | num_handles = 0; |
