simple_run.c revision 6881fda812136efa364537ad49964b509a345bd2
af84459fbf938e508fd10b01cb8d699c79083813takashi/* Licensed to the Apache Software Foundation (ASF) under one or more
af84459fbf938e508fd10b01cb8d699c79083813takashi * contributor license agreements. See the NOTICE file distributed with
af84459fbf938e508fd10b01cb8d699c79083813takashi * this work for additional information regarding copyright ownership.
af84459fbf938e508fd10b01cb8d699c79083813takashi * The ASF licenses this file to You under the Apache License, Version 2.0
af84459fbf938e508fd10b01cb8d699c79083813takashi * (the "License"); you may not use this file except in compliance with
af84459fbf938e508fd10b01cb8d699c79083813takashi * the License. You may obtain a copy of the License at
af84459fbf938e508fd10b01cb8d699c79083813takashi *
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * http://www.apache.org/licenses/LICENSE-2.0
af84459fbf938e508fd10b01cb8d699c79083813takashi *
af84459fbf938e508fd10b01cb8d699c79083813takashi * Unless required by applicable law or agreed to in writing, software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distributed under the License is distributed on an "AS IS" BASIS,
2e545ce2450a9953665f701bb05350f0d3f26275nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
af84459fbf938e508fd10b01cb8d699c79083813takashi */
af84459fbf938e508fd10b01cb8d699c79083813takashi
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen/* #define APR_RING_DEBUG 1 */
3f08db06526d6901aa08c110b5bc7dde6bc39905nd
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "httpd.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "http_log.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "simple_types.h"
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#include "simple_event.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "simple_children.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "simple_run.h"
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung#include "simple_io.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "ap_mpm.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "scoreboard.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "ap_listen.h"
af84459fbf938e508fd10b01cb8d699c79083813takashi#include "simple_api.h"
3c13a815670b54d1c17bf02954f7d2b066cde95cnd#include "mpm.h"
3c13a815670b54d1c17bf02954f7d2b066cde95cnd
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen/**
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * Create Timers.
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic apr_status_t simple_main_setup_timers(simple_core_t * sc)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_register_timer(sc, simple_check_children_size, NULL, 0, sc->pool);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return APR_SUCCESS;
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe/**
af84459fbf938e508fd10b01cb8d699c79083813takashi * Create worker thread pool.
af84459fbf938e508fd10b01cb8d699c79083813takashi */
af84459fbf938e508fd10b01cb8d699c79083813takashistatic apr_status_t simple_setup_workers(simple_core_t * sc)
af84459fbf938e508fd10b01cb8d699c79083813takashi{
af84459fbf938e508fd10b01cb8d699c79083813takashi apr_status_t rv;
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi rv = apr_thread_pool_create(&sc->workers,
af84459fbf938e508fd10b01cb8d699c79083813takashi sc->procmgr.thread_count,
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen sc->procmgr.thread_count, sc->pool);
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi if (rv) {
af84459fbf938e508fd10b01cb8d699c79083813takashi ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_setup_workers: apr_thread_pool_create with %d threads failed",
af84459fbf938e508fd10b01cb8d699c79083813takashi sc->procmgr.thread_count);
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh return rv;
af84459fbf938e508fd10b01cb8d699c79083813takashi }
af84459fbf938e508fd10b01cb8d699c79083813takashi
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen return APR_SUCCESS;
af84459fbf938e508fd10b01cb8d699c79083813takashi}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic apr_status_t simple_setup_listeners(simple_core_t * sc)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_listen_rec *lr;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_status_t rv;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf for (lr = ap_listeners; lr != NULL; lr = lr->next) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_pollfd_t *pfd = apr_palloc(sc->pool, sizeof(apr_pollfd_t));
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_sb_t *sb = apr_pcalloc(sc->pool, sizeof(simple_sb_t));
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen pfd->p = sc->pool;
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin pfd->desc_type = APR_POLL_SOCKET;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe pfd->desc.s = lr->sd;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe pfd->reqevents = APR_POLLIN;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe sb->type = SIMPLE_PT_CORE_ACCEPT;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe sb->baton = lr;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe pfd->client_data = sb;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen rv = apr_socket_opt_set(pfd->desc.s, APR_SO_NONBLOCK, 1);
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen if (rv) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_setup_workers: apr_socket_opt_set(APR_SO_NONBLOCK = 1) failed on %pI",
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe lr->bind_addr);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return rv;
4bebf996eb7002ebfe897d46a0e0572390604a77nd }
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd rv = apr_pollcb_add(sc->pollcb, pfd);
4bebf996eb7002ebfe897d46a0e0572390604a77nd if (rv) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
4bebf996eb7002ebfe897d46a0e0572390604a77nd "simple_setup_workers: apr_pollcb_add failed on %pI",
9534272616b71aaea50aeec4162e749a96aebd7fsf lr->bind_addr);
4bebf996eb7002ebfe897d46a0e0572390604a77nd return rv;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
af84459fbf938e508fd10b01cb8d699c79083813takashi }
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashi return APR_SUCCESS;
af84459fbf938e508fd10b01cb8d699c79083813takashi}
af84459fbf938e508fd10b01cb8d699c79083813takashi
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowenstatic apr_status_t simple_io_callback(void *baton, apr_pollfd_t * pfd)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_status_t rv = APR_SUCCESS;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_core_t *sc = (simple_core_t *) baton;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_sb_t *sb = pfd->client_data;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen if (sb->type == SIMPLE_PT_CORE_ACCEPT) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe rv = simple_io_accept(sc, sb);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else if (sb->type == SIMPLE_PT_CORE_IO) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe rv = simple_io_event_process(sc, sb);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else if (sb->type == SIMPLE_PT_USER) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* TODO: */
57c845e03570b3641fbf41d4f139e2a9b49e406and abort();
57c845e03570b3641fbf41d4f139e2a9b49e406and }
57c845e03570b3641fbf41d4f139e2a9b49e406and else {
57c845e03570b3641fbf41d4f139e2a9b49e406and abort();
57c845e03570b3641fbf41d4f139e2a9b49e406and }
57c845e03570b3641fbf41d4f139e2a9b49e406and
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf return rv;
57c845e03570b3641fbf41d4f139e2a9b49e406and}
7e9d90004f580231e0376880710dc25408950ab9rbowen
7e9d90004f580231e0376880710dc25408950ab9rbowenstatic void *simple_timer_invoke(apr_thread_t * thread, void *baton)
7e9d90004f580231e0376880710dc25408950ab9rbowen{
7e9d90004f580231e0376880710dc25408950ab9rbowen simple_timer_t *ep = (simple_timer_t *) baton;
7e9d90004f580231e0376880710dc25408950ab9rbowen
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_timer_run(ep);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen#ifndef apr_time_from_msec
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define apr_time_from_msec(msec) ((apr_time_t)(msec) * 1000)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic int simple_run_loop(simple_core_t * sc)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_status_t rv;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_timer_t *ep = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe while (sc->mpm_state == AP_MPMQ_RUNNING) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_time_t tnow = apr_time_now();
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_timer_t *head;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_interval_time_t timeout = apr_time_from_msec(500);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_RING_HEAD(simple_temp_timer_ring_t, simple_timer_t) tmp_ring;
4aa603e6448b99f9371397d439795c91a93637eand
4aa603e6448b99f9371397d439795c91a93637eand apr_thread_mutex_lock(sc->mtx);
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh head = APR_RING_FIRST(&sc->timer_ring);
4aa603e6448b99f9371397d439795c91a93637eand
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh if (head != APR_RING_SENTINEL(&sc->timer_ring, simple_timer_t, link)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (tnow < head->expires) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe timeout = (head->expires - tnow);
4aa603e6448b99f9371397d439795c91a93637eand if (timeout > apr_time_from_msec(500)) {
4aa603e6448b99f9371397d439795c91a93637eand /* pqXXXXX: I'm 95% sure that the Linux Powertop guys will slap me for this. */
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh timeout = apr_time_from_msec(500);
4aa603e6448b99f9371397d439795c91a93637eand }
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else {
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd /* We have already expired timers in the queue. */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe timeout = 0;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
4aa603e6448b99f9371397d439795c91a93637eand }
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh apr_thread_mutex_unlock(sc->mtx);
4aa603e6448b99f9371397d439795c91a93637eand
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh rv = apr_pollcb_poll(sc->pollcb, timeout, simple_io_callback, sc);
4aa603e6448b99f9371397d439795c91a93637eand
888cb40bdeec5abf452bd85d6bf63b26d5913d4chumbedooh tnow = apr_time_now();
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
af84459fbf938e508fd10b01cb8d699c79083813takashi if (rv) {
af84459fbf938e508fd10b01cb8d699c79083813takashi if (!APR_STATUS_IS_EINTR(rv) && !APR_STATUS_IS_TIMEUP(rv)) {
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen "simple_main_loop: apr_pollcb_poll failed");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return !OK;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_RING_INIT(&tmp_ring, simple_timer_t, link);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
c8c717fafa0a09ed13469a603a178921b851dd22igalic apr_thread_mutex_lock(sc->mtx);
c8c717fafa0a09ed13469a603a178921b851dd22igalic
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic /* now iterate any timers */
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic if (!APR_RING_EMPTY(&sc->timer_ring, simple_timer_t, link)) {
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic for (ep = APR_RING_FIRST(&sc->timer_ring);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic ep != APR_RING_SENTINEL(&sc->timer_ring,
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic simple_timer_t, link);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic ep = APR_RING_NEXT(ep, link)) {
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic if (ep->expires < tnow) {
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor simple_timer_t *next = APR_RING_PREV(ep, link);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* push this task */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_RING_REMOVE(ep, link);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_RING_CHECK_CONSISTENCY(&sc->timer_ring,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_timer_t, link);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_RING_INSERT_TAIL(&tmp_ring, ep, simple_timer_t, link);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ep = next;
acf65805923cf80834c39689cc0e2a8e7201c186sf }
acf65805923cf80834c39689cc0e2a8e7201c186sf else {
acf65805923cf80834c39689cc0e2a8e7201c186sf break;
c8c717fafa0a09ed13469a603a178921b851dd22igalic }
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor }
4bebf996eb7002ebfe897d46a0e0572390604a77nd }
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd APR_RING_CHECK_CONSISTENCY(&sc->timer_ring, simple_timer_t, link);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf apr_thread_mutex_unlock(sc->mtx);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (!APR_RING_EMPTY(&tmp_ring, simple_timer_t, link)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe for (ep = APR_RING_FIRST(&tmp_ring);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ep != APR_RING_SENTINEL(&tmp_ring,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_timer_t, link);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ep = APR_RING_NEXT(ep, link)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_thread_pool_push(sc->workers,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe simple_timer_invoke,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ep,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_THREAD_TASK_PRIORITY_NORMAL, NULL);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return 0;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
8559a67073808d84d85bb5dd552d4247caafe709sf
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowenvoid simple_single_process_hack(simple_core_t * sc)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe apr_status_t rv;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* Normally this is only ran in the child processes, but we want to do it here too... */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe rv = simple_setup_listeners(sc);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (rv) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_single_child_hack: simple_setup_listeners failed");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
253547fb9cc7986e84ff68aef076f664fc4169dctakashi}
253547fb9cc7986e84ff68aef076f664fc4169dctakashi
253547fb9cc7986e84ff68aef076f664fc4169dctakashistatic int simple_setup_privs(simple_core_t * sc)
253547fb9cc7986e84ff68aef076f664fc4169dctakashi{
253547fb9cc7986e84ff68aef076f664fc4169dctakashi int rv = ap_run_simple_drop_privileges(sc->pool, ap_server_conf);
253547fb9cc7986e84ff68aef076f664fc4169dctakashi
8559a67073808d84d85bb5dd552d4247caafe709sf if (rv) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_setup_privs: ap_run_simple_drop_privileges failed");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return rv;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
c8c717fafa0a09ed13469a603a178921b851dd22igalic
c8c717fafa0a09ed13469a603a178921b851dd22igalic return 0;
8559a67073808d84d85bb5dd552d4247caafe709sf}
c8c717fafa0a09ed13469a603a178921b851dd22igalic
c8c717fafa0a09ed13469a603a178921b851dd22igalicstatic int simple_setup_pollcb(simple_core_t * sc)
c8c717fafa0a09ed13469a603a178921b851dd22igalic{
8559a67073808d84d85bb5dd552d4247caafe709sf apr_status_t rv;
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf rv = apr_pollcb_create(&sc->pollcb, 512 /* pqXXXXX: make configrable */ ,
8559a67073808d84d85bb5dd552d4247caafe709sf sc->pool, 0);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf if (rv) {
8559a67073808d84d85bb5dd552d4247caafe709sf ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
8559a67073808d84d85bb5dd552d4247caafe709sf "simple_core_init: apr_pollcb_create failed.");
8559a67073808d84d85bb5dd552d4247caafe709sf return rv;
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf return rv;
8559a67073808d84d85bb5dd552d4247caafe709sf}
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfint simple_child_loop(simple_core_t * sc)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf apr_status_t rv;
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf rv = simple_setup_pollcb(sc);
8559a67073808d84d85bb5dd552d4247caafe709sf if (rv) {
8559a67073808d84d85bb5dd552d4247caafe709sf return rv;
a55680cd56cecad4f2d7d41b576aa63f0e008916rjung }
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf /* XXXXX: Hack. Reseting parts of the simple core needs to be more
8559a67073808d84d85bb5dd552d4247caafe709sf * thought out than this.
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf */
4bebf996eb7002ebfe897d46a0e0572390604a77nd APR_RING_INIT(&sc->timer_ring, simple_timer_t, link);
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd rv = simple_setup_workers(sc);
4bebf996eb7002ebfe897d46a0e0572390604a77nd if (rv) {
4bebf996eb7002ebfe897d46a0e0572390604a77nd ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
4bebf996eb7002ebfe897d46a0e0572390604a77nd "simple_child_loop: simple_setup_workers failed");
4bebf996eb7002ebfe897d46a0e0572390604a77nd return !OK;
4bebf996eb7002ebfe897d46a0e0572390604a77nd }
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd rv = simple_setup_listeners(sc);
4bebf996eb7002ebfe897d46a0e0572390604a77nd if (rv) {
4bebf996eb7002ebfe897d46a0e0572390604a77nd ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
65a611af7093423efb91e5794b8887a527d4cf63trawick "simple_child_loop: simple_setup_sockets failed");
65a611af7093423efb91e5794b8887a527d4cf63trawick return !OK;
65a611af7093423efb91e5794b8887a527d4cf63trawick }
65a611af7093423efb91e5794b8887a527d4cf63trawick
65a611af7093423efb91e5794b8887a527d4cf63trawick rv = simple_setup_privs(sc);
253547fb9cc7986e84ff68aef076f664fc4169dctakashi if (rv) {
253547fb9cc7986e84ff68aef076f664fc4169dctakashi ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
253547fb9cc7986e84ff68aef076f664fc4169dctakashi "simple_child_loop: simple_drop_privs failed");
253547fb9cc7986e84ff68aef076f664fc4169dctakashi return !OK;
253547fb9cc7986e84ff68aef076f664fc4169dctakashi }
253547fb9cc7986e84ff68aef076f664fc4169dctakashi
253547fb9cc7986e84ff68aef076f664fc4169dctakashi ap_run_child_init(sc->pool, ap_server_conf);
253547fb9cc7986e84ff68aef076f664fc4169dctakashi
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return simple_run_loop(sc);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
af84459fbf938e508fd10b01cb8d699c79083813takashi
af84459fbf938e508fd10b01cb8d699c79083813takashiint simple_main_loop(simple_core_t * sc)
af84459fbf938e508fd10b01cb8d699c79083813takashi{
af84459fbf938e508fd10b01cb8d699c79083813takashi apr_status_t rv;
af84459fbf938e508fd10b01cb8d699c79083813takashi
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe rv = simple_setup_pollcb(sc);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (rv) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return rv;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic rv = simple_setup_workers(sc);
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic if (rv) {
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
9534272616b71aaea50aeec4162e749a96aebd7fsf "simple_main_loop: simple_setup_workers failed");
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic return !OK;
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic }
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic rv = simple_main_setup_timers(sc);
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic if (rv) {
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "simple_main_loop: simple_setup_timers failed");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return !OK;
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen }
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen return simple_run_loop(sc);
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen}
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen