📄 mpm_netware.c
字号:
restart_pending = shutdown_pending = 0;
worker_thread_count = 0;
if (!is_graceful) {
if (ap_run_pre_mpm(s->process->pool, SB_NOT_SHARED) != OK) {
return 1;
}
}
/* Only set slot 0 since that is all NetWare will ever have. */
ap_scoreboard_image->parent[0].pid = getpid();
set_signals();
apr_pool_create(&pmain, pconf);
ap_run_child_init(pmain, ap_server_conf);
if (ap_threads_max_free < ap_threads_min_free + 1) /* Don't thrash... */
ap_threads_max_free = ap_threads_min_free + 1;
request_count = 0;
startup_workers(ap_threads_to_start);
/* Allow the Apache screen to be closed normally on exit() only if it
has not been explicitly forced to close on exit(). (ie. the -E flag
was specified at startup) */
if (hold_screen_on_exit > 0) {
hold_screen_on_exit = 0;
}
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
"%s configured -- resuming normal operations",
ap_get_server_version());
ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf,
"Server built: %s", ap_get_server_built());
#ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf,
"AcceptMutex: %s (default: %s)",
apr_proc_mutex_name(accept_mutex),
apr_proc_mutex_defname());
#endif
show_server_data();
mpm_state = AP_MPMQ_RUNNING;
while (!restart_pending && !shutdown_pending) {
perform_idle_server_maintenance(pconf);
if (show_settings)
display_settings();
apr_thread_yield();
apr_sleep(SCOREBOARD_MAINTENANCE_INTERVAL);
}
mpm_state = AP_MPMQ_STOPPING;
/* Shutdown the listen sockets so that we don't get stuck in a blocking call.
shutdown_listeners();*/
if (shutdown_pending) { /* Got an unload from the console */
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
"caught SIGTERM, shutting down");
while (worker_thread_count > 0) {
printf ("\rShutdown pending. Waiting for %d thread(s) to terminate...",
worker_thread_count);
apr_thread_yield();
}
return 1;
}
else { /* the only other way out is a restart */
/* 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;
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,
"Graceful restart requested, doing restart");
/* Wait for all of the threads to terminate before initiating the restart */
while (worker_thread_count > 0) {
printf ("\rRestart pending. Waiting for %d thread(s) to terminate...",
worker_thread_count);
apr_thread_yield();
}
printf ("\nRestarting...\n");
}
return 0;
}
static int netware_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
{
int debug;
char *addrname = NULL;
mpm_state = AP_MPMQ_STARTING;
debug = ap_exists_config_define("DEBUG");
is_graceful = 0;
ap_my_pid = getpid();
addrname = getaddressspacename (NULL, NULL);
if (addrname) {
ap_my_addrspace = apr_pstrdup (p, addrname);
free (addrname);
}
ap_listen_pre_config();
ap_threads_to_start = DEFAULT_START_THREADS;
ap_threads_min_free = DEFAULT_MIN_FREE_THREADS;
ap_threads_max_free = DEFAULT_MAX_FREE_THREADS;
ap_threads_limit = HARD_THREAD_LIMIT;
ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
ap_extended_status = 0;
#ifdef AP_MPM_WANT_SET_MAX_MEM_FREE
ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED;
#endif
return OK;
}
static void netware_mpm_hooks(apr_pool_t *p)
{
ap_hook_pre_config(netware_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
}
void netware_rewrite_args(process_rec *process)
{
char *def_server_root;
char optbuf[3];
const char *opt_arg;
apr_getopt_t *opt;
apr_array_header_t *mpm_new_argv;
atexit (mpm_term);
InstallConsoleHandler();
/* Make sure to hold the Apache screen open if exit() is called */
hold_screen_on_exit = 1;
/* Rewrite process->argv[];
*
* add default -d serverroot from the path of this executable
*
* The end result will look like:
* The -d serverroot default from the running executable
*/
if (process->argc > 0) {
char *s = apr_pstrdup (process->pconf, process->argv[0]);
if (s) {
int i, len = strlen(s);
for (i=len; i; i--) {
if (s[i] == '\\' || s[i] == '/') {
s[i] = '\0';
apr_filepath_merge(&def_server_root, NULL, s,
APR_FILEPATH_TRUENAME, process->pool);
break;
}
}
/* Use process->pool so that the rewritten argv
* lasts for the lifetime of the server process,
* because pconf will be destroyed after the
* initial pre-flight of the config parser.
*/
mpm_new_argv = apr_array_make(process->pool, process->argc + 2,
sizeof(const char *));
*(const char **)apr_array_push(mpm_new_argv) = process->argv[0];
*(const char **)apr_array_push(mpm_new_argv) = "-d";
*(const char **)apr_array_push(mpm_new_argv) = def_server_root;
optbuf[0] = '-';
optbuf[2] = '\0';
apr_getopt_init(&opt, process->pool, process->argc, (char**) process->argv);
while (apr_getopt(opt, AP_SERVER_BASEARGS"n:", optbuf + 1, &opt_arg) == APR_SUCCESS) {
switch (optbuf[1]) {
case 'n':
if (opt_arg) {
renamescreen(opt_arg);
}
break;
case 'E':
/* Don't need to hold the screen open if the output is going to a file */
hold_screen_on_exit = -1;
default:
*(const char **)apr_array_push(mpm_new_argv) =
apr_pstrdup(process->pool, optbuf);
if (opt_arg) {
*(const char **)apr_array_push(mpm_new_argv) = opt_arg;
}
break;
}
}
process->argc = mpm_new_argv->nelts;
process->argv = (const char * const *) mpm_new_argv->elts;
}
}
}
static int CommandLineInterpreter(scr_t screenID, const char *commandLine)
{
char *szCommand = "APACHE2 ";
int iCommandLen = 8;
char szcommandLine[256];
char *pID;
screenID = screenID;
if (commandLine == NULL)
return NOTMYCOMMAND;
if (strlen(commandLine) <= strlen(szCommand))
return NOTMYCOMMAND;
strncpy (szcommandLine, commandLine, sizeof(szcommandLine)-1);
/* All added commands begin with "APACHE2 " */
if (!strnicmp(szCommand, szcommandLine, iCommandLen)) {
ActivateScreen (getscreenhandle());
/* If an instance id was not given but the nlm is loaded in
protected space, then the the command belongs to the
OS address space instance to pass it on. */
pID = strstr (szcommandLine, "-p");
if ((pID == NULL) && nlmisloadedprotected())
return NOTMYCOMMAND;
/* If we got an instance id but it doesn't match this
instance of the nlm, pass it on. */
if (pID) {
pID = &pID[2];
while (*pID && (*pID == ' '))
pID++;
}
if (pID && ap_my_addrspace && strnicmp(pID, ap_my_addrspace, strlen(ap_my_addrspace)))
return NOTMYCOMMAND;
/* If we have determined that this command belongs to this
instance of the nlm, then handle it. */
if (!strnicmp("RESTART",&szcommandLine[iCommandLen],3)) {
printf("Restart Requested...\n");
restart();
}
else if (!strnicmp("VERSION",&szcommandLine[iCommandLen],3)) {
printf("Server version: %s\n", ap_get_server_version());
printf("Server built: %s\n", ap_get_server_built());
}
else if (!strnicmp("MODULES",&szcommandLine[iCommandLen],3)) {
ap_show_modules();
}
else if (!strnicmp("DIRECTIVES",&szcommandLine[iCommandLen],3)) {
ap_show_directives();
}
else if (!strnicmp("SHUTDOWN",&szcommandLine[iCommandLen],3)) {
printf("Shutdown Requested...\n");
shutdown_pending = 1;
}
else if (!strnicmp("SETTINGS",&szcommandLine[iCommandLen],3)) {
if (show_settings) {
show_settings = 0;
ClearScreen (getscreenhandle());
show_server_data();
}
else {
show_settings = 1;
display_settings();
}
}
else {
show_settings = 0;
if (strnicmp("HELP",&szcommandLine[iCommandLen],3))
printf("Unknown APACHE2 command %s\n", &szcommandLine[iCommandLen]);
printf("Usage: APACHE2 [command] [-p <instance ID>]\n");
printf("Commands:\n");
printf("\tDIRECTIVES - Show directives\n");
printf("\tHELP - Display this help information\n");
printf("\tMODULES - Show a list of the loaded modules\n");
printf("\tRESTART - Reread the configuration file and restart Apache\n");
printf("\tSETTINGS - Show current thread status\n");
printf("\tSHUTDOWN - Shutdown Apache\n");
printf("\tVERSION - Display the server version information\n");
}
/* Tell NetWare we handled the command */
return HANDLEDCOMMAND;
}
/* Tell NetWare that the command isn't mine */
return NOTMYCOMMAND;
}
static int InstallConsoleHandler(void)
{
/* Our command line handler interfaces the system operator
with this NLM */
NX_WRAP_INTERFACE(CommandLineInterpreter, 2, (void*)&(ConsoleHandler.parser));
ConsoleHandler.rTag = AllocateResourceTag(getnlmhandle(), "Command Line Processor",
ConsoleCommandSignature);
if (!ConsoleHandler.rTag)
{
printf("Error on allocate resource tag\n");
return 1;
}
RegisterConsoleCommand(&ConsoleHandler);
/* The Remove procedure unregisters the console handler */
return 0;
}
static void RemoveConsoleHandler(void)
{
UnRegisterConsoleCommand(&ConsoleHandler);
NX_UNWRAP_INTERFACE(ConsoleHandler.parser);
}
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);
return NULL;
}
static const char *set_min_free_threads(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_min_free = atoi(arg);
if (ap_threads_min_free <= 0) {
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"WARNING: detected MinSpareServers 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.");
ap_threads_min_free = 1;
}
return NULL;
}
static const char *set_max_free_threads(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_max_free = atoi(arg);
return NULL;
}
static const char *set_thread_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_threads_limit = atoi(arg);
if (ap_threads_limit > HARD_THREAD_LIMIT) {
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"WARNING: MaxThreads of %d exceeds compile time limit "
"of %d threads,", ap_threads_limit, HARD_THREAD_LIMIT);
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
" lowering MaxThreads to %d. To increase, please "
"see the", HARD_THREAD_LIMIT);
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
" HARD_THREAD_LIMIT define in %s.",
AP_MPM_HARD_LIMITS_FILE);
ap_threads_limit = HARD_THREAD_LIMIT;
}
else if (ap_threads_limit < 1) {
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"WARNING: Require MaxThreads > 0, setting to 1");
ap_threads_limit = 1;
}
return NULL;
}
static const char *set_thread_stacksize(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_stack_size = atoi(arg);
return NULL;
}
static const command_rec netware_mpm_cmds[] = {
AP_INIT_TAKE1("ThreadStackSize", set_thread_stacksize, NULL, RSRC_CONF,
"Stack size each created thread will use."),
LISTEN_COMMANDS,
AP_INIT_TAKE1("StartThreads", set_threads_to_start, NULL, RSRC_CONF,
"Number of worker threads launched at server startup"),
AP_INIT_TAKE1("MinSpareThreads", set_min_free_threads, NULL, RSRC_CONF,
"Minimum number of idle threads, to handle request spikes"),
AP_INIT_TAKE1("MaxSpareThreads", set_max_free_threads, NULL, RSRC_CONF,
"Maximum number of idle threads"),
AP_INIT_TAKE1("MaxThreads", set_thread_limit, NULL, RSRC_CONF,
"Maximum number of worker threads alive at the same time"),
{ NULL }
};
module AP_MODULE_DECLARE_DATA mpm_netware_module = {
MPM20_MODULE_STUFF,
netware_rewrite_args, /* 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 */
netware_mpm_cmds, /* command apr_table_t */
netware_mpm_hooks, /* register hooks */
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -