mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
cgi: gracefully handle missing wsi->http.cgi
This commit is contained in:
parent
027fe42cec
commit
fcde566fc6
2 changed files with 21 additions and 16 deletions
|
@ -686,21 +686,23 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
|
||||
case LWS_CALLBACK_CGI_TERMINATED:
|
||||
lwsl_wsi_debug(wsi, "CGI_TERMINATED: %d %" PRIu64,
|
||||
if (wsi->http.cgi) {
|
||||
lwsl_wsi_debug(wsi, "CGI_TERMINATED: %d %" PRIu64,
|
||||
wsi->http.cgi->explicitly_chunked,
|
||||
(uint64_t)wsi->http.cgi->content_length);
|
||||
if (!(wsi->http.cgi->explicitly_chunked && wsi->mux_substream) &&
|
||||
!wsi->http.cgi->content_length) {
|
||||
/* send terminating chunk */
|
||||
lwsl_wsi_debug(wsi, "LWS_CALLBACK_CGI_TERMINATED: ending");
|
||||
wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_CHUNK_END;
|
||||
lws_callback_on_writable(wsi);
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, 3);
|
||||
break;
|
||||
}
|
||||
if (wsi->mux_substream && !wsi->cgi_stdout_zero_length)
|
||||
lws_write(wsi, (unsigned char *)buf + LWS_PRE, 0,
|
||||
if (!(wsi->http.cgi->explicitly_chunked && wsi->mux_substream) &&
|
||||
!wsi->http.cgi->content_length) {
|
||||
/* send terminating chunk */
|
||||
lwsl_wsi_debug(wsi, "LWS_CALLBACK_CGI_TERMINATED: ending");
|
||||
wsi->reason_bf |= LWS_CB_REASON_AUX_BF__CGI_CHUNK_END;
|
||||
lws_callback_on_writable(wsi);
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_CGI, 3);
|
||||
break;
|
||||
}
|
||||
if (wsi->mux_substream && !wsi->cgi_stdout_zero_length)
|
||||
lws_write(wsi, (unsigned char *)buf + LWS_PRE, 0,
|
||||
LWS_WRITE_HTTP_FINAL);
|
||||
}
|
||||
#if defined(LWS_WITH_SERVER)
|
||||
if (lws_http_transaction_completed(wsi))
|
||||
return -1;
|
||||
|
|
|
@ -95,14 +95,16 @@ lws_cgi_reap_cb(void *opaque, lws_usec_t *accounting, siginfo_t *si,
|
|||
* The cgi has come to an end, by itself or with a signal...
|
||||
*/
|
||||
|
||||
lwsl_wsi_info(wsi, "post_in_expected %d",
|
||||
if (wsi->http.cgi)
|
||||
lwsl_wsi_info(wsi, "post_in_expected %d",
|
||||
(int)wsi->http.cgi->post_in_expected);
|
||||
|
||||
/*
|
||||
* Grace period to handle the incoming stdout
|
||||
*/
|
||||
|
||||
lws_sul_schedule(wsi->a.context, wsi->tsi, &wsi->http.cgi->sul_grace,
|
||||
if (wsi->http.cgi)
|
||||
lws_sul_schedule(wsi->a.context, wsi->tsi, &wsi->http.cgi->sul_grace,
|
||||
lws_cgi_grace, 1 * LWS_US_PER_SEC);
|
||||
}
|
||||
|
||||
|
@ -907,7 +909,7 @@ lws_cgi_kill(struct lws *wsi)
|
|||
{
|
||||
struct lws_cgi_args args;
|
||||
pid_t pid;
|
||||
int n, m;
|
||||
int n, m = 0;
|
||||
|
||||
if (!wsi->http.cgi || !wsi->http.cgi->lsp)
|
||||
return 0;
|
||||
|
@ -919,7 +921,8 @@ lws_cgi_kill(struct lws *wsi)
|
|||
/* that has invalidated and NULL'd wsi->http.cgi->lsp */
|
||||
|
||||
if (pid != -1) {
|
||||
m = wsi->http.cgi->being_closed;
|
||||
if (wsi->http.cgi)
|
||||
m = wsi->http.cgi->being_closed;
|
||||
n = user_callback_handle_rxflow(wsi->a.protocol->callback, wsi,
|
||||
LWS_CALLBACK_CGI_TERMINATED,
|
||||
wsi->user_space, (void *)&args,
|
||||
|
|
Loading…
Add table
Reference in a new issue