⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 beos.c

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 C
📖 第 1 页 / 共 3 页
字号:
}/* This is called to not only setup and run for the initial time, but also * when we've asked for a restart. This means it must be able to handle both * situations. It also means that when we exit here we should have tidied * up after ourselves fully. */int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s){    int remaining_threads_to_start, i,j;    apr_status_t rv;    ap_listen_rec *lr;    pconf = _pconf;    ap_server_conf = s;    /* Increase the available pool of fd's.  This code from     * Joe Kloss <joek@be.com>     */    if( FD_SETSIZE > 128 && (i = _kset_fd_limit_( 128 )) < 0 ){        ap_log_error(APLOG_MARK, APLOG_ERR, i, s,            "could not set FD_SETSIZE (_kset_fd_limit_ failed)");    }    /* BeOS R5 doesn't support pipes on select() calls, so we use a     * UDP socket as these are supported in both R5 and BONE.  If we only cared     * about BONE we'd use a pipe, but there it is.     * As we have UDP support in APR, now use the APR functions and check all the     * return values...     */    if (apr_sockaddr_info_get(&udp_sa, "127.0.0.1", APR_UNSPEC, 7772, 0, _pconf)        != APR_SUCCESS){        ap_log_error(APLOG_MARK, APLOG_ALERT, errno, s,            "couldn't create control socket information, shutting down");        return 1;    }    if (apr_socket_create(&udp_sock, udp_sa->family, SOCK_DGRAM, 0,                      _pconf) != APR_SUCCESS){        ap_log_error(APLOG_MARK, APLOG_ALERT, errno, s,            "couldn't create control socket, shutting down");        return 1;    }    if (apr_socket_bind(udp_sock, udp_sa) != APR_SUCCESS){        ap_log_error(APLOG_MARK, APLOG_ALERT, errno, s,            "couldn't bind UDP socket!");        return 1;    }    if ((num_listening_sockets = ap_setup_listeners(ap_server_conf)) < 1) {        ap_log_error(APLOG_MARK, APLOG_ALERT, 0, s,            "no listening sockets available, shutting down");        return 1;    }    ap_log_pid(pconf, ap_pid_fname);    /*     * Create our locks...     */    /* accept_mutex     * used to lock around select so we only have one thread     * in select at a time     */    rv = apr_thread_mutex_create(&accept_mutex, 0, pconf);    if (rv != APR_SUCCESS) {        /* tsch tsch, can't have more than one thread in the accept loop           at a time so we need to fall on our sword... */        ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,                     "Couldn't create accept lock");        return 1;    }    /*     * Startup/shutdown...     */    if (!is_graceful) {        /* setup the scoreboard shared memory */        if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {            return 1;        }        for (i = 0; i < HARD_SERVER_LIMIT; i++) {            ap_scoreboard_image->parent[i].pid = 0;            for (j = 0;j < HARD_THREAD_LIMIT; j++)                ap_scoreboard_image->servers[i][j].tid = 0;        }    }    if (HARD_SERVER_LIMIT == 1)        ap_scoreboard_image->parent[0].pid = getpid();    set_signals();    /* Sanity checks to avoid thrashing... */    if (max_spare_threads < min_spare_threads )        max_spare_threads = min_spare_threads;    /* If we're doing a graceful_restart then we're going to see a lot     * of threads exiting immediately when we get into the main loop     * below (because we just sent them AP_SIG_GRACEFUL).  This happens     * pretty rapidly... and for each one that exits we'll start a new one     * until we reach at least threads_min_free.  But we may be permitted to     * start more than that, so we'll just keep track of how many we're     * supposed to start up without the 1 second penalty between each fork.     */    remaining_threads_to_start = ap_threads_to_start;    /* sanity check on the number to start... */    if (remaining_threads_to_start > ap_thread_limit) {            remaining_threads_to_start = ap_thread_limit;    }    /* If we're doing the single process thing or we're in a graceful_restart     * then we don't start threads here.     * if we're in one_process mode we don't want to start threads     * do we??     */    if (!is_graceful && !one_process) {            startup_threads(remaining_threads_to_start);            remaining_threads_to_start = 0;    } else {            /* give the system some time to recover before kicking into             * exponential mode */        hold_off_on_exponential_spawning = 10;    }    /*     * record that we've entered the world !     */    ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,                "%s configured -- resuming normal operations",                ap_get_server_description());    ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,                "Server built: %s", ap_get_server_built());    restart_pending = shutdown_pending = 0;    mpm_state = AP_MPMQ_RUNNING;    /* We sit in the server_main_loop() until we somehow manage to exit. When     * we do, we need to kill the workers we have, so we start by using the     * tell_workers_to_exit() function, but as it sometimes takes a short while     * to accomplish this we have a pause builtin to allow them the chance to     * gracefully exit.     */    if (!one_process) {        server_main_loop(remaining_threads_to_start);        tell_workers_to_exit();        snooze(1000000);    } else {        worker_thread((void*)0);    }    mpm_state = AP_MPMQ_STOPPING;    /* close the UDP socket we've been using... */    apr_socket_close(udp_sock);    if ((one_process || shutdown_pending) && !child_fatal) {        const char *pidfile = NULL;        pidfile = ap_server_root_relative (pconf, ap_pid_fname);        if ( pidfile != NULL && unlink(pidfile) == 0)            ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,                         "removed PID file %s (pid=%ld)", pidfile,                         (long)getpid());    }    if (one_process) {        return 1;    }    /*     * If we get here we're shutting down...     */    if (shutdown_pending) {        /* Time to gracefully shut down:         * Kill child processes, tell them to call child_exit, etc...         */        if (beosd_killpg(getpgrp(), SIGTERM) < 0)            ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf,             "killpg SIGTERM");        /* use ap_reclaim_child_processes starting with SIGTERM */        ap_reclaim_child_processes(1);        if (!child_fatal) {         /* already recorded */            /* record the shutdown in the log */            ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,                         "caught SIGTERM, shutting down");        }        return 1;    }    /* we've been told to restart */    signal(SIGHUP, SIG_IGN);    if (is_graceful) {        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,                    AP_SIG_GRACEFUL_STRING " received.  Doing graceful restart");    } else {        /* Kill 'em all.  Since the child acts the same on the parents SIGTERM         * and a SIGHUP, we may as well use the same signal, because some user         * pthreads are stealing signals from us left and right.         */        ap_reclaim_child_processes(1);   /* Start with SIGTERM */            ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,                    "SIGHUP received.  Attempting to restart");    }    /* just before we go, tidy up the lock we created to prevent a     * potential leak of semaphores...     */    apr_thread_mutex_destroy(accept_mutex);    return 0;}static int beos_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp){    static int restart_num = 0;    int no_detach, debug, foreground;    apr_status_t rv;    mpm_state = AP_MPMQ_STARTING;    debug = ap_exists_config_define("DEBUG");    if (debug) {        foreground = one_process = 1;        no_detach = 0;    }    else    {        one_process = ap_exists_config_define("ONE_PROCESS");        no_detach = ap_exists_config_define("NO_DETACH");        foreground = ap_exists_config_define("FOREGROUND");    }    /* sigh, want this only the second time around */    if (restart_num++ == 1) {        is_graceful = 0;        if (!one_process && !foreground) {            rv = apr_proc_detach(no_detach ? APR_PROC_DETACH_FOREGROUND                                           : APR_PROC_DETACH_DAEMONIZE);            if (rv != APR_SUCCESS) {                ap_log_error(APLOG_MARK, APLOG_CRIT, rv, NULL,                             "apr_proc_detach failed");                return HTTP_INTERNAL_SERVER_ERROR;            }        }        server_pid = getpid();    }    beosd_pre_config();    ap_listen_pre_config();    ap_threads_to_start = DEFAULT_START_THREADS;    min_spare_threads = DEFAULT_MIN_FREE_THREADS;    max_spare_threads = DEFAULT_MAX_FREE_THREADS;    ap_thread_limit = HARD_THREAD_LIMIT;    ap_pid_fname = DEFAULT_PIDLOG;    ap_max_requests_per_thread = DEFAULT_MAX_REQUESTS_PER_THREAD;#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE        ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED;#endif    apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));    return OK;}static void beos_hooks(apr_pool_t *p){    one_process = 0;    ap_hook_pre_config(beos_pre_config, NULL, NULL, APR_HOOK_MIDDLE);}static const char *set_threads_to_start(cmd_parms *cmd, void *dummy, const char *arg){    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    ap_threads_to_start = atoi(arg);    if (ap_threads_to_start < 0) {        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                     "StartThreads set to a value less than 0, reset to 1");        ap_threads_to_start = 1;    }    return NULL;}static const char *set_min_spare_threads(cmd_parms *cmd, void *dummy, const char *arg){    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    min_spare_threads = atoi(arg);    if (min_spare_threads <= 0) {       ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                    "WARNING: detected MinSpareThreads set to non-positive.");       ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                    "Resetting to 1 to avoid almost certain Apache failure.");       ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                    "Please read the documentation.");       min_spare_threads = 1;    }    return NULL;}static const char *set_max_spare_threads(cmd_parms *cmd, void *dummy, const char *arg){    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    max_spare_threads = atoi(arg);    return NULL;}static const char *set_threads_limit (cmd_parms *cmd, void *dummy, const char *arg){    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    ap_thread_limit = atoi(arg);    if (ap_thread_limit > HARD_THREAD_LIMIT) {       ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                    "WARNING: MaxClients of %d exceeds compile time limit "                    "of %d servers,", ap_thread_limit, HARD_THREAD_LIMIT);       ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                    " lowering MaxClients to %d.  To increase, please "                    "see the", HARD_THREAD_LIMIT);       ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                    " HARD_THREAD_LIMIT define in server/mpm/beos/mpm_default.h.");       ap_thread_limit = HARD_THREAD_LIMIT;    }    else if (ap_thread_limit < 1) {        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                     "WARNING: Require MaxClients > 0, setting to %d", HARD_THREAD_LIMIT);        ap_thread_limit = HARD_THREAD_LIMIT;    }    return NULL;}static const char *set_max_requests_per_thread (cmd_parms *cmd, void *dummy, const char *arg){    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    ap_max_requests_per_thread = atoi(arg);    if (ap_max_requests_per_thread < 0) {        ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,                     "WARNING: MaxRequestsPerThread was set below 0"                     "reset to 0, but this may not be what you want.");        ap_max_requests_per_thread = 0;    }    return NULL;}static const command_rec beos_cmds[] = {BEOS_DAEMON_COMMANDS,LISTEN_COMMANDS,AP_INIT_TAKE1( "StartThreads", set_threads_to_start, NULL, RSRC_CONF,  "Number of threads to launch at server startup"),AP_INIT_TAKE1( "MinSpareThreads", set_min_spare_threads, NULL, RSRC_CONF,  "Minimum number of idle children, to handle request spikes"),AP_INIT_TAKE1( "MaxSpareThreads", set_max_spare_threads, NULL, RSRC_CONF,  "Maximum number of idle children" ),AP_INIT_TAKE1( "MaxClients", set_threads_limit, NULL, RSRC_CONF,  "Maximum number of children alive at the same time (max threads)" ),AP_INIT_TAKE1( "MaxRequestsPerThread", set_max_requests_per_thread, NULL, RSRC_CONF,  "Maximum number of requests served by a thread" ),{ NULL }};module AP_MODULE_DECLARE_DATA mpm_beos_module = {    MPM20_MODULE_STUFF,    NULL,          /* hook to run before apache parses args */    NULL,          /* create per-directory config structure */    NULL,          /* merge per-directory config structures */    NULL,          /* create per-server config structure */    NULL,          /* merge per-server config structures */    beos_cmds,     /* command apr_table_t */    beos_hooks     /* register_hooks */};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -