diff --git a/lib/core/context.c b/lib/core/context.c index f5dd745c8..c7df2628a 100644 --- a/lib/core/context.c +++ b/lib/core/context.c @@ -2059,14 +2059,17 @@ lws_context_destroy2(struct lws_context *context) if (context->event_loop_ops->destroy_context2) if (context->event_loop_ops->destroy_context2(context)) { + lws_context_unlock(context); /* } context ----------- */ context->finalize_destroy_after_internal_loops_stopped = 1; return; } if (!context->pt[0].event_loop_foreign) for (n = 0; n < context->count_threads; n++) - if (context->pt[n].inside_service) + if (context->pt[n].inside_service) { + lws_context_unlock(context); /* } context --- */ return; + } lws_context_unlock(context); /* } context ------------------- */ diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index 0104fbc6c..a781b1b82 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -105,7 +105,11 @@ int lws_open(const char *__file, int __oflag, ...) n = open(__file, __oflag); va_end(ap); - lws_plat_apply_FD_CLOEXEC(n); + if (n != -1 && lws_plat_apply_FD_CLOEXEC(n)) { + close(n); + + return -1; + } return n; } diff --git a/lib/core/private.h b/lib/core/private.h index 6e111ce95..84b4a949a 100644 --- a/lib/core/private.h +++ b/lib/core/private.h @@ -1370,7 +1370,7 @@ lws_plat_pipe_close(struct lws *wsi); int lws_create_event_pipes(struct lws_context *context); -void +int lws_plat_apply_FD_CLOEXEC(int n); const struct lws_plat_file_ops * diff --git a/lib/plat/esp32/esp32-file.c b/lib/plat/esp32/esp32-file.c index cfddd7aca..41bca2210 100644 --- a/lib/plat/esp32/esp32-file.c +++ b/lib/plat/esp32/esp32-file.c @@ -29,8 +29,9 @@ #include #include -void lws_plat_apply_FD_CLOEXEC(int n) +int lws_plat_apply_FD_CLOEXEC(int n) { + return 0; } diff --git a/lib/plat/optee/lws-plat-optee.c b/lib/plat/optee/lws-plat-optee.c index 9803dad49..6aa376bb6 100644 --- a/lib/plat/optee/lws-plat-optee.c +++ b/lib/plat/optee/lws-plat-optee.c @@ -4,8 +4,9 @@ * included from libwebsockets.c for OPTEE builds */ -void lws_plat_apply_FD_CLOEXEC(int n) +int lws_plat_apply_FD_CLOEXEC(int n) { + return 0; } int diff --git a/lib/plat/unix/unix-file.c b/lib/plat/unix/unix-file.c index 32392970a..bcdc213a8 100644 --- a/lib/plat/unix/unix-file.c +++ b/lib/plat/unix/unix-file.c @@ -30,10 +30,12 @@ #endif #include -void lws_plat_apply_FD_CLOEXEC(int n) +int lws_plat_apply_FD_CLOEXEC(int n) { - if (n != -1) - fcntl(n, F_SETFD, FD_CLOEXEC ); + if (n == -1) + return 0; + + return fcntl(n, F_SETFD, FD_CLOEXEC); } int diff --git a/lib/plat/unix/unix-sockets.c b/lib/plat/unix/unix-sockets.c index 01bd32c21..f4eb97cef 100644 --- a/lib/plat/unix/unix-sockets.c +++ b/lib/plat/unix/unix-sockets.c @@ -74,7 +74,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) struct protoent *tcp_proto; #endif - fcntl(fd, F_SETFD, FD_CLOEXEC); + (void)fcntl(fd, F_SETFD, FD_CLOEXEC); if (vhost->ka_time) { /* enable keepalive on this socket */ diff --git a/lib/plat/windows/windows-file.c b/lib/plat/windows/windows-file.c index 74920bd25..ee9dc7418 100644 --- a/lib/plat/windows/windows-file.c +++ b/lib/plat/windows/windows-file.c @@ -24,8 +24,9 @@ #endif #include "core/private.h" -void lws_plat_apply_FD_CLOEXEC(int n) +int lws_plat_apply_FD_CLOEXEC(int n) { + return 0; } lws_fop_fd_t diff --git a/lib/roles/cgi/cgi-server.c b/lib/roles/cgi/cgi-server.c index 95121b4dd..5c4b10c27 100644 --- a/lib/roles/cgi/cgi-server.c +++ b/lib/roles/cgi/cgi-server.c @@ -885,7 +885,9 @@ agin: /* payload processing */ - m = !wsi->http.cgi->implied_chunked && !wsi->http2_substream && !wsi->http.cgi->explicitly_chunked && !wsi->http.cgi->content_length; + m = !wsi->http.cgi->implied_chunked && !wsi->http2_substream && + !wsi->http.cgi->explicitly_chunked && + !wsi->http.cgi->content_length; n = lws_get_socket_fd(wsi->http.cgi->stdwsi[LWS_STDOUT]); if (n < 0) return -1; @@ -904,15 +906,14 @@ agin: return 0; } - n = read(n, start, sizeof(buf) - LWS_PRE - - (m ? LWS_HTTP_CHUNK_HDR_SIZE : 0)); + n = read(n, start, sizeof(buf) - LWS_PRE); if (n < 0 && errno != EAGAIN) { lwsl_debug("%s: stdout read says %d\n", __func__, n); return -1; } if (n > 0) { - +/* if (!wsi->http2_substream && m) { char chdr[LWS_HTTP_CHUNK_HDR_SIZE]; m = lws_snprintf(chdr, LWS_HTTP_CHUNK_HDR_SIZE - 3, @@ -922,6 +923,7 @@ agin: memcpy(start + m + n, "\x0d\x0a", 2); n += m + 2; } + */ cmd = LWS_WRITE_HTTP; if (wsi->http.cgi->content_length_seen + n == wsi->http.cgi->content_length) cmd = LWS_WRITE_HTTP_FINAL;