github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/apache_2_2_34/include/scoreboard.h (about) 1 /* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * @file scoreboard.h 19 * @brief Apache scoreboard library 20 */ 21 22 #ifndef APACHE_SCOREBOARD_H 23 #define APACHE_SCOREBOARD_H 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 #ifdef HAVE_SYS_TIMES_H 30 #include <sys/time.h> 31 #include <sys/times.h> 32 #elif defined(TPF) 33 #include <time.h> 34 #endif 35 36 #include "ap_config.h" 37 #include "apr_hooks.h" 38 #include "apr_thread_proc.h" 39 #include "apr_portable.h" 40 #include "apr_shm.h" 41 #include "apr_optional.h" 42 43 /* Scoreboard file, if there is one */ 44 #ifndef DEFAULT_SCOREBOARD 45 #define DEFAULT_SCOREBOARD "logs/apache_runtime_status" 46 #endif 47 48 /* Scoreboard info on a process is, for now, kept very brief --- 49 * just status value and pid (the latter so that the caretaker process 50 * can properly update the scoreboard when a process dies). We may want 51 * to eventually add a separate set of long_score structures which would 52 * give, for each process, the number of requests serviced, and info on 53 * the current, or most recent, request. 54 * 55 * Status values: 56 */ 57 58 #define SERVER_DEAD 0 59 #define SERVER_STARTING 1 /* Server Starting up */ 60 #define SERVER_READY 2 /* Waiting for connection (or accept() lock) */ 61 #define SERVER_BUSY_READ 3 /* Reading a client request */ 62 #define SERVER_BUSY_WRITE 4 /* Processing a client request */ 63 #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */ 64 #define SERVER_BUSY_LOG 6 /* Logging the request */ 65 #define SERVER_BUSY_DNS 7 /* Looking up a hostname */ 66 #define SERVER_CLOSING 8 /* Closing the connection */ 67 #define SERVER_GRACEFUL 9 /* server is gracefully finishing request */ 68 #define SERVER_IDLE_KILL 10 /* Server is cleaning up idle children. */ 69 #define SERVER_NUM_STATUS 11 /* number of status settings */ 70 71 /* Type used for generation indicies. Startup and every restart cause a 72 * new generation of children to be spawned. Children within the same 73 * generation share the same configuration information -- pointers to stuff 74 * created at config time in the parent are valid across children. However, 75 * this can't work effectively with non-forked architectures. So while the 76 * arrays in the scoreboard never change between the parent and forked 77 * children, so they do not require shm storage, the contents of the shm 78 * may contain no pointers. 79 */ 80 typedef int ap_generation_t; 81 82 /* Is the scoreboard shared between processes or not? 83 * Set by the MPM when the scoreboard is created. 84 */ 85 typedef enum { 86 SB_NOT_SHARED = 1, 87 SB_SHARED = 2 88 } ap_scoreboard_e; 89 90 #define SB_WORKING 0 /* The server is busy and the child is useful. */ 91 #define SB_IDLE_DIE 1 /* The server is idle and the child is superfluous. */ 92 /* The child should check for this and exit gracefully. */ 93 94 /* stuff which is worker specific */ 95 /***********************WARNING***************************************/ 96 /* These are things that are used by mod_status. Do not put anything */ 97 /* in here that you cannot live without. This structure will not */ 98 /* be available if mod_status is not loaded. */ 99 /*********************************************************************/ 100 typedef struct worker_score worker_score; 101 102 struct worker_score { 103 int thread_num; 104 #if APR_HAS_THREADS 105 apr_os_thread_t tid; 106 #endif 107 /* With some MPMs (e.g., worker), a worker_score can represent 108 * a thread in a terminating process which is no longer 109 * represented by the corresponding process_score. These MPMs 110 * should set pid and generation fields in the worker_score. 111 */ 112 pid_t pid; 113 ap_generation_t generation; 114 unsigned char status; 115 unsigned long access_count; 116 apr_off_t bytes_served; 117 unsigned long my_access_count; 118 apr_off_t my_bytes_served; 119 apr_off_t conn_bytes; 120 unsigned short conn_count; 121 apr_time_t start_time; 122 apr_time_t stop_time; 123 #ifdef HAVE_TIMES 124 struct tms times; 125 #endif 126 apr_time_t last_used; 127 char client[32]; /* Keep 'em small... */ 128 char request[64]; /* We just want an idea... */ 129 char vhost[32]; /* What virtual host is being accessed? */ 130 }; 131 132 typedef struct { 133 int server_limit; 134 int thread_limit; 135 ap_scoreboard_e sb_type; 136 ap_generation_t running_generation; /* the generation of children which 137 * should still be serving requests. 138 */ 139 apr_time_t restart_time; 140 int lb_limit; 141 } global_score; 142 143 /* stuff which the parent generally writes and the children rarely read */ 144 typedef struct process_score process_score; 145 struct process_score{ 146 pid_t pid; 147 ap_generation_t generation; /* generation of this child */ 148 ap_scoreboard_e sb_type; 149 int quiescing; /* the process whose pid is stored above is 150 * going down gracefully 151 */ 152 }; 153 154 /* stuff which is lb specific */ 155 typedef struct lb_score lb_score; 156 struct lb_score{ 157 /* TODO: make a real stuct from this */ 158 unsigned char data[1024]; 159 }; 160 161 /* Scoreboard is now in 'local' memory, since it isn't updated once created, 162 * even in forked architectures. Child created-processes (non-fork) will 163 * set up these indicies into the (possibly relocated) shmem records. 164 */ 165 typedef struct { 166 global_score *global; 167 process_score *parent; 168 worker_score **servers; 169 lb_score *balancers; 170 } scoreboard; 171 172 typedef struct ap_sb_handle_t ap_sb_handle_t; 173 174 AP_DECLARE(int) ap_exists_scoreboard_image(void); 175 AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r); 176 177 int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t); 178 apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached); 179 void ap_init_scoreboard(void *shared_score); 180 AP_DECLARE(int) ap_calc_scoreboard_size(void); 181 apr_status_t ap_cleanup_scoreboard(void *d); 182 183 AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p, 184 int child_num, int thread_num); 185 186 int find_child_by_pid(apr_proc_t *pid); 187 AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r); 188 AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num, 189 int status, request_rec *r); 190 void ap_time_process_request(ap_sb_handle_t *sbh, int status); 191 192 /** Return a pointer to the worker_score for a given child, thread pair. 193 * @param child_num The child number. 194 * @param thread_num The thread number. 195 * @return A pointer to the worker_score structure. 196 * @deprecated This function is deprecated, use ap_copy_scoreboard_worker instead. 197 */ 198 AP_DECLARE(worker_score *) ap_get_scoreboard_worker(int x, int y); 199 200 /** Copy the contents of a worker's scoreboard entry. The contents of 201 * the worker_score structure are copied verbatim into the dest 202 * structure. 203 * @param dest Output parameter. 204 * @param child_num The child number. 205 * @param thread_num The thread number. 206 */ 207 AP_DECLARE(void) ap_copy_scoreboard_worker(worker_score *dest, 208 int child_num, int thread_num); 209 210 AP_DECLARE(process_score *) ap_get_scoreboard_process(int x); 211 AP_DECLARE(global_score *) ap_get_scoreboard_global(void); 212 AP_DECLARE(lb_score *) ap_get_scoreboard_lb(int lb_num); 213 214 AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image; 215 AP_DECLARE_DATA extern const char *ap_scoreboard_fname; 216 AP_DECLARE_DATA extern int ap_extended_status; 217 AP_DECLARE_DATA extern int ap_mod_status_reqtail; 218 219 AP_DECLARE_DATA extern ap_generation_t volatile ap_my_generation; 220 221 /* Hooks */ 222 /** 223 * Hook for post scoreboard creation, pre mpm. 224 * @param p Apache pool to allocate from. 225 * @param sb_type 226 * @ingroup hooks 227 * @return OK or DECLINE on success; anything else is a error 228 */ 229 AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type)) 230 231 /** 232 * proxy load balancer 233 * @return the number of load balancer workers. 234 */ 235 APR_DECLARE_OPTIONAL_FN(int, ap_proxy_lb_workers, 236 (void)); 237 238 /* for time_process_request() in http_main.c */ 239 #define START_PREQUEST 1 240 #define STOP_PREQUEST 2 241 242 #ifdef __cplusplus 243 } 244 #endif 245 246 #endif /* !APACHE_SCOREBOARD_H */