Browse Source

dynamic handlers store debug flag in handler_ctx

(for persistence across multiple re-entries into routines upon
 receiving fdevent)

(setting module debug flag in global scope is still recommended
 since there are places where p->conf.debug is checked since
 handler_ctx might not be available at all points)
personal/stbuehler/mod-csrf-old
Glenn Strauss 5 years ago
parent
commit
dc91e40657
  1. 29
      src/mod_fastcgi.c
  2. 19
      src/mod_proxy.c
  3. 15
      src/mod_scgi.c

29
src/mod_fastcgi.c

@ -436,14 +436,12 @@ static void fcgi_host_reset(server *srv, handler_ctx *hctx) {
}
static void fcgi_host_disable(server *srv, handler_ctx *hctx) {
plugin_data *p = hctx->plugin_data;
if (hctx->host->disable_time || hctx->proc->is_local) {
if (hctx->proc->state == PROC_STATE_RUNNING) hctx->host->active_procs--;
hctx->proc->disabled_until = srv->cur_ts + hctx->host->disable_time;
hctx->proc->state = hctx->proc->is_local ? PROC_STATE_DIED_WAIT_FOR_PID : PROC_STATE_DIED;
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sds",
"backend disabled for", hctx->host->disable_time, "seconds");
}
@ -1604,7 +1602,7 @@ static void fcgi_backend_close(server *srv, handler_ctx *hctx) {
/* after the connect the process gets a load */
fcgi_proc_load_dec(srv, hctx);
if (hctx->plugin_data->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "ssdsbsd",
"released proc:",
"pid:", hctx->proc->pid,
@ -1635,8 +1633,6 @@ static void fcgi_connection_close(server *srv, handler_ctx *hctx) {
}
static int fcgi_reconnect(server *srv, handler_ctx *hctx) {
plugin_data *p = hctx->plugin_data;
/* child died
*
* 1.
@ -1668,7 +1664,7 @@ static int fcgi_reconnect(server *srv, handler_ctx *hctx) {
hctx->request_id = 0;
hctx->reconnects++;
if (p->conf.debug > 2) {
if (hctx->conf.debug > 2) {
if (hctx->proc) {
log_error_write(srv, __FILE__, __LINE__, "sdb",
"release proc for reconnect:",
@ -1946,7 +1942,6 @@ static int fcgi_env_add_request_headers(server *srv, connection *con, plugin_dat
static void fcgi_stdin_append(server *srv, connection *con, handler_ctx *hctx, int request_id) {
FCGI_Header header;
chunkqueue *req_cq = con->request_content_queue;
plugin_data *p = hctx->plugin_data;
off_t offset, weWant;
const off_t req_cqlen = req_cq->bytes_in - req_cq->bytes_out;
@ -1962,7 +1957,7 @@ static void fcgi_stdin_append(server *srv, connection *con, handler_ctx *hctx, i
chunkqueue_append_mem(hctx->wb, (const char *)&header, sizeof(header));
hctx->wb_reqlen += sizeof(header);
if (p->conf.debug > 10) {
if (hctx->conf.debug > 10) {
log_error_write(srv, __FILE__, __LINE__, "soso", "tosend:", offset, "/", req_cqlen);
}
@ -2330,7 +2325,7 @@ static int fcgi_response_parse(server *srv, connection *con, plugin_data *p, buf
filename = pos;
if (NULL == (range = strchr(pos, ' '))) {
/* missing range */
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "ss", "Couldn't find range after filename:", filename);
}
return 502;
@ -2366,14 +2361,14 @@ static int fcgi_response_parse(server *srv, connection *con, plugin_data *p, buf
}
if (HANDLER_ERROR == stat_cache_get_entry(srv, con, srv->tmp_buf, &sce)) {
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"send-file error: couldn't get stat_cache entry for X-Sendfile2:",
srv->tmp_buf);
}
return 404;
} else if (!S_ISREG(sce->st.st_mode)) {
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"send-file error: wrong filetype for X-Sendfile2:",
srv->tmp_buf);
@ -2400,7 +2395,7 @@ static int fcgi_response_parse(server *srv, connection *con, plugin_data *p, buf
goto range_success;
range_failed:
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "ss", "Couldn't decode range after filename:", filename);
}
return 502;
@ -2503,7 +2498,7 @@ static int fastcgi_get_packet(server *srv, handler_ctx *hctx, fastcgi_response_p
if (buffer_string_length(packet->b) < sizeof(FCGI_Header)) {
/* no header */
if (hctx->plugin_data->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sdsds", "FastCGI: header too small:", buffer_string_length(packet->b), "bytes <", sizeof(FCGI_Header), "bytes, waiting for more data");
}
@ -2923,7 +2918,7 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
return HANDLER_ERROR;
}
if (socket_error != 0) {
if (!hctx->proc->is_local || p->conf.debug) {
if (!hctx->proc->is_local || hctx->conf.debug) {
/* local procs get restarted */
log_error_write(srv, __FILE__, __LINE__, "sssb",
@ -3077,7 +3072,7 @@ static handler_t fcgi_write_request(server *srv, handler_ctx *hctx) {
status_counter_inc(srv, CONST_BUF_LEN(p->statuskey));
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "ssdsbsd",
"got proc:",
"pid:", hctx->proc->pid,
@ -3398,7 +3393,7 @@ static handler_t fcgi_recv_response(server *srv, handler_ctx *hctx) {
status);
}
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "ssbsdsd",
"--- fastcgi spawning",
"\n\tsocket", proc->connection_name,

19
src/mod_proxy.c

@ -104,6 +104,8 @@ typedef struct {
size_t path_info_offset; /* start of path_info in uri.path */
plugin_config conf;
connection *remote_conn; /* dump pointer */
plugin_data *plugin_data; /* dump pointer */
} handler_ctx;
@ -368,7 +370,6 @@ static int proxy_establish_connection(server *srv, handler_ctx *hctx) {
#endif
socklen_t servlen;
plugin_data *p = hctx->plugin_data;
data_proxy *host= hctx->host;
int proxy_fd = hctx->fd;
@ -411,7 +412,7 @@ static int proxy_establish_connection(server *srv, handler_ctx *hctx) {
if (-1 == connect(proxy_fd, proxy_addr, servlen)) {
if (errno == EINPROGRESS || errno == EALREADY) {
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"connect delayed:", proxy_fd);
}
@ -425,7 +426,7 @@ static int proxy_establish_connection(server *srv, handler_ctx *hctx) {
return -1;
}
}
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"connect succeeded: ", proxy_fd);
}
@ -646,7 +647,7 @@ static int proxy_demux_response(server *srv, handler_ctx *hctx) {
#endif
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"proxy - have to read:", b);
}
@ -1024,7 +1025,7 @@ static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
if (revents & FDEVENT_IN) {
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"proxy: fdevent-in", hctx->state);
}
@ -1036,7 +1037,7 @@ static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
}
if (revents & FDEVENT_OUT) {
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"proxy: fdevent-out", hctx->state);
}
@ -1059,7 +1060,7 @@ static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
return HANDLER_FINISHED;
}
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "s", "proxy - connect - delayed success");
}
@ -1071,7 +1072,7 @@ static handler_t proxy_handle_fdevent(server *srv, void *ctx, int revents) {
/* perhaps this issue is already handled */
if (revents & FDEVENT_HUP) {
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"proxy: fdevent-hup", hctx->state);
}
@ -1321,6 +1322,8 @@ static handler_t mod_proxy_check_extension(server *srv, connection *con, void *p
hctx->plugin_data = p;
hctx->host = host;
hctx->conf.debug = p->conf.debug;
con->plugin_ctx[p->id] = hctx;
host->usage++;

15
src/mod_scgi.c

@ -1325,7 +1325,7 @@ static void scgi_connection_close(server *srv, handler_ctx *hctx) {
/* after the connect the process gets a load */
hctx->proc->load--;
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sddb",
"release proc:",
hctx->fd,
@ -1347,8 +1347,6 @@ static void scgi_connection_close(server *srv, handler_ctx *hctx) {
}
static int scgi_reconnect(server *srv, handler_ctx *hctx) {
plugin_data *p = hctx->plugin_data;
/* child died
*
* 1.
@ -1376,7 +1374,7 @@ static int scgi_reconnect(server *srv, handler_ctx *hctx) {
hctx->reconnects++;
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sddb",
"release proc:",
hctx->fd,
@ -2249,7 +2247,6 @@ static int scgi_restart_dead_procs(server *srv, plugin_data *p, scgi_extension_h
static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
plugin_data *p = hctx->plugin_data;
scgi_extension_host *host= hctx->host;
connection *con = hctx->remote_conn;
@ -2349,7 +2346,7 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
return HANDLER_ERROR;
}
if (socket_error != 0) {
if (!hctx->proc->is_local || p->conf.debug) {
if (!hctx->proc->is_local || hctx->conf.debug) {
/* local procs get restarted */
log_error_write(srv, __FILE__, __LINE__, "ss",
@ -2367,7 +2364,7 @@ static handler_t scgi_write_request(server *srv, handler_ctx *hctx) {
hctx->proc->last_used = srv->cur_ts;
hctx->got_proc = 1;
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sddbdd",
"got proc:",
hctx->fd,
@ -2497,7 +2494,7 @@ static handler_t scgi_send_request(server *srv, handler_ctx *hctx) {
*/
if (proc && proc->is_local) {
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "sbdb", "connect() to scgi failed, restarting the request-handling:",
host->host,
proc->port,
@ -2633,7 +2630,7 @@ static handler_t scgi_recv_response(server *srv, handler_ctx *hctx) {
status);
}
if (p->conf.debug) {
if (hctx->conf.debug) {
log_error_write(srv, __FILE__, __LINE__, "ssdsbsdsd",
"--- scgi spawning",
"\n\tport:", host->port,

Loading…
Cancel
Save