/* Set up startup-time initialization */ static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data; const char *userdata_key = "llzr_init"; llzr_config *conf = ap_get_module_config(parms->server->module_config, &llzr_module); conf->redisconn = redisConnect(conf->redis_host, conf->redis_port); if (conf->redisconn == NULL || conf->redisconn->err) { if (conf->redisconn) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Redis error encountered %s", conf->redisconn->errstr); redisFree(c); } else { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, "Unable to connect to redis server"); } /* We don't want to kill our site if Redis goes down, but we would be susceptible to attack */ } apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key,apr_pool_cleanup_null, s->process->pool); return OK; } /* Lets get details from the MPM */ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, MODULE_NAME " " MODULE_VERSION " started"); ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit); return OK; }
AP_DECLARE(int) ap_find_child_by_pid(apr_proc_t *pid) { int i; int max_daemons_limit; ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit); /* * ********* begin amiya 20140223 ********* */ int running_max_daemons, sb_index; ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &running_max_daemons); sb_index = (max_daemons_limit > running_max_daemons) ? max_daemons_limit : running_max_daemons; /* * ********* end amiya ********** */ for (i = 0; i < sb_index/*max_daemons_limit*/; ++i) { if (ap_scoreboard_image->parent[i].pid == pid->pid) { return i; } } return -1; }
static int sb_get_idle_worker() { int i, j, res; worker_score *ws_record; process_score *ps_record; int idle = 0; #ifdef __APACHE24__ ap_generation_t ap_my_generation; ap_mpm_query(AP_MPMQ_GENERATION, &ap_my_generation); #endif ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &mruby_thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &mruby_server_limit); if (!ap_extended_status) return idle; for (i = 0; i < mruby_server_limit; ++i) { ps_record = ap_get_scoreboard_process(i); for (j = 0; j < mruby_thread_limit; ++j) { ws_record = ap_get_scoreboard_worker(i, j); res = ws_record->status; if (!ps_record->quiescing && ps_record->pid) { if (res == SERVER_READY && ps_record->generation == ap_my_generation) idle++; } } } return idle; }
AP_DECLARE(int) ap_calc_scoreboard_size(void) { ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit); scoreboard_size = sizeof(global_score); scoreboard_size += sizeof(process_score) * server_limit; scoreboard_size += sizeof(worker_score) * server_limit * thread_limit; pfn_ap_logio_get_last_bytes = APR_RETRIEVE_OPTIONAL_FN(ap_logio_get_last_bytes); return scoreboard_size; }
static void *ipblock_create_config(apr_pool_t *p, server_rec *s) { ipblock_config *cfg = (ipblock_config *) apr_pcalloc(p, sizeof(ipblock_config)); ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, MODULE_NAME " " MODULE_VERSION " started."); ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit); #else static void *ipblock_create_config(pool *p, server_rec *s) { ipblock_config *cfg = (ipblock_config *) ap_pcalloc(p, sizeof(ipblock_config)); #endif cfg->limit = 0; memset(&cfg->cmd, 0, MAX_CMD); return cfg; }
void ap_relieve_child_processes(void) { int i; extra_process_t *cur_extra; int max_daemons; ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &max_daemons); /* now see who is done */ for (i = 0; i < max_daemons; ++i) { pid_t pid = MPM_CHILD_PID(i); if (pid == 0) { continue; /* not every scoreboard entry is in use */ } if (reclaim_one_pid(pid, DO_NOTHING)) { MPM_NOTE_CHILD_KILLED(i); } } cur_extra = extras; while (cur_extra) { extra_process_t *next = cur_extra->next; if (reclaim_one_pid(cur_extra->pid, DO_NOTHING)) { AP_DEBUG_ASSERT(1 == ap_unregister_extra_mpm_process(cur_extra->pid)); } cur_extra = next; } }
apr_status_t h2_conn_run(struct h2_ctx *ctx, conn_rec *c) { apr_status_t status; int mpm_state = 0; do { if (c->cs) { c->cs->sense = CONN_SENSE_DEFAULT; } status = h2_session_process(h2_ctx_session_get(ctx), async_mpm); if (c->cs) { c->cs->state = CONN_STATE_WRITE_COMPLETION; } if (APR_STATUS_IS_EOF(status)) { ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, c, "h2_session(%ld): process, closing conn", c->id); c->keepalive = AP_CONN_CLOSE; } else { c->keepalive = AP_CONN_KEEPALIVE; } if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state)) { break; } } while (!async_mpm && c->keepalive == AP_CONN_KEEPALIVE && mpm_state != AP_MPMQ_STOPPING); return DONE; }
/*--------------------------------------------------------------------------*/ static int wd_pre_config_hook(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { apr_status_t rv; ap_watchdog_t *w; ap_mpm_query(AP_MPMQ_IS_FORKED, &mpm_is_forked); if ((rv = ap_watchdog_get_instance(&w, AP_WATCHDOG_SINGLETON, 0, 1, pconf)) != APR_SUCCESS) { return rv; } if ((rv = ap_watchdog_get_instance(&w, AP_WATCHDOG_DEFAULT, 0, 0, pconf)) != APR_SUCCESS) { return rv; } if (mpm_is_forked == AP_MPMQ_NOT_SUPPORTED) { /* Create parent process watchdog for * non forked mpm's only. */ if ((rv = ap_watchdog_get_instance(&w, AP_WATCHDOG_DEFAULT, 1, 0, pconf)) != APR_SUCCESS) { return rv; } } if ((rv = ap_mutex_register(pconf, wd_proc_mutex_type, NULL, APR_LOCK_DEFAULT, 0)) != APR_SUCCESS) { return rv; } return OK; }
static int update_child_status_internal(int child_num, int thread_num, int status, conn_rec *c, request_rec *r) { 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; 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; } if (ap_extended_status) { ws->last_used = apr_time_now(); if (status == SERVER_READY || status == SERVER_DEAD) { /* * Reset individual counters */ if (status == SERVER_DEAD) { ws->my_access_count = 0L; ws->my_bytes_served = 0L; } ws->conn_count = 0; ws->conn_bytes = 0; } if (r) { 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); if (r->server) { apr_snprintf(ws->vhost, sizeof(ws->vhost), "%s:%d", r->server->server_hostname, r->connection->local_addr->port); } } else if (c) { apr_cpystrn(ws->client, ap_get_remote_host(c, NULL, REMOTE_NOLOOKUP, NULL), sizeof(ws->client)); ws->request[0]='\0'; ws->vhost[0]='\0'; } } return old_status; }
/** * Configuration and start-up */ static int mem_cache_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { /* Sanity check the cache configuration */ if (sconf->min_cache_object_size >= sconf->max_cache_object_size) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "MCacheMaxObjectSize must be greater than MCacheMinObjectSize"); return DONE; } if (sconf->max_cache_object_size >= sconf->max_cache_size) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "MCacheSize must be greater than MCacheMaxObjectSize"); return DONE; } if (sconf->max_streaming_buffer_size > sconf->max_cache_object_size) { /* Issue a notice only if something other than the default config * is being used */ if (sconf->max_streaming_buffer_size != DEFAULT_MAX_STREAMING_BUFFER_SIZE && sconf->max_cache_object_size != DEFAULT_MAX_CACHE_OBJECT_SIZE) { ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, "MCacheMaxStreamingBuffer must be less than or equal to MCacheMaxObjectSize. " "Resetting MCacheMaxStreamingBuffer to MCacheMaxObjectSize."); } sconf->max_streaming_buffer_size = sconf->max_cache_object_size; } if (sconf->max_streaming_buffer_size < sconf->min_cache_object_size) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "MCacheMaxStreamingBuffer must be greater than or equal to MCacheMinObjectSize. " "Resetting MCacheMaxStreamingBuffer to MCacheMinObjectSize."); sconf->max_streaming_buffer_size = sconf->min_cache_object_size; } ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm); if (threaded_mpm) { apr_thread_mutex_create(&sconf->lock, APR_THREAD_MUTEX_DEFAULT, p); } sconf->cache_cache = cache_init(sconf->max_object_cnt, sconf->max_cache_size, memcache_get_priority, sconf->cache_remove_algorithm, memcache_get_pos, memcache_set_pos, memcache_inc_frequency, memcache_cache_get_size, memcache_cache_get_key, memcache_cache_free); apr_pool_cleanup_register(p, sconf, cleanup_cache_mem, apr_pool_cleanup_null); if (sconf->cache_cache) return OK; return -1; }
/* * Persist the slotmem in a file * slotmem name and file name. * none : no persistent data * rel_name : $server_root/rel_name * /abs_name : $abs_name * */ static int slotmem_filenames(apr_pool_t *pool, const char *slotname, const char **filename, const char **persistname) { const char *fname = NULL, *pname = NULL; if (slotname && *slotname && strcasecmp(slotname, "none") != 0) { if (slotname[0] != '/') { #if !SLOTMEM_UNLINK_SEMANTIC /* Each generation needs its own file name. */ int generation = 0; ap_mpm_query(AP_MPMQ_GENERATION, &generation); fname = apr_psprintf(pool, "%s%s_%x%s", DEFAULT_SLOTMEM_PREFIX, slotname, generation, DEFAULT_SLOTMEM_SUFFIX); #else /* Reuse the same file name for each generation. */ fname = apr_pstrcat(pool, DEFAULT_SLOTMEM_PREFIX, slotname, DEFAULT_SLOTMEM_SUFFIX, NULL); #endif fname = ap_runtime_dir_relative(pool, fname); } else { /* Don't mangle the file name if given an absolute path, it's * up to the caller to provide a unique name when necessary. */ fname = slotname; } if (persistname) { /* Persisted file names are immutable... */ #if !SLOTMEM_UNLINK_SEMANTIC if (slotname[0] != '/') { pname = apr_pstrcat(pool, DEFAULT_SLOTMEM_PREFIX, slotname, DEFAULT_SLOTMEM_SUFFIX, DEFAULT_SLOTMEM_PERSIST_SUFFIX, NULL); pname = ap_runtime_dir_relative(pool, pname); } else #endif pname = apr_pstrcat(pool, fname, DEFAULT_SLOTMEM_PERSIST_SUFFIX, NULL); } } *filename = fname; if (persistname) { *persistname = pname; } return (fname != NULL); }
static int http_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { apr_uint64_t val; if (ap_mpm_query(AP_MPMQ_IS_ASYNC, &async_mpm) != APR_SUCCESS) { async_mpm = 0; } ap_random_insecure_bytes(&val, sizeof(val)); ap_multipart_boundary = apr_psprintf(p, "%0" APR_UINT64_T_HEX_FMT, val); return OK; }
static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s) { int threaded; pchild = pool; #ifdef APR_HAS_THREADS ap_mpm_query(AP_MPMQ_IS_THREADED,&threaded); if(threaded) { apr_thread_mutex_create(&thread_mutex,APR_THREAD_MUTEX_DEFAULT,pool); } #endif }
AP_DECLARE(int) ap_calc_scoreboard_size(void) { ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit); if (!proxy_lb_workers) proxy_lb_workers = APR_RETRIEVE_OPTIONAL_FN(ap_proxy_lb_workers); if (proxy_lb_workers) lb_limit = proxy_lb_workers(); else lb_limit = 0; scoreboard_size = sizeof(global_score); scoreboard_size += sizeof(process_score) * server_limit; scoreboard_size += sizeof(worker_score) * server_limit * thread_limit; if (lb_limit) scoreboard_size += sizeof(lb_score) * lb_limit; return scoreboard_size; }
apr_status_t h2_conn_child_init(apr_pool_t *pool, server_rec *s) { apr_status_t status = APR_SUCCESS; int minw, maxw; int max_threads_per_child = 0; int idle_secs = 0; check_modules(1); ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads_per_child); status = ap_mpm_query(AP_MPMQ_IS_ASYNC, &async_mpm); if (status != APR_SUCCESS) { /* some MPMs do not implemnent this */ async_mpm = 0; status = APR_SUCCESS; } h2_config_init(pool); h2_get_num_workers(s, &minw, &maxw); idle_secs = h2_config_sgeti(s, H2_CONF_MAX_WORKER_IDLE_SECS); ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s, "h2_workers: min=%d max=%d, mthrpchild=%d, idle_secs=%d", minw, maxw, max_threads_per_child, idle_secs); workers = h2_workers_create(s, pool, minw, maxw, idle_secs); ap_register_input_filter("H2_IN", h2_filter_core_input, NULL, AP_FTYPE_CONNECTION); status = h2_mplx_child_init(pool, s); if (status == APR_SUCCESS) { status = apr_socket_create(&dummy_socket, APR_INET, SOCK_STREAM, APR_PROTO_TCP, pool); } return status; }
static PyObject *mpm_query(PyObject *self, PyObject *code) { int result; #if PY_MAJOR_VERSION < 3 if (! PyInt_Check(code)) { PyErr_SetString(PyExc_TypeError, "The argument must be an integer"); return NULL; } ap_mpm_query(PyInt_AsLong(code), &result); return PyInt_FromLong(result); #else if (! PyLong_Check(code)) { PyErr_SetString(PyExc_TypeError, "The argument must be an integer"); return NULL; } ap_mpm_query(PyLong_AsLong(code), &result); return PyLong_FromLong(result); #endif }
static void piped_log_maintenance(int reason, void *data, apr_wait_t status) { piped_log *pl = data; apr_status_t stats; int mpm_state; switch (reason) { case APR_OC_REASON_DEATH: case APR_OC_REASON_LOST: pl->pid = NULL; /* in case we don't get it going again, this * tells other logic not to try to kill it */ apr_proc_other_child_unregister(pl); stats = ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state); if (stats != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "can't query MPM state; not restarting " "piped log program '%s'", pl->program); } else if (mpm_state != AP_MPMQ_STOPPING) { ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "piped log program '%s' failed unexpectedly", pl->program); if ((stats = piped_log_spawn(pl)) != APR_SUCCESS) { /* what can we do? This could be the error log we're having * problems opening up... */ char buf[120]; ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "piped_log_maintenance: unable to respawn '%s': %s", pl->program, apr_strerror(stats, buf, sizeof(buf))); } } break; case APR_OC_REASON_UNWRITABLE: /* We should not kill off the pipe here, since it may only be full. * If it really is locked, we should kill it off manually. */ break; case APR_OC_REASON_RESTART: if (pl->pid != NULL) { apr_proc_kill(pl->pid, SIGTERM); pl->pid = NULL; } break; case APR_OC_REASON_UNREGISTER: break; } }
static apr_off_t sb_get_kbcount() { int i, j, res; unsigned long lres; apr_off_t bytes; apr_off_t bcount, kbcount; worker_score *ws_record; //process_score *ps_record; ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &mruby_thread_limit); ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &mruby_server_limit); bcount = 0; kbcount = 0; if (!ap_extended_status) return kbcount; for (i = 0; i < mruby_server_limit; ++i) { //ps_record = ap_get_scoreboard_process(i); for (j = 0; j < mruby_thread_limit; ++j) { ws_record = ap_get_scoreboard_worker(i, j); res = ws_record->status; lres = ws_record->access_count; bytes = ws_record->bytes_served; if (lres != 0 || (res != SERVER_READY && res != SERVER_DEAD)) { bcount += bytes; if (bcount >= KBYTE) { kbcount += (bcount >> 10); bcount = bcount & 0x3ff; } } }
apr_status_t h2_conn_run(conn_rec *c) { apr_status_t status; int mpm_state = 0; h2_session *session = h2_ctx_get_session(c); ap_assert(session); do { if (c->cs) { c->cs->sense = CONN_SENSE_DEFAULT; c->cs->state = CONN_STATE_HANDLER; } status = h2_session_process(session, async_mpm); if (APR_STATUS_IS_EOF(status)) { ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, c, H2_SSSN_LOG(APLOGNO(03045), session, "process, closing conn")); c->keepalive = AP_CONN_CLOSE; } else { c->keepalive = AP_CONN_KEEPALIVE; } if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state)) { break; } } while (!async_mpm && c->keepalive == AP_CONN_KEEPALIVE && mpm_state != AP_MPMQ_STOPPING); if (c->cs) { switch (session->state) { case H2_SESSION_ST_INIT: case H2_SESSION_ST_IDLE: case H2_SESSION_ST_BUSY: case H2_SESSION_ST_WAIT: c->cs->state = CONN_STATE_WRITE_COMPLETION; break; case H2_SESSION_ST_CLEANUP: case H2_SESSION_ST_DONE: default: c->cs->state = CONN_STATE_LINGER; break; } } return APR_SUCCESS; }
static PyObject *mpm_query(PyObject *self, PyObject *code) { int result; if (!PyInt_Check(code)) { PyErr_SetString(PyExc_TypeError, "The argument must be an integer"); return NULL; } ap_mpm_query(PyInt_AS_LONG(code), &result); return PyInt_FromLong(result); }
int find_child_by_pid(apr_proc_t *pid) { int i; int max_daemons_limit; ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_daemons_limit); for (i = 0; i < max_daemons_limit; ++i) { if (ap_scoreboard_image->parent[i].pid == pid->pid) { return i; } } return -1; }
static apr_status_t psgi_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { int argc = 2; char *argv[] = { "perl", "-e;0", NULL }; char **envp = NULL; PERL_SYS_INIT3(&argc, (char ***) argv, &envp); perlinterp = perl_alloc(); PL_perl_destruct_level = 1; perl_construct(perlinterp); perl_parse(perlinterp, xs_init, argc, argv, envp); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_run(perlinterp); init_perl_variables(); ap_mpm_query(AP_MPMQ_IS_THREADED, &psgi_multithread); psgi_multithread = (psgi_multithread != AP_MPMQ_NOT_SUPPORTED); ap_mpm_query(AP_MPMQ_IS_FORKED, &psgi_multiprocess); psgi_multiprocess = (psgi_multiprocess != AP_MPMQ_NOT_SUPPORTED); return OK; }
static int php_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { #ifndef ZTS int threaded_mpm; ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm); if(threaded_mpm) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, 0, "Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP."); return DONE; } #endif /* When this is NULL, apache won't override the hard-coded default * php.ini path setting. */ apache2_php_ini_path_override = NULL; return OK; }
static void create_shm(server_rec *s,apr_pool_t *p) { int threaded_mpm; ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded_mpm); //if (threaded_mpm) { tmpnam(lock_name); apr_global_mutex_create(&lock, lock_name, APR_THREAD_MUTEX_DEFAULT, p); //DEBUGLOG("threaded!"); // } size_t size; size = sizeof(client_list_t) + table_size * sizeof(client_t); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Create or Joining shmem. name: %s, size: %zd", shmname, size); if(lock) apr_global_mutex_lock(lock); apr_status_t rc = apr_shm_attach(&shm, shmname, p); if (APR_SUCCESS != rc) { DEBUGLOG("dosdetector: Creating shared memory"); apr_shm_remove(shmname, p); rc = apr_shm_create(&shm, size, shmname, p); if (APR_SUCCESS != rc) { ap_log_error(APLOG_MARK, APLOG_ERR, 0,0, "dosdetector: failed to create shared memory %s\n", shmname); //ap_log_error(APLOG_MARK, APLOG_ERR, 0,0, "dosdetector: %s:%d: failed to create shared memory %s\n", __FILE__, __LINE__, shmname); } else { client_list = apr_shm_baseaddr_get(shm); memset(client_list, 0, size); } } else { DEBUGLOG("dosdetector: Joining shared memory"); client_list = apr_shm_baseaddr_get(shm); } apr_shm_remove(shmname, p); // Just to set destroy flag. client_list->head = client_list->base; client_t *c = client_list->base; int i; for (i = 1; i < table_size; i++) { c->next = (c + 1); c++; } c->next = NULL; if (lock) apr_global_mutex_unlock(lock); }
/* Called my mod_log_config to initialise a log writer. */ static void *ap_rotated_log_writer_init(apr_pool_t *p, server_rec *s, const char* name) { rotated_log *rl; apr_status_t rv; log_options *ls = ap_get_module_config(s->module_config, &log_rotate_module); rl = apr_palloc(p, sizeof(rotated_log)); rl->fname = apr_pstrdup(p, name); if (rv = apr_pool_create(&rl->pool, p), APR_SUCCESS != rv) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "can't make log rotation pool."); return NULL; } rl->mutex.type = apr_anylock_none; #if APR_HAS_THREADS { int mpm_threads; ap_mpm_query(AP_MPMQ_MAX_THREADS, &mpm_threads); if (mpm_threads > 1) { apr_status_t rv; rl->mutex.type = apr_anylock_threadmutex; rv = apr_thread_mutex_create(&rl->mutex.lock.tm, APR_THREAD_MUTEX_DEFAULT, p); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, "could not initialize log rotation mutex, " "transfer log may become corrupted"); rl->mutex.type = apr_anylock_none; } } } #endif rl->st = *ls; rl->logtime = ap_get_quantized_time(rl, apr_time_now()); if (rl->fd = ap_open_log(rl->pool, s, rl->fname, &rl->st, rl->logtime), NULL == rl->fd) { return NULL; } return rl; }
static int privileges_init(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp) { /* refuse to work if the MPM is threaded */ int threaded; int rv = ap_mpm_query(AP_MPMQ_IS_THREADED, &threaded); if (rv != APR_SUCCESS) { ap_log_perror(APLOG_MARK, APLOG_NOTICE, rv, ptemp, APLOGNO(02153) "mod_privileges: unable to determine MPM characteristics." " Please ensure you are using a non-threaded MPM " "with this module."); } if (threaded) { ap_log_perror(APLOG_MARK, APLOG_CRIT, rv, ptemp, APLOGNO(02154) "mod_privileges is not compatible with a threaded MPM."); return !OK; } return OK; }
static void init_child(apr_pool_t *p, server_rec *s) { int mpm_threads; ap_mpm_query(AP_MPMQ_MAX_THREADS, &mpm_threads); /* Now register the last buffer flush with the cleanup engine */ if (buffered_logs) { int i; buffered_log **array = (buffered_log **)all_buffered_logs->elts; apr_pool_cleanup_register(p, s, flush_all_logs, flush_all_logs); for (i = 0; i < all_buffered_logs->nelts; i++) { buffered_log *this = array[i]; #if APR_HAS_THREADS if (mpm_threads > 1) { apr_status_t rv; this->mutex.type = apr_anylock_threadmutex; rv = apr_thread_mutex_create(&this->mutex.lock.tm, APR_THREAD_MUTEX_DEFAULT, p); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, "could not initialize buffered log mutex, " "transfer log may become corrupted"); this->mutex.type = apr_anylock_none; } } else #endif { this->mutex.type = apr_anylock_none; } } } }
AP_DECLARE(void) ap_relieve_child_processes(ap_reclaim_callback_fn_t *mpm_callback) { int i; extra_process_t *cur_extra; int max_daemons; ap_mpm_query(AP_MPMQ_MAX_DAEMON_USED, &max_daemons); /* now see who is done */ for (i = 0; i < max_daemons; ++i) { process_score *ps = ap_get_scoreboard_process(i); pid_t pid = ps->pid; if (pid == 0) { continue; /* not every scoreboard entry is in use */ } if (reclaim_one_pid(pid, DO_NOTHING)) { mpm_callback(i, 0, 0); } } cur_extra = extras; while (cur_extra) { ap_generation_t old_gen; extra_process_t *next = cur_extra->next; if (reclaim_one_pid(cur_extra->pid, DO_NOTHING)) { if (ap_unregister_extra_mpm_process(cur_extra->pid, &old_gen) == 1) { mpm_callback(-1, cur_extra->pid, old_gen); } else { AP_DEBUG_ASSERT(1 == 0); } } cur_extra = next; } }
void h2_config_init(apr_pool_t *pool) { /* Determine a good default for this platform and mpm? * TODO: not sure how APR wants to hand out this piece of * information. */ int max_files = 256; int conn_threads = 1; int tx_files = max_files / 4; (void)pool; ap_mpm_query(AP_MPMQ_MAX_THREADS, &conn_threads); switch (h2_conn_mpm_type()) { case H2_MPM_PREFORK: case H2_MPM_WORKER: case H2_MPM_EVENT: /* allow that many transfer open files per mplx */ files_per_session = (tx_files / conn_threads); break; default: /* don't know anything about it, stay safe */ break; } }
static int ap_process_http_sync_connection(conn_rec *c) { request_rec *r; conn_state_t *cs = c->cs; apr_socket_t *csd = NULL; int mpm_state = 0; /* * Read and process each request found on our connection * until no requests are left or we decide to close. */ ap_update_child_status_from_conn(c->sbh, SERVER_BUSY_READ, c); while ((r = ap_read_request(c)) != NULL) { c->keepalive = AP_CONN_UNKNOWN; /* process the request if it was read without error */ ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r); if (r->status == HTTP_OK) { if (cs) cs->state = CONN_STATE_HANDLER; ap_process_request(r); /* After the call to ap_process_request, the * request pool will have been deleted. We set * r=NULL here to ensure that any dereference * of r that might be added later in this function * will result in a segfault immediately instead * of nondeterministic failures later. */ r = NULL; } if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted) break; ap_update_child_status(c->sbh, SERVER_BUSY_KEEPALIVE, NULL); if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state)) { break; } if (mpm_state == AP_MPMQ_STOPPING) { break; } if (!csd) { csd = ap_get_conn_socket(c); } apr_socket_opt_set(csd, APR_INCOMPLETE_READ, 1); apr_socket_timeout_set(csd, c->base_server->keep_alive_timeout); /* Go straight to select() to wait for the next request */ /* * ******* begin amiya 20140224 ******** */ //ap_log_error(APLOG_MARK, APLOG_WARNING, 0, NULL, APLOGNO(0999) // "After processing request, setting kat: %d",apr_time_sec(c->base_server->keep_alive_timeout)); } return OK; }