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

📄 threaded.c

📁 Apache V2.0.15 Alpha For Linuxhttpd-2_0_15-alpha.tar.Z
💻 C
📖 第 1 页 / 共 4 页
字号:
    }    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,		"%s configured -- resuming normal operations",		ap_get_server_version());    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, ap_server_conf,		"Server built: %s", ap_get_server_built());    restart_pending = shutdown_pending = 0;    server_main_loop(remaining_children_to_start);    if (shutdown_pending) {        /* Time to gracefully shut down:         * Kill child processes, tell them to call child_exit, etc...         */        if (unixd_killpg(getpgrp(), SIGTERM) < 0) {            ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");        }        ap_reclaim_child_processes(1);		/* Start with SIGTERM */            /* cleanup pid file on normal shutdown */        {            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_NOERRNO|APLOG_INFO, 0,            		 ap_server_conf,            		 "removed PID file %s (pid=%ld)",            		 pidfile, (long)getpid());        }            ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,            "caught SIGTERM, shutting down");    	return 1;    }    /* we've been told to restart */    apr_signal(SIGHUP, SIG_IGN);    if (one_process) {	/* not worth thinking about */	return 1;    }    /* advance to the next generation */    /* XXX: we really need to make sure this new generation number isn't in     * use by any of the children.     */    ++ap_my_generation;    ap_scoreboard_image->global.running_generation = ap_my_generation;    update_scoreboard_global();    if (is_graceful) {	int i, j;        char char_of_death = '!';	ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,		    "SIGWINCH received.  Doing graceful restart");	/* give the children the signal to die */        for (i = 0; i < ap_daemons_limit;) {            if ((rv = apr_file_write(pipe_of_death_in, &char_of_death, &one)) != APR_SUCCESS) {                if (APR_STATUS_IS_EINTR(rv)) continue;                ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf, "write pipe_of_death");            }            i++;        }	/* This is mostly for debugging... so that we know what is still         * gracefully dealing with existing request.         */		for (i = 0; i < ap_daemons_limit; ++i) {  	    for (j = 0; j < ap_threads_per_child; j++) { 	        if (ap_scoreboard_image->servers[i][j].status != SERVER_DEAD) {		    ap_scoreboard_image->servers[i][j].status = SERVER_GRACEFUL;		}	    } 	}    }    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.       */	if (unixd_killpg(getpgrp(), SIGTERM) < 0) {	    ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "killpg SIGTERM");	}        ap_reclaim_child_processes(1);		/* Start with SIGTERM */	ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf,		    "SIGHUP received.  Attempting to restart");    }    return 0;}static void threaded_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp){    static int restart_num = 0;    int no_detach = 0;    one_process = !!ap_exists_config_define("ONE_PROCESS");    no_detach = !!ap_exists_config_define("NO_DETACH");    /* sigh, want this only the second time around */    if (restart_num++ == 1) {	is_graceful = 0;	if (!one_process && !no_detach) {	    apr_proc_detach();	}	ap_my_pid = getpid();    }    unixd_pre_config(ptemp);    ap_listen_pre_config();    ap_daemons_to_start = DEFAULT_START_DAEMON;    min_spare_threads = DEFAULT_MIN_FREE_DAEMON * DEFAULT_THREADS_PER_CHILD;    max_spare_threads = DEFAULT_MAX_FREE_DAEMON * DEFAULT_THREADS_PER_CHILD;    ap_daemons_limit = HARD_SERVER_LIMIT;    ap_threads_per_child = DEFAULT_THREADS_PER_CHILD;    ap_pid_fname = DEFAULT_PIDLOG;    ap_scoreboard_fname = DEFAULT_SCOREBOARD;    lock_fname = DEFAULT_LOCKFILE;    ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;    ap_extended_status = 0;    apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));}static void threaded_hooks(apr_pool_t *p){    one_process = 0;    ap_hook_pre_config(threaded_pre_config, NULL, NULL, APR_HOOK_MIDDLE);}static const char *set_pidfile(cmd_parms *cmd, void *dummy, const char *arg) {    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    if (cmd->server->is_virtual) {	return "PidFile directive not allowed in <VirtualHost>";    }    ap_pid_fname = arg;    return NULL;}static const char *set_scoreboard(cmd_parms *cmd, void *dummy,				  const char *arg) {    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    ap_scoreboard_fname = arg;    return NULL;}static const char *set_lockfile(cmd_parms *cmd, void *dummy, const char *arg) {    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    lock_fname = arg;    return NULL;}static const char *set_daemons_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_daemons_to_start = atoi(arg);    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 | APLOG_NOERRNO, 0, NULL,                     "WARNING: detected MinSpareThreads set to non-positive.");       ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                     "Resetting to 1 to avoid almost certain Apache failure.");       ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 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_server_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_daemons_limit = atoi(arg);    if (ap_daemons_limit > HARD_SERVER_LIMIT) {       ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                     "WARNING: MaxClients of %d exceeds compile time limit "                    "of %d servers,", ap_daemons_limit, HARD_SERVER_LIMIT);       ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                     " lowering MaxClients to %d.  To increase, please "                    "see the", HARD_SERVER_LIMIT);       ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                     " HARD_SERVER_LIMIT define in %s.",                    AP_MPM_HARD_LIMITS_FILE);       ap_daemons_limit = HARD_SERVER_LIMIT;    }     else if (ap_daemons_limit < 1) {	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "WARNING: Require MaxClients > 0, setting to 1");	ap_daemons_limit = 1;    }    return NULL;}static const char *set_threads_per_child (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_per_child = atoi(arg);    if (ap_threads_per_child > HARD_THREAD_LIMIT) {        ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                      "WARNING: ThreadsPerChild of %d exceeds compile time"                     "limit of %d threads,", ap_threads_per_child,                     HARD_THREAD_LIMIT);        ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                      " lowering ThreadsPerChild to %d. To increase, please"                     " see the", HARD_THREAD_LIMIT);        ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                      " HARD_THREAD_LIMIT define in %s.",                     AP_MPM_HARD_LIMITS_FILE);    }    else if (ap_threads_per_child < 1) {	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,                      "WARNING: Require ThreadsPerChild > 0, setting to 1");	ap_threads_per_child = 1;    }    return NULL;}static const char *set_max_requests(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_child = atoi(arg);    return NULL;}static const char *set_coredumpdir (cmd_parms *cmd, void *dummy,				    const char *arg) {    apr_finfo_t finfo;    const char *fname;    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    fname = ap_server_root_relative(cmd->pool, arg);    if ((apr_stat(&finfo, fname, APR_FINFO_TYPE, cmd->pool) != APR_SUCCESS)         || (finfo.filetype != APR_DIR)) {	return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname, 			  " does not exist or is not a directory", NULL);    }    apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir));    return NULL;}static const command_rec threaded_cmds[] = {UNIX_DAEMON_COMMANDSLISTEN_COMMANDSAP_INIT_TAKE1("PidFile", set_pidfile, NULL, RSRC_CONF,    "A file for logging the server process ID"),AP_INIT_TAKE1("ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF,    "A file for Apache to maintain runtime process management information"),AP_INIT_TAKE1("LockFile", set_lockfile, NULL, RSRC_CONF,    "The lockfile used when Apache needs to lock the accept() call"),AP_INIT_TAKE1("StartServers", set_daemons_to_start, NULL, RSRC_CONF,  "Number of child processes launched 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_server_limit, NULL, RSRC_CONF,  "Maximum number of children alive at the same time"),AP_INIT_TAKE1("ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF,  "Number of threads each child creates"),AP_INIT_TAKE1("MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF,  "Maximum number of requests a particular child serves before dying."),AP_INIT_TAKE1("CoreDumpDirectory", set_coredumpdir, NULL, RSRC_CONF,  "The location of the directory Apache changes to before dumping core"),{ NULL }};module AP_MODULE_DECLARE_DATA mpm_threaded_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 */    threaded_cmds,		/* command apr_table_t */    threaded_hooks		/* register_hooks */};

⌨️ 快捷键说明

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