📄 beos.c
字号:
if (!is_graceful) { 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 SIGWINCH). 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; } /* setup the child pool to use for the workers. Each worker creates * a seperate pool of it's own to use. */ apr_pool_create(&pchild, pconf); ap_run_child_init(pchild, ap_server_conf); /* Now that we have the child pool (pchild) we can allocate * the listenfds and creat the pollset... */ listening_sockets = apr_palloc(pchild, sizeof(*listening_sockets) * (num_listening_sockets + 1)); listening_sockets[0] = udp_sock; for (lr = ap_listeners, i = 1; i <= num_listening_sockets; lr = lr->next, ++i) listening_sockets[i]=lr->sd; /* we assume all goes OK...hmm might want to check that! */ if (!is_graceful) { 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_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; /* * main_loop until it's all over */ server_main_loop(remaining_threads_to_start); tell_workers_to_exit(); /* if we get here we're exiting... */ sleep(1); /* give them a brief chance to exit */ /* close the UDP socket we've been using... */ apr_socket_close(listening_sockets[0]); /* * 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"); /* 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()); } /* use ap_reclaim_child_processes starting with SIGTERM */ ap_reclaim_child_processes(1); /* record the shutdown in the log */ 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 */ signal(SIGHUP, SIG_IGN); if (one_process) { return 1; } if (is_graceful) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, 0, ap_server_conf, "SIGWINCH 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_NOERRNO|APLOG_NOTICE, 0, ap_server_conf, "SIGHUP received. Attempting to restart"); } /* just before we go, tidy up the locks we've created to prevent a * potential leak of semaphores... */ apr_lock_destroy(worker_thread_count_mutex); apr_lock_destroy(accept_mutex); return 0;}static void beos_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(); 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_threads_per_child = DEFAULT_THREADS_PER_CHILD; ap_pid_fname = DEFAULT_PIDLOG; ap_scoreboard_fname = DEFAULT_SCOREBOARD; ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));}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_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_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_threads_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_thread_limit = atoi(arg); if (ap_thread_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_thread_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 src/include/httpd.h."); ap_thread_limit = HARD_SERVER_LIMIT; } else if (ap_thread_limit < 1) { ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "WARNING: Require MaxClients > 0, setting to 1"); ap_thread_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 beos_cmds[] = {LISTEN_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( "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_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 + -