int is_spawn_allowed()

in modules/fcgid/fcgid_spawn_ctl.c [158:225]


int is_spawn_allowed(server_rec * main_server, fcgid_command * command)
{
    struct fcgid_stat_node *current_node;
    fcgid_server_conf *sconf = ap_get_module_config(main_server->module_config,
                                                    &fcgid_module);

    if (!command || !g_stat_pool)
        return 1;

    /* Total process count higher than up limit? */
    if (g_total_process >= sconf->max_process_count) {
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server,
                     "mod_fcgid: %s total process count %d >= %d, skip the spawn request",
                     command->cgipath, g_total_process, sconf->max_process_count);
        return 0;
    }

    /* Can I find the node base on inode, device id and cmdline? */
    for (current_node = g_stat_list_header;
         current_node != NULL; current_node = current_node->next) {
        if (current_node->inode == command->inode
            && current_node->deviceid == command->deviceid
            && !strcmp(current_node->cmdline, command->cmdline)
            && current_node->vhost_id == command->vhost_id
            && current_node->uid == command->uid
            && current_node->gid == command->gid)
            break;
    }

    if (!current_node) {
        /* There are no existing processes for this class, so obviously
         * no class-specific limits have been exceeded.
         */
        return 1;
    }
    else {
        apr_time_t now = apr_time_now();

        current_node->score -=
          sconf->time_score *
          (int)(apr_time_sec(now) - apr_time_sec(current_node->last_stat_time));
        current_node->last_stat_time = now;
        if (current_node->score < 0)
            current_node->score = 0;

        /* Score is higher than up limit? */
        if (current_node->score >= sconf->spawnscore_uplimit) {
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server,
                         "mod_fcgid: %s spawn score %d >= %d, skip the spawn request",
                         command->cgipath, current_node->score,
                         sconf->spawnscore_uplimit);
            return 0;
        }

        /*
         * Process count of this class higher than up limit?
         */
        if (current_node->process_counter >= current_node->max_class_process_count) {
            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server,
                         "mod_fcgid: too many %s processes (current:%d, max:%d), skip the spawn request",
                         command->cgipath, current_node->process_counter,
                         current_node->max_class_process_count);
            return 0;
        }

        return 1;
    }
}