]> granicus.if.org Git - apache/blobdiff - server/scoreboard.c
Help doc writer to spot places where:
[apache] / server / scoreboard.c
index 4e79a1f714efa6c74293752eba2224f67c13429c..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)
@@ -488,6 +499,12 @@ 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;
@@ -500,19 +517,30 @@ static int update_child_status_internal(int child_num,
         else if (r) {
             copy_request(ws->request, sizeof(ws->request), r);
         }
+        else if (c) {
+            ws->request[0]='\0';
+        }
 
-        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));
+        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));
+            }
+            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));
+                                           REMOTE_NOLOOKUP, NULL))) {
+                apr_cpystrn(ws->client, c->client_ip, sizeof(ws->client)); /* DEPRECATE */
+                apr_cpystrn(ws->client64, c->client_ip, sizeof(ws->client64));
+            }
+            else {
+                apr_cpystrn(ws->client, val, sizeof(ws->client)); /* DEPRECATE */
+                apr_cpystrn(ws->client64, val, sizeof(ws->client64));
+            }
         }
 
         if (s) {
@@ -524,6 +552,9 @@ static int update_child_status_internal(int child_num,
                 apr_cpystrn(ws->vhost, s->server_hostname, sizeof(ws->vhost));
             }
         }
+        else if (c) {
+            ws->vhost[0]='\0';
+        }
 
         if (c) {
             val = ap_get_protocol(c);
@@ -609,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)
@@ -641,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';