diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2023-04-28 00:03:02 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2023-05-03 23:11:35 -0400 |
commit | 99f03a2bce23f55b49d85cd7fc1acbaee3dd22c7 (patch) | |
tree | ab520258b516096a0a2fff85efc0d3e9ba26a50f | |
parent | 7381c119ed11f36260fe724b0dda907c56bf3108 (diff) | |
download | lighttpd-git-99f03a2bce23f55b49d85cd7fc1acbaee3dd22c7.tar.gz |
[core] always decr fd count upon socket close()
always decr fd count in connection_close()
always decr fd count in fdevent_sched_run()
Error return value from close() should be used for diagnostics and
recovery, but the state of the file descriptor is unspecified by POSIX.
On most systems, it is invalid to redo close(). (Linux 'man 2 close'
suggests that HP-UX is an outlier, and that a future POSIX standard
update will specify the behavior for the file descriptor to be closed)
EBADF should not happen in those funcs for lighttpd since those should
be the only locations in lighttpd where those fds are closed.
-rw-r--r-- | src/connections.c | 5 | ||||
-rw-r--r-- | src/fdevent_impl.c | 5 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/connections.c b/src/connections.c index 7c849bf1..51afa665 100644 --- a/src/connections.c +++ b/src/connections.c @@ -88,9 +88,7 @@ static void connection_close(connection *con) { fdevent_fdnode_event_del(srv->ev, con->fdn); fdevent_unregister(srv->ev, con->fdn); con->fdn = NULL; - if (0 == fdio_close_socket(con->fd)) - --srv->cur_fds; - else + if (0 != fdio_close_socket(con->fd)) log_serror(r->conf.errh, __FILE__, __LINE__, "(warning) close: %d", con->fd); @@ -100,6 +98,7 @@ static void connection_close(connection *con) { } con->fd = -1; + --srv->cur_fds; connection_del(srv, con); } diff --git a/src/fdevent_impl.c b/src/fdevent_impl.c index a3a1f66b..bd409a85 100644 --- a/src/fdevent_impl.c +++ b/src/fdevent_impl.c @@ -282,14 +282,15 @@ fdevent_sched_run (fdevents * const ev) { for (fdnode *fdn = ev->pendclose; fdn; ) { int fd = fdn->fd; + /*(inlined fdio_close_socket() for tighter loop; worthwhile?)*/ #ifdef _WIN32 if (0 != closesocket(fd)) /* WSAPoll() valid only on SOCKET */ #else if (0 != close(fd)) #endif log_serror(ev->errh, __FILE__, __LINE__, "close() %d", fd); - else - --(*ev->cur_fds); + + --(*ev->cur_fds); fdnode * const fdn_tmp = fdn; fdn = (fdnode *)fdn->ctx; /* next */ |