]> granicus.if.org Git - apache/commitdiff
Provide new ap_update_child_status_from_conn() mostly
authorJim Jagielski <jim@apache.org>
Sat, 3 Oct 2009 12:54:35 +0000 (12:54 +0000)
committerJim Jagielski <jim@apache.org>
Sat, 3 Oct 2009 12:54:35 +0000 (12:54 +0000)
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

include/scoreboard.h
modules/experimental/mod_noloris.c
server/scoreboard.c

index 5a990c3545c9e4eb2c65f3519504991754d38721..07ba9d1a54a5aee8ef04fe3fc57411d167283562 100644 (file)
@@ -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);
index 75bb9115db81072595dbbc6f2b8d72859f99887e..dec385318e233e847323023eee1f7887057759dd 100644 (file)
@@ -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;
 }
index 257212e56d80399ad41a7879abee852eba14957e..f5423a8ed0a3610cff107c4c10c796fd983b7602 100644 (file)
@@ -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;