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

📄 mpm_winnt.c

📁 apache的软件linux版本
💻 C
📖 第 1 页 / 共 5 页
字号:
                     service_name);        exit(APEXIT_INIT);    }    else if (!one_process && !ap_my_generation) {        /* Open a null handle to soak stdout in this process.         * We need to emulate apr_proc_detach, unix performs this         * same check in the pre_config hook (although it is         * arguably premature).  Services already fixed this.         */        apr_file_t *nullfile;        apr_status_t rv;        apr_pool_t *pproc = apr_pool_parent_get(pconf);        if ((rv = apr_file_open(&nullfile, "NUL",                                APR_READ | APR_WRITE, APR_OS_DEFAULT,                                pproc)) == APR_SUCCESS) {            apr_file_t *nullstdout;            if (apr_file_open_stdout(&nullstdout, pproc)                    == APR_SUCCESS)                apr_file_dup2(nullstdout, nullfile, pproc);            apr_file_close(nullfile);        }    }    /* Win9x: disable AcceptEx */    if (osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {        use_acceptex = 0;    }    ap_listen_pre_config();    ap_threads_per_child = DEFAULT_THREADS_PER_CHILD;    ap_pid_fname = DEFAULT_PIDLOG;    ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;#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 int winnt_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec* s){    static int restart_num = 0;    apr_status_t rv = 0;    /* Handle the following SCM aspects in this phase:     *     *   -k install     *   -k config     *   -k start     *   -k restart     *   -k runservice [Win95, only once - after we parsed the config]     *     * because all of these signals are useful _only_ if there     * is a valid conf\httpd.conf environment to start.     *     * We reached this phase by avoiding errors that would cause     * these options to fail unexpectedly in another process.     */    if (!strcasecmp(signal_arg, "install")) {        rv = mpm_service_install(ptemp, inst_argc, inst_argv, 0);        apr_pool_destroy(s->process->pool);        apr_terminate();        exit(rv);    }    if (!strcasecmp(signal_arg, "config")) {        rv = mpm_service_install(ptemp, inst_argc, inst_argv, 1);        apr_pool_destroy(s->process->pool);        apr_terminate();        exit(rv);    }    if (!strcasecmp(signal_arg, "start")) {        ap_listen_rec *lr;        /* Close the listening sockets. */        for (lr = ap_listeners; lr; lr = lr->next) {            apr_socket_close(lr->sd);            lr->active = 0;        }        rv = mpm_service_start(ptemp, inst_argc, inst_argv);        apr_pool_destroy(s->process->pool);        apr_terminate();        exit(rv);    }    if (!strcasecmp(signal_arg, "restart")) {        mpm_signal_service(ptemp, 1);        apr_pool_destroy(s->process->pool);        apr_terminate();        exit(rv);    }    if (parent_pid == my_pid)     {        if (restart_num++ == 1)         {            /* This code should be run once in the parent and not run             * across a restart             */            PSECURITY_ATTRIBUTES sa = GetNullACL();  /* returns NULL if invalid (Win95?) */            setup_signal_names(apr_psprintf(pconf,"ap%d", parent_pid));            ap_log_pid(pconf, ap_pid_fname);                        /* Create shutdown event, apPID_shutdown, where PID is the parent              * Apache process ID. Shutdown is signaled by 'apache -k shutdown'.             */            shutdown_event = CreateEvent(sa, FALSE, FALSE, signal_shutdown_name);            if (!shutdown_event) {                ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf,                             "Parent: Cannot create shutdown event %s", signal_shutdown_name);                CleanNullACL((void *)sa);                return HTTP_INTERNAL_SERVER_ERROR;            }            /* Create restart event, apPID_restart, where PID is the parent              * Apache process ID. Restart is signaled by 'apache -k restart'.             */            restart_event = CreateEvent(sa, FALSE, FALSE, signal_restart_name);            if (!restart_event) {                CloseHandle(shutdown_event);                ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf,                             "Parent: Cannot create restart event %s", signal_restart_name);                CleanNullACL((void *)sa);                return HTTP_INTERNAL_SERVER_ERROR;            }            CleanNullACL((void *)sa);            /* Now that we are flying at 15000 feet...              * wipe out the Win95 service console,             * signal the SCM the WinNT service started, or             * if not a service, setup console handlers instead.             */            if (!strcasecmp(signal_arg, "runservice"))            {                if (osver.dwPlatformId != VER_PLATFORM_WIN32_NT)                 {                    rv = mpm_service_to_start(&service_name,                                              s->process->pool);                    if (rv != APR_SUCCESS) {                        ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf,                                     "%s: Unable to start the service manager.",                                     service_name);                        return HTTP_INTERNAL_SERVER_ERROR;                    }                }            }            else /* ! -k runservice */            {                mpm_start_console_handler();            }            /* Create the start mutex, as an unnamed object for security.             * Ths start mutex is used during a restart to prevent more than              * one child process from entering the accept loop at once.             */            rv =  apr_proc_mutex_create(&start_mutex, NULL,                                        APR_LOCK_DEFAULT,                                        ap_server_conf->process->pool);            if (rv != APR_SUCCESS) {                ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf,                             "%s: Unable to create the start_mutex.",                             service_name);                return HTTP_INTERNAL_SERVER_ERROR;            }                    }    }    else /* parent_pid != my_pid */    {        mpm_start_child_console_handler();    }    return OK;}/* This really should be a post_config hook, but the error log is already * redirected by that point, so we need to do this in the open_logs phase. */static int winnt_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){    /* Initialize shared static objects.      */    ap_server_conf = s;    if (parent_pid != my_pid) {        return OK;    }    /* We cannot initialize our listeners if we are restarting     * (the parent process already has glomed on to them)     * nor should we do so for service reconfiguration      * (since the service may already be running.)     */    if (!strcasecmp(signal_arg, "restart")             || !strcasecmp(signal_arg, "config")) {        return OK;    }    if (ap_setup_listeners(s) < 1) {        ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0,                      NULL, "no listening sockets available, shutting down");        return DONE;    }    return OK;}static void winnt_child_init(apr_pool_t *pchild, struct server_rec *s){    apr_status_t rv;    setup_signal_names(apr_psprintf(pchild,"ap%d", parent_pid));    /* This is a child process, not in single process mode */    if (!one_process) {        /* Set up events and the scoreboard */        get_handles_from_parent(s, &exit_event, &start_mutex,                                 &ap_scoreboard_shm);        /* Set up the listeners */        get_listeners_from_parent(s);        /* Done reading from the parent, close that channel */        CloseHandle(pipe);        ap_my_generation = ap_scoreboard_image->global->running_generation;    }    else {        /* Single process mode - this lock doesn't even need to exist */        rv = apr_proc_mutex_create(&start_mutex, signal_name_prefix,                                    APR_LOCK_DEFAULT, s->process->pool);        if (rv != APR_SUCCESS) {            ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf,                         "%s child %d: Unable to init the start_mutex.",                         service_name, my_pid);            exit(APEXIT_CHILDINIT);        }                /* Borrow the shutdown_even as our _child_ loop exit event */        exit_event = shutdown_event;    }}AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ){    static int restart = 0;            /* Default is "not a restart" */    if (!restart) {        first_thread_limit = thread_limit;    }    if (changed_limit_at_restart) {        ap_log_error(APLOG_MARK, APLOG_WARNING, APR_SUCCESS, ap_server_conf,                     "WARNING: Attempt to change ThreadLimit ignored "                     "during restart");        changed_limit_at_restart = 0;    }        /* ### If non-graceful restarts are ever introduced - we need to rerun      * the pre_mpm hook on subsequent non-graceful restarts.  But Win32      * has only graceful style restarts - and we need this hook to act      * the same on Win32 as on Unix.     */    if (!restart && ((parent_pid == my_pid) || one_process)) {        /* Set up the scoreboard. */        if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) {            return 1;        }    }        if ((parent_pid != my_pid) || one_process)     {        /* The child process or in one_process (debug) mode          */        ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf,                     "Child %d: Child process is running", my_pid);        child_main(pconf);        ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf,                     "Child %d: Child process is exiting", my_pid);                return 1;    }    else     {        /* A real-honest to goodness parent */        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_NOTICE, 0, ap_server_conf,                     "Server built: %s", ap_get_server_built());        restart = master_main(ap_server_conf, shutdown_event, restart_event);        if (!restart)         {            /* Shutting down. Clean up... */            const char *pidfile = ap_server_root_relative (pconf, ap_pid_fname);            if (pidfile != NULL && unlink(pidfile) == 0) {                ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS,                             ap_server_conf, "removed PID file %s (pid=%ld)",                             pidfile, GetCurrentProcessId());            }            apr_proc_mutex_destroy(start_mutex);            CloseHandle(restart_event);            CloseHandle(shutdown_event);            return 1;        }    }    return 0; /* Restart */}static void winnt_hooks(apr_pool_t *p){    /* The prefork open_logs phase must run before the core's, or stderr     * will be redirected to a file, and the messages won't print to the     * console.     */    static const char *const aszSucc[] = {"core.c", NULL};    ap_hook_pre_config(winnt_pre_config, NULL, NULL, APR_HOOK_MIDDLE);    ap_hook_post_config(winnt_post_config, NULL, NULL, 0);    ap_hook_child_init(winnt_child_init, NULL, NULL, APR_HOOK_MIDDLE);    ap_hook_open_logs(winnt_open_logs, NULL, aszSucc, APR_HOOK_MIDDLE);}AP_MODULE_DECLARE_DATA module mpm_winnt_module = {    MPM20_MODULE_STUFF,    winnt_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 */    winnt_cmds,		        /* command apr_table_t */    winnt_hooks 		/* register_hooks */};#endif /* def WIN32 */

⌨️ 快捷键说明

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