PeruserAttachments: httpd-2.2.3-peruser-0.3.0-dc3.patch

File httpd-2.2.3-peruser-0.3.0-dc3.patch, 43.1 KB (added by mephisto23, 3 years ago)
  • server/mpm/experimental/peruser/mpm_default.h

    old new  
    7777#define DEFAULT_MIN_FREE_PROCESSORS 2 
    7878#endif 
    7979 
     80/* Maximum --- more than this, and idle processors will be killed (0 = disable) */ 
     81 
     82#ifndef DEFAULT_MAX_FREE_PROCESSORS 
     83#define DEFAULT_MAX_FREE_PROCESSORS 0 
     84#endif 
     85 
    8086/* Maximum processors per ServerEnvironment */ 
    8187 
    8288#ifndef DEFAULT_MAX_PROCESSORS 
     
    107113#define DEFAULT_MAX_REQUESTS_PER_CHILD 10000 
    108114#endif 
    109115 
     116/* Maximum multiplexers */ 
     117 
     118#ifndef DEFAULT_MAX_MULTIPLEXERS 
     119#define DEFAULT_MAX_MULTIPLEXERS 20 
     120#endif 
     121 
     122/* Minimum multiplexers */ 
     123 
     124#ifndef DEFAULT_MIN_MULTIPLEXERS 
     125#define DEFAULT_MIN_MULTIPLEXERS 3 
     126#endif 
     127 
     128/* Amount of time a child can run before it expires (0 = turn off) */ 
     129 
     130#ifndef DEFAULT_EXPIRE_TIMEOUT 
     131#define DEFAULT_EXPIRE_TIMEOUT 1800 
     132#endif 
     133 
     134/* Amount of time a child can stay idle (0 = turn off) */ 
     135 
     136#ifndef DEFAULT_IDLE_TIMEOUT 
     137#define DEFAULT_IDLE_TIMEOUT 900 
     138#endif 
     139 
     140/* Amount of time a multiplexer can stay idle (0 = turn off) */ 
     141 
     142#ifndef DEFAULT_MULTIPLEXER_IDLE_TIMEOUT 
     143#define DEFAULT_MULTIPLEXER_IDLE_TIMEOUT 0 
     144#endif 
     145 
     146/* Amount of maximum time a multiplexer can wait for processor if it is busy (0 = never wait) 
     147 * This is decreased with every busy request 
     148 */ 
     149 
     150#ifndef DEFAULT_PROCESSOR_WAIT_TIMEOUT 
     151#define DEFAULT_PROCESSOR_WAIT_TIMEOUT 5 
     152#endif 
     153 
     154/* The number of different levels there are when a multiplexer is waiting for processor 
     155 * (between maximum waiting time and no waiting) 
     156 */ 
     157 
     158#ifndef DEFAULT_PROCESSOR_WAIT_STEPS 
     159#define DEFAULT_PROCESSOR_WAIT_STEPS 10 
     160#endif 
     161 
    110162#endif /* AP_MPM_DEFAULT_H */ 
  • server/mpm/experimental/peruser/mpm.h

    old new  
    8484#define AP_MPM_USES_POD 1 
    8585#define MPM_CHILD_PID(i) (ap_scoreboard_image->parent[i].pid) 
    8686#define MPM_NOTE_CHILD_KILLED(i) (MPM_CHILD_PID(i) = 0) 
     87#define MPM_VALID_PID(p) (getpgid(p) == getpgrp()) 
    8788#define MPM_ACCEPT_FUNC unixd_accept 
    8889 
    8990extern int ap_threads_per_child; 
  • server/mpm/experimental/peruser/peruser.c

    old new  
    195195 
    196196#define CHILD_STATUS_STANDBY  0  /* wait for a request before starting */ 
    197197#define CHILD_STATUS_STARTING 1  /* wait for socket creation */ 
    198 #define CHILD_STATUS_READY    2  /* wait for mux to restart */ 
    199 #define CHILD_STATUS_ACTIVE   3  /* ready to take requests */ 
     198#define CHILD_STATUS_READY    2  /* is ready to take requests */ 
     199#define CHILD_STATUS_ACTIVE   3  /* is currently busy handling requests */ 
    200200#define CHILD_STATUS_RESTART  4  /* child about to die and restart */ 
    201201 
     202/* cgroup settings */ 
     203#define CGROUP_TASKS_FILE "/tasks" 
     204#define CGROUP_TASKS_FILE_LEN 7 
     205 
    202206/* config globals */ 
    203207 
    204208int ap_threads_per_child=0;         /* Worker threads per child */ 
    205209static apr_proc_mutex_t *accept_mutex; 
    206210static int ap_min_processors=DEFAULT_MIN_PROCESSORS; 
    207211static int ap_min_free_processors=DEFAULT_MIN_FREE_PROCESSORS; 
     212static int ap_max_free_processors=DEFAULT_MAX_FREE_PROCESSORS; 
    208213static int ap_max_processors=DEFAULT_MAX_PROCESSORS; 
     214static int ap_min_multiplexers=DEFAULT_MIN_MULTIPLEXERS; 
     215static int ap_max_multiplexers=DEFAULT_MAX_MULTIPLEXERS; 
    209216static int ap_daemons_limit=0;      /* MaxClients */ 
    210 static int expire_timeout=1800; 
    211 static int idle_timeout=900; 
     217static int expire_timeout=DEFAULT_EXPIRE_TIMEOUT; 
     218static int idle_timeout=DEFAULT_IDLE_TIMEOUT; 
     219static int multiplexer_idle_timeout=DEFAULT_MULTIPLEXER_IDLE_TIMEOUT; 
     220static int processor_wait_timeout=DEFAULT_PROCESSOR_WAIT_TIMEOUT; 
     221static int processor_wait_steps=DEFAULT_PROCESSOR_WAIT_STEPS; 
    212222static int server_limit = DEFAULT_SERVER_LIMIT; 
    213223static int first_server_limit; 
    214224static int changed_limit_at_restart; 
     
    222232{ 
    223233    int processor_id; 
    224234 
     235    const char *name;   /* Server environment's unique string identifier */ 
     236 
    225237    /* security settings */ 
    226238    uid_t uid;          /* user id */ 
    227239    gid_t gid;          /* group id */ 
    228240    const char *chroot; /* directory to chroot() to, can be null */ 
     241    int nice_lvl; 
     242    const char *cgroup; /* cgroup directory, can be null */ 
    229243 
    230244    /* resource settings */ 
    231245    int min_processors; 
    232246    int min_free_processors; 
     247    int max_free_processors; 
    233248    int max_processors; 
     249    int availability; 
    234250 
    235251    /* sockets */ 
    236252    int input;          /* The socket descriptor */ 
     
    437453    return "UNKNOWN"; 
    438454} 
    439455 
     456char* scoreboard_status_string(int status) { 
     457    switch(status) 
     458    { 
     459        case SERVER_DEAD:  return "DEAD"; 
     460        case SERVER_STARTING: return "STARTING"; 
     461        case SERVER_READY:    return "READY"; 
     462        case SERVER_BUSY_READ:   return "BUSY_READ"; 
     463        case SERVER_BUSY_WRITE:   return "BUSY_WRITE"; 
     464        case SERVER_BUSY_KEEPALIVE:   return "BUSY_KEEPALIVE"; 
     465        case SERVER_BUSY_LOG:   return "BUSY_LOG"; 
     466        case SERVER_BUSY_DNS:   return "BUSY_DNS"; 
     467        case SERVER_CLOSING:   return "CLOSING"; 
     468        case SERVER_GRACEFUL:   return "GRACEFUL"; 
     469        case SERVER_NUM_STATUS:   return "NUM_STATUS"; 
     470    } 
     471 
     472    return "UNKNOWN"; 
     473} 
     474 
    440475void dump_child_table() 
    441476{ 
    442477#ifdef MPM_PERUSER_DEBUG 
     
    511546 
    512547static void accept_mutex_on(void) 
    513548{ 
    514 /* for some reason this fails if we listen on the pipe_of_death. 
    515    fortunately I don't think we currently need it */ 
    516  
    517 #if 0 
    518549    apr_status_t rv = apr_proc_mutex_lock(accept_mutex); 
    519550    if (rv != APR_SUCCESS) { 
    520551        const char *msg = "couldn't grab the accept mutex"; 
     
    529560            exit(APEXIT_CHILDFATAL); 
    530561        } 
    531562    } 
    532 #endif 
    533563} 
    534564 
    535565static void accept_mutex_off(void) 
    536566{ 
    537 #if 0 
    538567    apr_status_t rv = apr_proc_mutex_unlock(accept_mutex); 
    539568    if (rv != APR_SUCCESS) { 
    540569        const char *msg = "couldn't release the accept mutex"; 
     
    552581            exit(APEXIT_CHILDFATAL); 
    553582        } 
    554583    } 
    555 #endif 
    556584} 
    557585 
    558586/* On some architectures it's safe to do unserialized accept()s in the single 
     
    715743    ret = apr_socket_recv(lr->sd, &pipe_read_char, &n); 
    716744    if (APR_STATUS_IS_EAGAIN(ret)) 
    717745    { 
    718             /* It lost the lottery. It must continue to suffer 
    719              * through a life of servitude. */ 
     746       /* It lost the lottery. It must continue to suffer 
     747        * through a life of servitude. */ 
     748       _DBG("POD read EAGAIN"); 
     749       return ret; 
    720750    } 
    721751    else 
    722752    { 
     
    10871117    for(i = 0, total = 0; i < NUM_CHILDS; ++i) 
    10881118    { 
    10891119        if(CHILD_INFO_TABLE[i].senv == CHILD_INFO_TABLE[child_num].senv && 
    1090            (SCOREBOARD_STATUS(i) == SERVER_STARTING || 
    1091             SCOREBOARD_STATUS(i) == SERVER_READY)) 
     1120           (CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY)) 
    10921121        { 
    10931122            total++; 
    10941123        } 
     
    11161145    apr_bucket *bucket; 
    11171146    const apr_array_header_t *headers_in_array; 
    11181147    const apr_table_entry_t *headers_in; 
    1119     int counter; 
     1148    int counter, wait_time, wait_step_size; 
    11201149 
    11211150    apr_socket_t *thesock = ap_get_module_config(r->connection->conn_config, &core_module); 
    11221151 
     
    11371166      apr_table_get(r->headers_in, "Host"), my_child_num, processor->senv->output); 
    11381167    _DBG("r->the_request=\"%s\" len=%d", r->the_request, strlen(r->the_request)); 
    11391168 
    1140     ap_get_brigade(r->connection->input_filters, bb, AP_MODE_EXHAUSTIVE, APR_NONBLOCK_READ, len); 
     1169    wait_step_size = 100 / processor_wait_steps; 
    11411170 
    1142     /* Scan the brigade looking for heap-buckets */ 
     1171    /*  Check if the processor is available */ 
     1172    if (total_processors(processor->id) == processor->senv->max_processors && 
     1173        idle_processors(processor->id) == 0) { 
     1174        /* The processor is currently busy, try to wait (a little) */ 
     1175        _DBG("processor seems to be busy, trying to wait for it"); 
     1176 
     1177        if (processor->senv->availability == 0) { 
     1178            processor->senv->availability = 0; 
     1179 
     1180            _DBG("processor is very busy (availability = 0) - not passing request"); 
     1181 
     1182            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf, 
     1183                         "Too many requests for processor %s, increase MaxProcessors", processor->senv->name); 
     1184             
     1185            /* No point in waiting for the processor, it's very busy */ 
     1186            return -1; 
     1187        } 
     1188         
     1189        /* We sleep a little (depending how available the processor usually is) */ 
     1190        int i; 
     1191         
     1192        wait_time = (processor_wait_timeout / processor_wait_steps) * 1000000; 
     1193 
     1194        for(i = 0; i <= processor->senv->availability; i += wait_step_size) { 
     1195            usleep(wait_time); 
    11431196 
     1197            /* Check if the processor is ready */ 
     1198            if (total_processors(processor->id) < processor->senv->max_processors || 
     1199                idle_processors(processor->id) > 0) { 
     1200                /* The processor has freed - lets use it */ 
     1201                _DBG("processor freed before wait time expired"); 
     1202                break; 
     1203            } 
     1204        } 
     1205         
     1206        if (processor->senv->availability <= wait_step_size) { 
     1207            processor->senv->availability = 0; 
     1208        } 
     1209        else processor->senv->availability -= wait_step_size; 
     1210         
     1211        /* Check if we waited all the time */ 
     1212        if (i > processor->senv->availability) { 
     1213            _DBG("processor is busy - not passing request (availability = %d)", 
     1214                 processor->senv->availability); 
     1215            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, ap_server_conf, 
     1216                         "Too many requests for processor %s, increase MaxProcessors", processor->senv->name); 
     1217            return -1; 
     1218        } 
     1219 
     1220        /* We could increase the availability a little here, 
     1221         * because the processor got freed eventually 
     1222         */ 
     1223    } 
     1224    else { 
     1225        /* Smoothly increment the availability back to 100 */ 
     1226        if (processor->senv->availability >= 100-wait_step_size) { 
     1227            processor->senv->availability = 100; 
     1228        } 
     1229        else processor->senv->availability += wait_step_size; 
     1230    } 
     1231     
     1232    ap_get_brigade(r->connection->input_filters, bb, AP_MODE_EXHAUSTIVE, APR_NONBLOCK_READ, len); 
     1233     
     1234    /* Scan the brigade looking for heap-buckets */ 
     1235     
    11441236    _DBG("Scanning the brigade",0); 
    11451237    bucket = APR_BRIGADE_FIRST(bb); 
    11461238    while (bucket != APR_BRIGADE_SENTINEL(bb) && 
     
    12941386    /* -- receive data from socket -- */ 
    12951387    apr_os_sock_get(&ctrl_sock_fd, lr->sd); 
    12961388    _DBG("receiving from sock_fd=%d", ctrl_sock_fd); 
    1297     ret = recvmsg(ctrl_sock_fd, &msg, 0); 
    12981389 
    1299     if(ret == -1) 
    1300       _DBG("recvmsg failed with error \"%s\"", strerror(errno)); 
    1301     else 
    1302       _DBG("recvmsg returned %d", ret); 
     1390    // Don't block 
     1391    ret = recvmsg(ctrl_sock_fd, &msg, MSG_DONTWAIT); 
     1392 
     1393    if (ret == -1 && errno == EAGAIN) { 
     1394        _DBG("receive_from_multiplexer recvmsg() EAGAIN, someone was faster"); 
     1395         
     1396        return APR_EAGAIN; 
     1397    } 
     1398    else if (ret == -1) { 
     1399        _DBG("recvmsg failed with error \"%s\"", strerror(errno)); 
     1400         
     1401        // Error, better kill this child to be on the safe side 
     1402        return APR_EGENERAL; 
     1403    } 
     1404    else _DBG("recvmsg returned %d", ret); 
    13031405 
    13041406    /* -- extract socket from the cmsg -- */ 
    13051407    memcpy(&trans_sock_fd, CMSG_DATA(cmsg), sizeof(trans_sock_fd)); 
     
    13991501    return 0; 
    14001502} 
    14011503 
    1402 static int peruser_setup_child(int childnum) 
     1504static int peruser_setup_cgroup(int childnum, server_env_t *senv, apr_pool_t *pool) 
     1505{ 
     1506    apr_file_t *file; 
     1507    int length; 
     1508    apr_size_t content_len; 
     1509    char *tasks_file, *content, *pos; 
     1510 
     1511    _DBG("starting to add pid to cgroup %s", senv->cgroup); 
     1512 
     1513    length = strlen(senv->cgroup) + CGROUP_TASKS_FILE_LEN; 
     1514    tasks_file = malloc(length); 
     1515 
     1516    if (!tasks_file) return -1; 
     1517 
     1518    pos = apr_cpystrn(tasks_file, senv->cgroup, length); 
     1519    apr_cpystrn(pos, CGROUP_TASKS_FILE, CGROUP_TASKS_FILE_LEN); 
     1520 
     1521    /* Prepare the data to be written to tasks file */ 
     1522    content = apr_itoa(pool, ap_my_pid); 
     1523    content_len  = strlen(content); 
     1524 
     1525    _DBG("writing pid %s to tasks file %s", content, tasks_file); 
     1526 
     1527    if (apr_file_open(&file, tasks_file, APR_WRITE, APR_OS_DEFAULT, pool)) { 
     1528        ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL, 
     1529                     "cgroup: unable to open file %s", 
     1530                     tasks_file); 
     1531        free(tasks_file); 
     1532        return OK; /* don't fail if cgroup not available */ 
     1533    } 
     1534 
     1535    if (apr_file_write(file, content, &content_len)) { 
     1536        ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL, 
     1537                     "cgroup: unable to write pid to file %s", 
     1538                     tasks_file); 
     1539    } 
     1540 
     1541    apr_file_close(file); 
     1542 
     1543    free(tasks_file); 
     1544 
     1545    return OK; 
     1546} 
     1547 
     1548static int peruser_setup_child(int childnum, apr_pool_t *pool) 
    14031549{ 
    14041550    server_env_t *senv = CHILD_INFO_TABLE[childnum].senv; 
    14051551 
     1552    if (senv->nice_lvl != 0) { 
     1553        nice(senv->nice_lvl); 
     1554    } 
     1555 
    14061556    if(senv->chroot) { 
    14071557      _DBG("chdir to %s", senv->chroot); 
    14081558      if(chdir(senv->chroot)) { 
     
    14211571      } 
    14221572    } 
    14231573 
     1574    if(senv->cgroup) { 
     1575        peruser_setup_cgroup(childnum, senv, pool); 
     1576    } 
     1577 
    14241578    if (senv->uid == -1 && senv->gid == -1) { 
    14251579        return unixd_setup_child(); 
    14261580    } 
     
    15941748    { 
    15951749        case CHILD_TYPE_MULTIPLEXER: 
    15961750            _DBG("MULTIPLEXER %d", my_child_num); 
    1597  
    1598             /* update status on processors that are ready to accept requests */ 
    1599             _DBG("updating processor stati", 0); 
    1600             for(i = 0; i < NUM_CHILDS; ++i) 
    1601             { 
    1602                 if(CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY) 
    1603                     CHILD_INFO_TABLE[i].status = CHILD_STATUS_ACTIVE; 
    1604             } 
    1605  
    16061751            break; 
    16071752 
    16081753        case CHILD_TYPE_PROCESSOR: 
     
    16261771    apr_os_sock_put(&pod_sock, &fd, pconf); 
    16271772    listen_add(pconf, pod_sock, check_pipe_of_death); 
    16281773 
    1629     if(peruser_setup_child(my_child_num) != 0) 
     1774    if(peruser_setup_child(my_child_num, pchild) != 0) 
    16301775        clean_child_exit(APEXIT_CHILDFATAL); 
    16311776 
    16321777    ap_run_child_init(pchild, ap_server_conf); 
     
    16701815            clean_child_exit(0); 
    16711816        } 
    16721817 
    1673         (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL); 
     1818        (void) ap_update_child_status(sbh, SERVER_READY, (request_rec *) NULL); 
     1819 
     1820        CHILD_INFO_TABLE[my_child_num].status = CHILD_STATUS_READY; 
     1821        _DBG("Child %d (%s) is now ready", my_child_num, child_type_string(CHILD_INFO_TABLE[my_child_num].type)); 
    16741822 
    16751823        /* 
    16761824         * Wait for an acceptable connection to arrive. 
    16771825         */ 
    16781826 
    1679         /* Lock around "accept", if necessary */ 
    1680         SAFE_ACCEPT(accept_mutex_on()); 
     1827        /* Lock around "accept", if necessary */ 
     1828        if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) { 
     1829            SAFE_ACCEPT(accept_mutex_on()); 
     1830        } 
    16811831 
    16821832        if (num_listensocks == 1) { 
    16831833            offset = 0; 
     
    17291879         * defer the exit 
    17301880         */ 
    17311881        status = listensocks[offset].accept_func((void *)&sock, &listensocks[offset], ptrans); 
    1732         SAFE_ACCEPT(accept_mutex_off());        /* unlock after "accept" */ 
     1882 
     1883        if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) { 
     1884            SAFE_ACCEPT(accept_mutex_off());    /* unlock after "accept" */ 
     1885        } 
    17331886 
    17341887        if (status == APR_EGENERAL) { 
    17351888            /* resource shortage or should-not-occur occured */ 
    17361889            clean_child_exit(1); 
    17371890        } 
    1738         else if (status != APR_SUCCESS || die_now) { 
     1891        else if (status != APR_SUCCESS || die_now || sock == NULL) { 
    17391892            continue; 
    17401893        } 
    17411894 
     1895        if (CHILD_INFO_TABLE[my_child_num].status == CHILD_STATUS_READY) { 
     1896            CHILD_INFO_TABLE[my_child_num].status = CHILD_STATUS_ACTIVE; 
     1897            _DBG("Child %d (%s) is now active", my_child_num, child_type_string(CHILD_INFO_TABLE[my_child_num].type)); 
     1898        } 
     1899 
    17421900        if (CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_PROCESSOR || 
    1743             CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_WORKER) 
     1901            CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_WORKER || 
     1902            CHILD_INFO_TABLE[my_child_num].type == CHILD_TYPE_MULTIPLEXER) 
    17441903        { 
    17451904          _DBG("CHECKING IF WE SHOULD CLONE A CHILD..."); 
    17461905 
     
    17541913 
    17551914          if(total_processors(my_child_num) < 
    17561915              CHILD_INFO_TABLE[my_child_num].senv->max_processors && 
    1757             idle_processors(my_child_num) <= 
    1758               CHILD_INFO_TABLE[my_child_num].senv->min_free_processors) 
     1916            (idle_processors(my_child_num) <= 
     1917              CHILD_INFO_TABLE[my_child_num].senv->min_free_processors || 
     1918             total_processors(my_child_num) < 
     1919              CHILD_INFO_TABLE[my_child_num].senv->min_processors 
     1920            )) 
    17591921          { 
    17601922              _DBG("CLONING CHILD"); 
    17611923              child_clone(); 
     
    18041966    clean_child_exit(0); 
    18051967} 
    18061968 
    1807 static server_env_t* senv_add(int uid, int gid, const char* chroot) 
    1808 { 
     1969static server_env_t* find_senv_by_name(const char *name) { 
    18091970    int i; 
    1810     int socks[2]; 
    18111971 
    1812     _DBG("Searching for matching senv..."); 
     1972    if (name == NULL) return NULL; 
     1973 
     1974    _DBG("name=%s", name); 
     1975 
     1976    for(i = 0; i < NUM_SENV; i++) 
     1977      { 
     1978          if(SENV[i].name != NULL && !strcmp(SENV[i].name, name)) { 
     1979              return &SENV[i]; 
     1980          } 
     1981      } 
     1982 
     1983    return NULL; 
     1984} 
     1985 
     1986static server_env_t* find_matching_senv(server_env_t* senv) { 
     1987    int i; 
     1988 
     1989    _DBG("name=%s uid=%d gid=%d chroot=%s", senv->name, senv->uid, senv->gid, senv->chroot); 
    18131990 
    18141991    for(i = 0; i < NUM_SENV; i++) 
    1815     { 
    1816       if(SENV[i].uid == uid && SENV[i].gid == gid && 
    1817          (SENV[i].chroot == NULL || !strcmp(SENV[i].chroot, chroot))) 
    18181992      { 
    1819           _DBG("Found existing senv: %i", i); 
    1820           return &SENV[i]; 
     1993          if((senv->name != NULL && SENV[i].name != NULL && !strcmp(SENV[i].name, senv->name)) || 
     1994             (senv->name == NULL && SENV[i].uid == senv->uid && SENV[i].gid == senv->gid && 
     1995              ( 
     1996               (SENV[i].chroot == NULL && senv->chroot == NULL) || 
     1997               ((SENV[i].chroot != NULL || senv->chroot != NULL) && !strcmp(SENV[i].chroot, senv->chroot))) 
     1998              ) 
     1999             ) { 
     2000              return &SENV[i]; 
     2001          } 
    18212002      } 
     2003 
     2004    return NULL; 
     2005} 
     2006 
     2007static server_env_t* senv_add(server_env_t *senv) 
     2008{ 
     2009    int socks[2]; 
     2010    server_env_t *old_senv; 
     2011 
     2012    _DBG("Searching for matching senv..."); 
     2013 
     2014    old_senv = find_matching_senv(senv); 
     2015 
     2016    if (old_senv) { 
     2017        _DBG("Found existing senv"); 
     2018        senv = old_senv; 
     2019        return old_senv; 
    18222020    } 
    18232021 
    18242022    if(NUM_SENV >= server_limit) 
    1825     { 
    1826       _DBG("server_limit reached!"); 
    1827       return NULL; 
    1828     } 
     2023      { 
     2024          _DBG("server_limit reached!"); 
     2025          return NULL; 
     2026      } 
    18292027 
    18302028    _DBG("Creating new senv"); 
    18312029 
    1832     SENV[NUM_SENV].uid = uid; 
    1833     SENV[NUM_SENV].gid = gid; 
    1834     SENV[NUM_SENV].chroot = chroot; 
    1835  
    1836     SENV[NUM_SENV].min_processors = ap_min_processors; 
    1837     SENV[NUM_SENV].min_free_processors = ap_min_free_processors; 
    1838     SENV[NUM_SENV].max_processors = ap_max_processors; 
     2030    memcpy(&SENV[NUM_SENV], senv, sizeof(server_env_t)); 
     2031 
     2032    SENV[NUM_SENV].availability = 100; 
    18392033 
    18402034    socketpair(PF_UNIX, SOCK_STREAM, 0, socks); 
    18412035    SENV[NUM_SENV].input  = socks[0]; 
    18422036    SENV[NUM_SENV].output = socks[1]; 
    18432037 
     2038    senv = &SENV[NUM_SENV]; 
    18442039    return &SENV[server_env_image->control->num++]; 
    18452040} 
    18462041 
     2042 
    18472043static const char* child_clone() 
    18482044{ 
    18492045    int i; 
     
    18692065    new = &CHILD_INFO_TABLE[i]; 
    18702066 
    18712067    new->senv = this->senv; 
    1872     new->type = CHILD_TYPE_WORKER; 
     2068 
     2069    if (this->type == CHILD_TYPE_MULTIPLEXER) { 
     2070        new->type = CHILD_TYPE_MULTIPLEXER; 
     2071    } 
     2072    else { 
     2073        new->type = CHILD_TYPE_WORKER; 
     2074    } 
     2075 
    18732076    new->sock_fd = this->sock_fd; 
    18742077    new->status = CHILD_STATUS_STARTING; 
    18752078 
     
    18782081} 
    18792082 
    18802083static const char* child_add(int type, int status, 
    1881                              apr_pool_t *pool, uid_t uid, gid_t gid, const char* chroot) 
     2084                             apr_pool_t *pool, server_env_t *senv) 
    18822085{ 
    18832086    _DBG("adding child #%d", NUM_CHILDS); 
    18842087 
     
    18882091               "Increase NumServers in your config file."; 
    18892092    } 
    18902093 
    1891        if (chroot && !ap_is_directory(pool, chroot)) 
    1892                return apr_psprintf(pool, "Error: chroot directory [%s] does not exist", chroot); 
     2094       if (senv->chroot && !ap_is_directory(pool, senv->chroot)) 
     2095               return apr_psprintf(pool, "Error: chroot directory [%s] does not exist", senv->chroot); 
    18932096 
    1894     CHILD_INFO_TABLE[NUM_CHILDS].senv = senv_add(uid, gid, chroot); 
     2097    CHILD_INFO_TABLE[NUM_CHILDS].senv = senv_add(senv); 
    18952098 
    18962099    if(CHILD_INFO_TABLE[NUM_CHILDS].senv == NULL) 
    18972100    { 
     
    19072110    CHILD_INFO_TABLE[NUM_CHILDS].status = status; 
    19082111 
    19092112    _DBG("[%d] uid=%d gid=%d type=%d chroot=%s", 
    1910          NUM_CHILDS, uid, gid, type, 
    1911          chroot); 
     2113         NUM_CHILDS, senv->uid, senv->gid, type, 
     2114         senv->chroot); 
    19122115 
    1913     if (uid == 0 || gid == 0) 
     2116    if (senv->uid == 0 || senv->gid == 0) 
    19142117    { 
    19152118        _DBG("Assigning root user/group to a child.", 0); 
    19162119    } 
     
    19572160    (void) ap_update_child_status_from_indexes(slot, 0, SERVER_STARTING, 
    19582161                                               (request_rec *) NULL); 
    19592162 
    1960     CHILD_INFO_TABLE[slot].status = CHILD_STATUS_ACTIVE; 
     2163    CHILD_INFO_TABLE[slot].status = CHILD_STATUS_READY; 
    19612164 
    19622165 
    19632166#ifdef _OSD_POSIX 
     
    20622265        if(CHILD_INFO_TABLE[i].status == CHILD_STATUS_STARTING) 
    20632266          make_child(ap_server_conf, i); 
    20642267      } 
    2065       else if(((CHILD_INFO_TABLE[i].type == CHILD_TYPE_PROCESSOR ||  
    2066                CHILD_INFO_TABLE[i].type == CHILD_TYPE_WORKER)  && 
    2067                ap_scoreboard_image->parent[i].pid > 1) && 
    2068                (idle_processors (i) > 1 || total_processes (i) == 1) && ( 
    2069                    (expire_timeout > 0 &&  ap_scoreboard_image->servers[i][0].status != SERVER_DEAD &&  
    2070                    apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > expire_timeout) || 
    2071                    (idle_timeout >   0 &&  ap_scoreboard_image->servers[i][0].status == SERVER_READY &&   
    2072                    apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > idle_timeout))) 
     2268      else if( 
     2269              (((CHILD_INFO_TABLE[i].type == CHILD_TYPE_PROCESSOR || 
     2270                 CHILD_INFO_TABLE[i].type == CHILD_TYPE_WORKER)  && 
     2271                ap_scoreboard_image->parent[i].pid > 1) && 
     2272               (idle_processors (i) > CHILD_INFO_TABLE[i].senv->min_free_processors || CHILD_INFO_TABLE[i].senv->min_free_processors == 0) && 
     2273               total_processes (i) > CHILD_INFO_TABLE[i].senv->min_processors &&  
     2274               ( 
     2275                (expire_timeout > 0 &&  ap_scoreboard_image->servers[i][0].status != SERVER_DEAD &&  
     2276                 apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > expire_timeout) || 
     2277                (idle_timeout >   0 &&  ap_scoreboard_image->servers[i][0].status == SERVER_READY &&   
     2278                 apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > idle_timeout) || 
     2279                (CHILD_INFO_TABLE[i].senv->max_free_processors > 0 && CHILD_INFO_TABLE[i].status == CHILD_STATUS_READY && 
     2280                 idle_processors(i) > CHILD_INFO_TABLE[i].senv->max_free_processors)) 
     2281               ) 
     2282              || (CHILD_INFO_TABLE[i].type == CHILD_TYPE_MULTIPLEXER && 
     2283                  (multiplexer_idle_timeout > 0 && ap_scoreboard_image->servers[i][0].status == SERVER_READY && 
     2284                   apr_time_sec(now - ap_scoreboard_image->servers[i][0].last_used) > multiplexer_idle_timeout) && 
     2285                  total_processors(i) > CHILD_INFO_TABLE[i].senv->min_processors 
     2286                  ) 
     2287            ) 
    20732288      { 
    20742289        CHILD_INFO_TABLE[i].pid = 0; 
    20752290        CHILD_INFO_TABLE[i].status = CHILD_STATUS_STANDBY; 
    20762291 
    2077         if(CHILD_INFO_TABLE[i].type == CHILD_TYPE_WORKER) 
     2292        if(CHILD_INFO_TABLE[i].type == CHILD_TYPE_WORKER || CHILD_INFO_TABLE[i].type == CHILD_TYPE_MULTIPLEXER) 
    20782293        { 
    20792294          /* completely free up this slot */ 
    20802295 
     
    21732388        return 1; 
    21742389    } 
    21752390 
    2176 #if 0 
    21772391#if APR_USE_SYSVSEM_SERIALIZE 
    21782392    if (ap_accept_lock_mech == APR_LOCK_DEFAULT ||  
    21792393        ap_accept_lock_mech == APR_LOCK_SYSVSEM) { 
     
    21892403            return 1; 
    21902404        } 
    21912405    } 
    2192 #endif 
    21932406 
    21942407    if (!is_graceful) { 
    21952408        if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { 
     
    25982811    ap_listen_pre_config(); 
    25992812    ap_min_processors = DEFAULT_MIN_PROCESSORS; 
    26002813    ap_min_free_processors = DEFAULT_MIN_FREE_PROCESSORS; 
     2814    ap_max_free_processors = DEFAULT_MAX_FREE_PROCESSORS; 
    26012815    ap_max_processors = DEFAULT_MAX_PROCESSORS; 
     2816    ap_min_multiplexers = DEFAULT_MIN_MULTIPLEXERS; 
     2817    ap_max_multiplexers = DEFAULT_MAX_MULTIPLEXERS; 
    26022818    ap_daemons_limit = server_limit; 
    26032819    ap_pid_fname = DEFAULT_PIDLOG; 
    26042820    ap_lock_fname = DEFAULT_LOCKFILE; 
     
    26082824        ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED; 
    26092825#endif 
    26102826 
     2827    expire_timeout = DEFAULT_EXPIRE_TIMEOUT; 
     2828    idle_timeout = DEFAULT_IDLE_TIMEOUT; 
     2829    multiplexer_idle_timeout = DEFAULT_MULTIPLEXER_IDLE_TIMEOUT; 
     2830    processor_wait_timeout = DEFAULT_PROCESSOR_WAIT_TIMEOUT; 
     2831    processor_wait_steps = DEFAULT_PROCESSOR_WAIT_STEPS; 
     2832 
     2833 
    26112834    apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir)); 
    26122835 
    26132836    /* we need to know ServerLimit and ThreadLimit before we start processing 
     
    27092932        server_env_image->control = (server_env_control*)shmem; 
    27102933        shmem += sizeof(server_env_control*); 
    27112934        server_env_image->table = (server_env_t*)shmem; 
     2935    } 
    27122936 
     2937    if(restart_num <= 2) { 
     2938        _DBG("Cleaning server environments table"); 
     2939     
    27132940        server_env_image->control->num = 0; 
    2714  
    2715         for (i = 0; i < tmp_server_limit; i++) 
    2716         { 
     2941        for (i = 0; i < tmp_server_limit; i++) { 
    27172942            SENV[i].processor_id = -1; 
    27182943            SENV[i].uid          = -1; 
    27192944            SENV[i].gid          = -1; 
     
    27813006                if (pass_request(r, processor) == -1) 
    27823007                { 
    27833008                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, 
    2784                              ap_server_conf, "Could not pass request to proper "                             "child, request will not be honoured."); 
    2785                     return DECLINED; 
     3009                                 ap_server_conf, "Could not pass request to processor %s (virtualhost %s), request will not be honoured.", 
     3010                                 processor->senv->name, r->hostname); 
    27863011                } 
    27873012                _DBG("doing longjmp",0); 
    27883013                longjmp(CHILD_INFO_TABLE[my_child_num].jmpbuffer, 1); 
     
    28593084    ap_rputs("<hr>\n", r); 
    28603085    ap_rputs("<h2>peruser status</h2>\n", r); 
    28613086    ap_rputs("<table border=\"0\">\n", r); 
    2862     ap_rputs("<tr><td>ID</td><td>PID</td><td>STATUS</td><td>TYPE</td><td>UID</td>" 
    2863                    "<td>GID</td><td>CHROOT</td><td>INPUT</td>" 
     3087    ap_rputs("<tr><td>ID</td><td>PID</td><td>STATUS</td><td>SB STATUS</td><td>TYPE</td><td>UID</td>" 
     3088                   "<td>GID</td><td>CHROOT</td><td>NICE</td><td>INPUT</td>" 
    28643089                   "<td>OUTPUT</td><td>SOCK_FD</td>" 
    28653090                   "<td>TOTAL PROCESSORS</td><td>MAX PROCESSORS</td>" 
    2866                    "<td>IDLE PROCESSORS</td><td>MIN FREE PROCESSORS</td></tr>\n", r); 
     3091                   "<td>IDLE PROCESSORS</td><td>MIN FREE PROCESSORS</td>" 
     3092                   "<td>AVAIL</td>" 
     3093                   "</tr>\n", r); 
    28673094    for (x = 0; x < NUM_CHILDS; x++) 
    28683095        { 
    28693096        senv = CHILD_INFO_TABLE[x].senv; 
    2870         ap_rprintf(r, "<tr><td>%3d</td><td>%5d</td><td>%8s</td><td>%12s</td>" 
    2871                        "<td>%4d</td><td>%4d</td><td>%25s</td><td>%5d</td>" 
     3097        ap_rprintf(r, "<tr><td>%3d</td><td>%5d</td><td>%8s</td><td>%8s</td><td>%12s</td>" 
     3098                       "<td>%4d</td><td>%4d</td><td>%25s</td><td>%3d</td><td>%5d</td>" 
    28723099                       "<td>%6d</td><td>%7d</td><td>%d</td><td>%d</td>" 
    2873                        "<td>%d</td><td>%d</td></tr>\n",  
     3100                       "<td>%d</td><td>%d</td><td>%3d</td></tr>\n", 
    28743101                       CHILD_INFO_TABLE[x].id,  
    28753102                       CHILD_INFO_TABLE[x].pid,  
    28763103                       child_status_string(CHILD_INFO_TABLE[x].status),  
     3104                       scoreboard_status_string(SCOREBOARD_STATUS(x)), 
    28773105                       child_type_string(CHILD_INFO_TABLE[x].type),  
    28783106                       senv == NULL ? -1 : senv->uid,  
    28793107                       senv == NULL ? -1 : senv->gid,  
    28803108                       senv == NULL ? NULL : senv->chroot,  
     3109                       senv == NULL ? 0 : senv->nice_lvl, 
    28813110                       senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->input,  
    28823111                       senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->output,  
    28833112                       CHILD_INFO_TABLE[x].sock_fd, 
    28843113                       total_processors(x),  
    28853114                       senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->max_processors, 
    28863115                       idle_processors(x), 
    2887                        senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->min_free_processors 
     3116                       senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->min_free_processors, 
     3117                       senv == NULL ? -1 : CHILD_INFO_TABLE[x].senv->availability 
    28883118                       ); 
    28893119       } 
    28903120    ap_rputs("</table>\n", r); 
     
    29383168    APR_OPTIONAL_HOOK(ap, status_hook, peruser_status_hook, NULL, NULL, APR_HOOK_MIDDLE); 
    29393169} 
    29403170 
    2941 /* we define an Processor w/ specific uid/gid */ 
    2942 static const char *cf_Processor(cmd_parms *cmd, void *dummy, 
    2943     const char *user_name, const char *group_name, const char *chroot) 
     3171static const char *cf_Processor(cmd_parms *cmd, void *dummy, const char *arg) 
    29443172{ 
    2945     uid_t uid = ap_uname2id(user_name); 
    2946     gid_t gid = ap_gname2id(group_name); 
     3173    const char *user_name = NULL, *group_name = NULL, *directive; 
     3174    server_env_t senv; 
     3175    ap_directive_t *current; 
     3176 
     3177    const char *endp = ap_strrchr_c(arg, '>'); 
     3178 
     3179    if (endp == NULL) { 
     3180        return apr_psprintf(cmd->temp_pool, 
     3181                            "Error: Directive %s> missing closing '>'", cmd->cmd->name); 
     3182    } 
     3183 
     3184    arg = apr_pstrndup(cmd->pool, arg, endp - arg); 
     3185 
     3186    if (!arg) { 
     3187        return apr_psprintf(cmd->temp_pool, 
     3188                            "Error: %s> must specify a processor name", cmd->cmd->name); 
     3189    } 
     3190 
     3191    senv.name = ap_getword_conf(cmd->pool, &arg); 
     3192    _DBG("processor_name: %s", senv.name); 
     3193 
     3194    if (strlen(senv.name) == 0) { 
     3195        return apr_psprintf(cmd->temp_pool, 
     3196                            "Error: Directive %s> takes one argument", cmd->cmd->name); 
     3197    } 
     3198 
     3199    /*  Check for existing processors on first launch and between gracefuls */ 
     3200    if (restart_num == 1 || is_graceful) { 
     3201        server_env_t *old_senv = find_senv_by_name(senv.name); 
     3202 
     3203        if (old_senv) { 
     3204            return apr_psprintf(cmd->temp_pool, 
     3205                                "Error: Processor %s already defined", senv.name); 
     3206        } 
     3207    } 
     3208 
     3209    senv.nice_lvl               = 0; 
     3210    senv.chroot                 = NULL; 
     3211    senv.cgroup                 = NULL; 
     3212    senv.min_processors         = ap_min_processors; 
     3213    senv.min_free_processors    = ap_min_free_processors; 
     3214    senv.max_free_processors    = ap_max_free_processors; 
     3215    senv.max_processors         = ap_max_processors; 
     3216 
     3217    current = cmd->directive->first_child; 
     3218 
     3219    int proc_temp = 0; 
     3220    for(; current != NULL; current = current->next) { 
     3221        directive = current->directive; 
     3222         
     3223        if (!strcasecmp(directive, "user")) { 
     3224            user_name = current->args; 
     3225        } 
     3226        else if (!strcasecmp(directive, "group")) { 
     3227            group_name = current->args; 
     3228        } 
     3229        else if (!strcasecmp(directive, "chroot")) { 
     3230            senv.chroot = ap_getword_conf(cmd->pool, &current->args); 
     3231        } 
     3232        else if (!strcasecmp(directive, "nicelevel")) { 
     3233            senv.nice_lvl = atoi(current->args); 
     3234        } 
     3235        else if (!strcasecmp(directive, "maxprocessors")) { 
     3236            proc_temp = atoi(current->args); 
     3237 
     3238            if (proc_temp < 1) { 
     3239                ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3240                             "WARNING: Require MaxProcessors > 0, setting to 1"); 
     3241                proc_temp = 1; 
     3242            } 
     3243 
     3244            senv.max_processors = proc_temp; 
     3245        } 
     3246        else if (!strcasecmp(directive, "minprocessors")) { 
     3247            proc_temp = atoi(current->args); 
     3248 
     3249            if (proc_temp < 0) { 
     3250                ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3251                             "WARNING: Require MinProcessors >= 0, setting to 0"); 
     3252                proc_temp = 0; 
     3253            } 
     3254 
     3255            senv.min_processors = proc_temp; 
     3256        } 
     3257        else if (!strcasecmp(directive, "minspareprocessors")) { 
     3258            proc_temp = atoi(current->args); 
    29473259 
    2948     _DBG("user=%s:%d group=%s:%d chroot=%s", 
    2949         user_name, uid, group_name, gid, chroot); 
     3260            if (proc_temp < 0) { 
     3261                ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3262                             "WARNING: Require MinSpareProcessors >= 0, setting to 0"); 
     3263                proc_temp = 0; 
     3264            } 
     3265 
     3266            senv.min_free_processors = proc_temp; 
     3267        } 
     3268        else if (!strcasecmp(directive, "maxspareprocessors")) { 
     3269            proc_temp = atoi(current->args); 
     3270             
     3271            if (proc_temp < 0) { 
     3272                ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3273                             "WARNING: Require MaxSpareProcessors >= 0, setting to 0"); 
     3274                proc_temp = 0; 
     3275            } 
     3276 
     3277            senv.max_free_processors = proc_temp; 
     3278        } 
     3279        else if (!strcasecmp(directive, "cgroup")) { 
     3280            senv.cgroup = ap_getword_conf(cmd->pool, &current->args); 
     3281        } 
     3282        else { 
     3283            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3284                         "Unknown directive %s in %s>", directive, cmd->cmd->name); 
     3285        } 
     3286    } 
     3287 
     3288    if (user_name == NULL || group_name == NULL) { 
     3289        return apr_psprintf(cmd->temp_pool, 
     3290                            "Error: User or Group must be set in %s>", cmd->cmd->name); 
     3291    } 
     3292 
     3293    senv.uid = ap_uname2id(user_name); 
     3294    senv.gid = ap_gname2id(group_name); 
     3295 
     3296    _DBG("name=%s user=%s:%d group=%s:%d chroot=%s nice_lvl=%d", 
     3297         senv.name, user_name, senv.uid, group_name, senv.gid, senv.chroot, senv.nice_lvl); 
     3298 
     3299    _DBG("min_processors=%d min_free_processors=%d max_spare_processors=%d max_processors=%d", 
     3300         senv.min_processors, senv.min_free_processors, senv.max_free_processors, senv.max_processors); 
    29503301 
    29513302    return child_add(CHILD_TYPE_PROCESSOR, CHILD_STATUS_STANDBY, 
    2952                      cmd->pool, uid, gid, chroot); 
     3303                     cmd->pool, &senv); 
    29533304} 
    29543305 
    29553306/* we define an Multiplexer child w/ specific uid/gid */ 
    29563307static const char *cf_Multiplexer(cmd_parms *cmd, void *dummy, 
    29573308    const char *user_name, const char *group_name, const char *chroot) 
    29583309{ 
    2959     uid_t uid = ap_uname2id(user_name); 
    2960     gid_t gid = ap_gname2id(group_name); 
     3310    server_env_t senv; 
     3311 
     3312    senv.name           = NULL; 
     3313 
     3314    senv.uid            = ap_uname2id(user_name); 
     3315    senv.gid            = ap_gname2id(group_name); 
     3316    senv.nice_lvl       = 0; 
     3317    senv.cgroup         = NULL; 
     3318    senv.chroot         = chroot; 
     3319 
     3320    senv.min_processors         = ap_min_multiplexers; 
     3321    senv.min_free_processors    = ap_min_free_processors; 
     3322    senv.max_free_processors    = ap_max_free_processors; 
     3323    senv.max_processors         = ap_max_multiplexers; 
    29613324 
    29623325    _DBG("user=%s:%d group=%s:%d chroot=%s [multiplexer id %d]", 
    2963         user_name, uid, group_name, gid, chroot, NUM_CHILDS); 
     3326        user_name, senv.uid, group_name, senv.gid, senv.chroot, NUM_CHILDS); 
    29643327 
    29653328    return child_add(CHILD_TYPE_MULTIPLEXER, CHILD_STATUS_STARTING, 
    2966                      cmd->pool, uid, gid, chroot); 
     3329                     cmd->pool, &senv); 
    29673330} 
    29683331 
    29693332static const char* cf_ServerEnvironment(cmd_parms *cmd, void *dummy, 
    2970     const char *user_name, const char *group_name, const char *chroot) 
     3333    const char *name) 
    29713334{ 
    2972     int uid = ap_uname2id(user_name); 
    2973     int gid = ap_gname2id(group_name); 
    29743335    peruser_server_conf *sconf = PERUSER_SERVER_CONF(cmd->server->module_config); 
    29753336 
    29763337    _DBG("function entered", 0); 
    29773338 
    2978        if (chroot && !ap_is_directory(cmd->pool, chroot)) 
    2979                return apr_psprintf(cmd->pool, "Error: chroot directory [%s] does not exist", chroot); 
     3339    sconf->senv = find_senv_by_name(name); 
    29803340 
    2981     sconf->senv = senv_add(uid, gid, chroot); 
     3341    if (sconf->senv == NULL) { 
     3342        return apr_psprintf(cmd->pool, 
     3343                            "Error: Processor %s not defined", name); 
     3344    } 
    29823345 
    2983     _DBG("user=%s:%d group=%s:%d chroot=%s numchilds=%d", 
    2984         user_name, uid, group_name, gid, chroot, NUM_CHILDS); 
     3346    _DBG("user=%d group=%d chroot=%s numchilds=%d", 
     3347        sconf->senv->uid, sconf->senv->gid, sconf->senv->chroot, NUM_CHILDS); 
    29853348 
    29863349    return NULL; 
    29873350} 
     
    30463409 
    30473410    min_procs = atoi(arg); 
    30483411 
    3049     if (min_procs < 1) { 
     3412    if (min_procs < 0) { 
    30503413        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
    3051                      "WARNING: Require MaxProcessors > 0, setting to 1"); 
    3052         min_procs = 1; 
     3414                     "WARNING: Require MinProcessors >= 0, setting to 0"); 
     3415        min_procs = 0; 
    30533416    } 
    30543417 
    30553418    if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) { 
     
    30753438 
    30763439    min_free_procs = atoi(arg); 
    30773440 
    3078     if (min_free_procs < 1) { 
     3441    if (min_free_procs < 0) { 
    30793442        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
    3080                      "WARNING: Require MinSpareProcessors > 0, setting to 1"); 
    3081         min_free_procs = 1; 
     3443                     "WARNING: Require MinSpareProcessors >= 0, setting to 0"); 
     3444        min_free_procs = 0; 
    30823445    } 
    30833446 
    30843447    if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) { 
     
    30923455    return NULL; 
    30933456} 
    30943457 
     3458static const char *set_max_free_processors (cmd_parms *cmd, void *dummy, const char *arg) 
     3459{ 
     3460     peruser_server_conf *sconf; 
     3461     int max_free_procs; 
     3462     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); 
     3463 
     3464     if (err != NULL) { 
     3465         return err; 
     3466     } 
     3467 
     3468     max_free_procs = atoi(arg); 
     3469 
     3470     if (max_free_procs < 0) { 
     3471         ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3472                      "WARNING: Require MaxSpareProcessors >= 0, setting to 0"); 
     3473         max_free_procs = 0; 
     3474     } 
     3475 
     3476     if (ap_check_cmd_context(cmd, NOT_IN_VIRTUALHOST) != NULL) { 
     3477         sconf = PERUSER_SERVER_CONF(cmd->server->module_config); 
     3478         sconf->senv->max_free_processors = max_free_procs; 
     3479     } 
     3480     else { 
     3481         ap_max_free_processors = max_free_procs; 
     3482     } 
     3483 
     3484     return NULL; 
     3485} 
     3486 
    30953487static const char *set_max_processors (cmd_parms *cmd, void *dummy, const char *arg) 
    30963488{ 
    30973489    peruser_server_conf *sconf; 
     
    31213513    return NULL; 
    31223514} 
    31233515 
     3516static const char *set_min_multiplexers (cmd_parms *cmd, void *dummy, const char *arg) 
     3517{ 
     3518    int min_multiplexers; 
     3519    const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); 
     3520 
     3521    if (err != NULL) { 
     3522        return err; 
     3523    } 
     3524 
     3525    min_multiplexers = atoi(arg); 
     3526 
     3527    if (min_multiplexers < 1) { 
     3528        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3529                     "WARNING: Require MinMultiplexers > 0, setting to 1"); 
     3530        min_multiplexers = 1; 
     3531    } 
     3532 
     3533    ap_min_multiplexers = min_multiplexers; 
     3534 
     3535    return NULL; 
     3536} 
     3537 
     3538static const char *set_max_multiplexers (cmd_parms *cmd, void *dummy, const char *arg) 
     3539{ 
     3540    int max_multiplexers; 
     3541    const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); 
     3542 
     3543    if (err != NULL) { 
     3544        return err; 
     3545    } 
     3546 
     3547    max_multiplexers = atoi(arg); 
     3548 
     3549    if (max_multiplexers < 1) { 
     3550        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3551                     "WARNING: Require MaxMultiplexers > 0, setting to 1"); 
     3552        max_multiplexers = 1; 
     3553    } 
     3554 
     3555    ap_max_multiplexers = max_multiplexers; 
     3556 
     3557    return NULL; 
     3558} 
     3559 
    31243560static const char *set_server_limit (cmd_parms *cmd, void *dummy, const char *arg)  
    31253561{ 
    31263562    int tmp_server_limit; 
     
    31833619    return NULL; 
    31843620} 
    31853621 
     3622static const char *set_multiplexer_idle_timeout (cmd_parms *cmd, void *dummy, const char *arg) { 
     3623    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); 
     3624 
     3625    if (err != NULL) { 
     3626        return err; 
     3627    } 
     3628 
     3629    multiplexer_idle_timeout = atoi(arg); 
     3630 
     3631    return NULL; 
     3632} 
     3633 
     3634static const char *set_processor_wait_timeout (cmd_parms *cmd, void *dummy, const char *timeout, const char *steps) { 
     3635    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); 
     3636     
     3637    if (err != NULL) { 
     3638        return err; 
     3639    } 
     3640 
     3641    processor_wait_timeout = atoi(timeout); 
     3642 
     3643    if (steps != NULL) { 
     3644        int steps_tmp = atoi(steps); 
     3645 
     3646        if (steps_tmp < 1) { 
     3647            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, 
     3648                         "WARNING: Require ProcessorWaitTimeout steps > 0, setting to 1"); 
     3649            steps_tmp = 1; 
     3650        } 
     3651 
     3652        processor_wait_steps = steps_tmp; 
     3653    } 
     3654 
     3655    return NULL; 
     3656} 
     3657 
    31863658static const command_rec peruser_cmds[] = { 
    31873659UNIX_DAEMON_COMMANDS, 
    31883660LISTEN_COMMANDS, 
     
    31903662              "Minimum number of idle children, to handle request spikes"), 
    31913663AP_INIT_TAKE1("MinSpareServers", set_min_free_servers, NULL, RSRC_CONF, 
    31923664              "Minimum number of idle children, to handle request spikes"), 
     3665AP_INIT_TAKE1("MaxSpareProcessors", set_max_free_processors, NULL, RSRC_CONF, 
     3666              "Maximum number of idle children, 0 to disable"), 
    31933667AP_INIT_TAKE1("MaxClients", set_max_clients, NULL, RSRC_CONF, 
    31943668              "Maximum number of children alive at the same time"), 
    31953669AP_INIT_TAKE1("MinProcessors", set_min_processors, NULL, RSRC_CONF, 
    31963670              "Minimum number of processors per vhost"), 
    31973671AP_INIT_TAKE1("MaxProcessors", set_max_processors, NULL, RSRC_CONF, 
    31983672              "Maximum number of processors per vhost"), 
     3673AP_INIT_TAKE1("MinMultiplexers", set_min_multiplexers, NULL, RSRC_CONF, 
     3674              "Minimum number of multiplexers the server can have"), 
     3675AP_INIT_TAKE1("MaxMultiplexers", set_max_multiplexers, NULL, RSRC_CONF, 
     3676              "Maximum number of multiplexers the server can have"), 
    31993677AP_INIT_TAKE1("ServerLimit", set_server_limit, NULL, RSRC_CONF, 
    32003678              "Maximum value of MaxClients for this run of Apache"), 
    32013679AP_INIT_TAKE1("ExpireTimeout", set_expire_timeout, NULL, RSRC_CONF, 
    3202               "Maximum idle time before a child is killed, 0 to disable"), 
     3680              "Maximum time a child can live, 0 to disable"), 
    32033681AP_INIT_TAKE1("IdleTimeout", set_idle_timeout, NULL, RSRC_CONF, 
    32043682              "Maximum time before a child is killed after being idle, 0 to disable"), 
     3683AP_INIT_TAKE1("MultiplexerIdleTimeout", set_multiplexer_idle_timeout, NULL, RSRC_CONF, 
     3684              "Maximum time before a multiplexer is killed after being idle, 0 to disable"), 
     3685AP_INIT_TAKE12("ProcessorWaitTimeout", set_processor_wait_timeout, NULL, RSRC_CONF, 
     3686              "Maximum time a multiplexer waits for the processor if it is busy"), 
    32053687AP_INIT_TAKE23("Multiplexer", cf_Multiplexer, NULL, RSRC_CONF, 
    32063688              "Specify an Multiplexer Child configuration."), 
    3207 AP_INIT_TAKE23("Processor", cf_Processor, NULL, RSRC_CONF, 
    3208               "Specify a User and Group for a specific child process."), 
    3209 AP_INIT_TAKE23("ServerEnvironment", cf_ServerEnvironment, NULL, RSRC_CONF, 
     3689AP_INIT_RAW_ARGS("<Processor", cf_Processor, NULL, RSRC_CONF, 
     3690              "Specify settings for processor."), 
     3691AP_INIT_TAKE1("ServerEnvironment", cf_ServerEnvironment, NULL, RSRC_CONF, 
    32103692              "Specify the server environment for this virtual host."), 
    32113693{ NULL } 
    32123694};