]> granicus.if.org Git - apache/blobdiff - server/scoreboard.c
Help doc writer to spot places where:
[apache] / server / scoreboard.c
index c6e8a4e00ca8248e74a8f8e8d4cbeef0094a41ba..a028447ffbd0f31ba3f72da53c390d064d627006 100644 (file)
@@ -210,19 +210,12 @@ static apr_status_t open_scoreboard(apr_pool_t *pconf)
 #if APR_HAS_SHARED_MEMORY
     apr_status_t rv;
     char *fname = NULL;
-    apr_pool_t *global_pool;
-
-    /* We don't want to have to recreate the scoreboard after
-     * restarts, so we'll create a global pool and never clean it.
-     */
-    rv = apr_pool_create(&global_pool, NULL);
-    if (rv != APR_SUCCESS) {
-        ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, APLOGNO(00002)
-                     "Fatal error: unable to create global pool "
-                     "for use by the scoreboard");
-        return rv;
-    }
+    apr_pool_t *global_pool = apr_pool_parent_get(pconf);
 
+    /* If this is not passed pconf, or pconf is no longer a direct
+     * child of a global pool, this should change... */
+    AP_DEBUG_ASSERT(apr_pool_parent_get(global_pool) == NULL);
+    
     /* The config says to create a name-based shmem */
     if (ap_scoreboard_fname) {
         /* make sure it's an absolute pathname */
@@ -364,6 +357,18 @@ AP_DECLARE(int) ap_exists_scoreboard_image(void)
     return (ap_scoreboard_image ? 1 : 0);
 }
 
+AP_DECLARE(void) ap_set_conn_count(ap_sb_handle_t *sb, request_rec *r, 
+                                   unsigned short conn_count)
+{
+    worker_score *ws;
+
+    if (!sb)
+        return;
+
+    ws = &ap_scoreboard_image->servers[sb->child_num][sb->thread_num];
+    ws->conn_count = conn_count;
+}
+
 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sb, request_rec *r)
 {
     worker_score *ws;
@@ -410,12 +415,18 @@ AP_DECLARE(int) ap_find_child_by_pid(apr_proc_t *pid)
     return -1;
 }
 
+AP_DECLARE(void) ap_update_sb_handle(ap_sb_handle_t *sbh,
+                                     int child_num, int thread_num)
+{
+    sbh->child_num = child_num;
+    sbh->thread_num = thread_num;
+}
+
 AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p,
                                      int child_num, int thread_num)
 {
     *new_sbh = (ap_sb_handle_t *)apr_palloc(p, sizeof(ap_sb_handle_t));
-    (*new_sbh)->child_num = child_num;
-    (*new_sbh)->thread_num = thread_num;
+    ap_update_sb_handle(*new_sbh, child_num, thread_num);
 }
 
 static void copy_request(char *rbuf, apr_size_t rbuflen, request_rec *r)
