From: Jim Jagielski Date: Sat, 3 Oct 2009 12:54:35 +0000 (+0000) Subject: Provide new ap_update_child_status_from_conn() mostly X-Git-Tag: 2.3.3~225 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=abcfac33f8d3f7690425f6426bb1fb1af9fe6419;p=thirdparty%2Fapache%2Fhttpd.git Provide new ap_update_child_status_from_conn() mostly for use with mod_noloris.c Add some logic protection, for NULL ref, which shoulda be there in any case. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@821307 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/scoreboard.h b/include/scoreboard.h index 5a990c3545c..07ba9d1a54a 100644 --- a/include/scoreboard.h +++ b/include/scoreboard.h @@ -173,6 +173,7 @@ AP_DECLARE(int) ap_find_child_by_pid(apr_proc_t *pid); AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r); AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num, int status, request_rec *r); +AP_DECLARE(int) ap_update_child_status_from_conn(ap_sb_handle_t *sbh, int status, conn_rec *c); AP_DECLARE(void) ap_time_process_request(ap_sb_handle_t *sbh, int status); AP_DECLARE(worker_score *) ap_get_scoreboard_worker(ap_sb_handle_t *sbh); diff --git a/modules/experimental/mod_noloris.c b/modules/experimental/mod_noloris.c index 75bb9115db8..dec385318e2 100644 --- a/modules/experimental/mod_noloris.c +++ b/modules/experimental/mod_noloris.c @@ -57,17 +57,9 @@ static int thread_limit; static int noloris_conn(conn_rec *conn) { - /*** FIXME - * This is evil: we're assuming info that's private to the scoreboard - * We need to do that because there's no API to update the scoreboard - * on a connection, only with a request (or NULL to say not processing - * any request). We need a version of ap_update_child_status that - * accepts a conn_rec. - */ struct { int child_num; int thread_num; } *sbh = conn->sbh; char *shm_rec; - worker_score *ws; if (shm == NULL) { return DECLINED; /* we're disabled */ } @@ -88,13 +80,8 @@ static int noloris_conn(conn_rec *conn) } /* store this client IP for the monitor to pick up */ - /* under traditional scoreboard, none of this happens until - * there's a request_rec. This is where we use the illegally- - * obtained private info from the scoreboard. - */ - - ws = &ap_scoreboard_image->servers[sbh->child_num][sbh->thread_num]; - strcpy(ws->client, conn->remote_ip); + + ap_update_child_status_from_conn(conn->sbh, SERVER_READY, conn); return DECLINED; } diff --git a/server/scoreboard.c b/server/scoreboard.c index 257212e56d8..f5423a8ed0a 100644 --- a/server/scoreboard.c +++ b/server/scoreboard.c @@ -472,8 +472,10 @@ AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, apr_cpystrn(ws->client, ap_get_remote_host(c, r->per_dir_config, REMOTE_NOLOOKUP, NULL), sizeof(ws->client)); copy_request(ws->request, sizeof(ws->request), r); - apr_cpystrn(ws->vhost, r->server->server_hostname, - sizeof(ws->vhost)); + if (r->server) { + apr_cpystrn(ws->vhost, r->server->server_hostname, + sizeof(ws->vhost)); + } } } @@ -490,6 +492,19 @@ AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, status, r); } +AP_DECLARE(int) ap_update_child_status_from_conn(ap_sb_handle_t *sbh, int status, + conn_rec *c) +{ + if (!sbh) + return -1; + + request_rec fake_rec; + fake_rec.connection = c; + + return ap_update_child_status_from_indexes(sbh->child_num, sbh->thread_num, + status, &fake_rec); +} + AP_DECLARE(void) ap_time_process_request(ap_sb_handle_t *sbh, int status) { worker_score *ws;