@@ -464,22 +475,18 @@ static int update_child_status_internal(int child_num,
 {
     int old_status;
     worker_score *ws;
-    process_score *ps;
     int mpm_generation;
 
     ws = &ap_scoreboard_image->servers[child_num][thread_num];
     old_status = ws->status;
-    if (status >= 0) {
-        ws->status = status;
-        
-        ps = &ap_scoreboard_image->parent[child_num];
-        
-        if (status == SERVER_READY
-            && old_status == SERVER_STARTING) {
-            ws->thread_num = child_num * thread_limit + thread_num;
-            ap_mpm_query(AP_MPMQ_GENERATION, &mpm_generation);
-            ps->generation = mpm_generation;
-        }
+    ws->status = status;
+    
+    if (status == SERVER_READY
+        && old_status == SERVER_STARTING) {
+        process_score *ps = &ap_scoreboard_image->parent[child_num];
+        ws->thread_num = child_num * thread_limit + thread_num;
+        ap_mpm_query(AP_MPMQ_GENERATION, &mpm_generation);
+        ps->generation = mpm_generation;
     }
 
     if (ap_extended_status) {
@@ -492,50 +499,66 @@ static int update_child_status_internal(int child_num,
             if (status == SERVER_DEAD) {
                 ws->my_access_count = 0L;
                 ws->my_bytes_served = 0L;
+#ifdef HAVE_TIMES
+                ws->times.tms_utime = 0;
+                ws->times.tms_stime = 0;
+                ws->times.tms_cutime = 0;
+                ws->times.tms_cstime = 0;
+#endif
             }
             ws->conn_count = 0;
             ws->conn_bytes = 0;
             ws->last_used = apr_time_now();
         }
-        if (status == SERVER_READY) {
-            ws->client[0]='\0';
-            ws->vhost[0]='\0';
+
+        if (descr) {
+            apr_cpystrn(ws->request, descr, sizeof(ws->request));
+        }
+        else if (r) {
+            copy_request(ws->request, sizeof(ws->request), r);
+        }
+        else if (c) {
             ws->request[0]='\0';
-            ws->protocol[0]='\0';
         }
-        else {
-            if (descr) {
-                apr_cpystrn(ws->request, descr, sizeof(ws->request));
-            }
-            else if (r) {
-                copy_request(ws->request, sizeof(ws->request), r);
+
+        if (r && r->useragent_ip) {
+            if (!(val = ap_get_useragent_host(r, REMOTE_NOLOOKUP, NULL))) {
+                apr_cpystrn(ws->client, r->useragent_ip, sizeof(ws->client)); /* DEPRECATE */
+                apr_cpystrn(ws->client64, r->useragent_ip, sizeof(ws->client64));
             }
-            if (r) {
-                if (!(val = ap_get_useragent_host(r, REMOTE_NOLOOKUP, NULL)))
-                    apr_cpystrn(ws->client, r->useragent_ip, sizeof(ws->client));
-                else
-                    apr_cpystrn(ws->client, val, sizeof(ws->client));
+            else {
+                apr_cpystrn(ws->client, val, sizeof(ws->client)); /* DEPRECATE */
+                apr_cpystrn(ws->client64, val, sizeof(ws->client64));
             }
-            else if (c) {
-                if (!(val = ap_get_remote_host(c, c->base_server->lookup_defaults,
-                                               REMOTE_NOLOOKUP, NULL)))
-                    apr_cpystrn(ws->client, c->client_ip, sizeof(ws->client));
-                else
-                    apr_cpystrn(ws->client, val, sizeof(ws->client));
+        }
+        else if (c) {
+            if (!(val = ap_get_remote_host(c, c->base_server->lookup_defaults,
+                                           REMOTE_NOLOOKUP, NULL))) {
+                apr_cpystrn(ws->client, c->client_ip, sizeof(ws->client)); /* DEPRECATE */
+                apr_cpystrn(ws->client64, c->client_ip, sizeof(ws->client64));
             }
-            if (s) {
-                if (c) {
-                    apr_snprintf(ws->vhost, sizeof(ws->vhost), "%s:%d",
-                                 s->server_hostname, c->local_addr->port);
-                }
-                else {
-                    apr_cpystrn(ws->vhost, s->server_hostname, sizeof(ws->vhost));
-                }
+            else {
+                apr_cpystrn(ws->client, val, sizeof(ws->client)); /* DEPRECATE */
+                apr_cpystrn(ws->client64, val, sizeof(ws->client64));
             }
+        }
+
+        if (s) {
             if (c) {
-                val = ap_get_protocol(c);
-                apr_cpystrn(ws->protocol, val, sizeof(ws->protocol));
+                apr_snprintf(ws->vhost, sizeof(ws->vhost), "%s:%d",
+                             s->server_hostname, c->local_addr->port);
             }
+            else {
+                apr_cpystrn(ws->vhost, s->server_hostname, sizeof(ws->vhost));
+            }
+        }
+        else if (c) {
+            ws->vhost[0]='\0';
+        }
+
+        if (c) {
+            val = ap_get_protocol(c);
+            apr_cpystrn(ws->protocol, val, sizeof(ws->protocol));
         }
     }
 
@@ -617,7 +640,21 @@ AP_DECLARE(void) ap_time_process_request(ap_sb_handle_t *sbh, int status)
     }
     else if (status == STOP_PREQUEST) {
         ws->stop_time = ws->last_used = apr_time_now();
+        if (ap_extended_status) {
+            ws->duration += ws->stop_time - ws->start_time;
+        }
+    }
+}
+
+AP_DECLARE(int) ap_update_global_status()
+{
+#ifdef HAVE_TIMES
+    if (ap_scoreboard_image == NULL) {
+        return APR_SUCCESS;
     }
+    times(&ap_scoreboard_image->global->times);
+#endif
+    return APR_SUCCESS;
 }
 
 AP_DECLARE(worker_score *) ap_get_scoreboard_worker_from_indexes(int x, int y)
@@ -649,6 +686,7 @@ AP_DECLARE(void) ap_copy_scoreboard_worker(worker_score *dest,
     /* For extra safety, NUL-terminate the strings returned, though it
      * should be true those last bytes are always zero anyway. */
     dest->client[sizeof(dest->client) - 1] = '\0';
+    dest->client64[sizeof(dest->client64) - 1] = '\0';
     dest->request[sizeof(dest->request) - 1] = '\0';
     dest->vhost[sizeof(dest->vhost) - 1] = '\0';
     dest->protocol[sizeof(dest->protocol) - 1] = '\0';