Commit 0392527e authored by Jeff Trawick's avatar Jeff Trawick
Browse files

Add child_status hook for tracking creation/termination of MPM child

processes.  Add end_generation hook for notification when the last
MPM child of a generation exits.

end_generation is implemented completely by core using the
child_status hook run by the MPM.

simple and mpmt_os2 MPMs don't currently run the child_status
hook, so neither hook is invoked with those MPMs.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1096609 13f79535-47bb-0310-9956-ffa450edef68
parent 23ed395f
Loading
Loading
Loading
Loading
+4 −0
Changes for CHANGES: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@

Changes with Apache 2.3.12

  *) Add child_status hook for tracking creation/termination of MPM child
     processes.  Add end_generation hook for notification when the last
     MPM child of a generation exits. [Jeff Trawick]

  *) mod_ldap: Make LDAPSharedCacheSize 0 create a non-shared-memory cache per
     process as opposed to disabling caching completely. This allows to use
     the non-shared-memory cache as a workaround for the shared memory cache
+2 −1
Changes for include/ap_mmn.h: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -319,6 +319,7 @@
 * 20110329.1 (2.3.12-dev) Add ap_reserve_module_slots()/ap_reserve_module_slots_directive()
 *                         change AP_CORE_DECLARE to AP_DECLARE: ap_create_request_config()
 *                         change AP_DECLARE to AP_CORE_DECLARE: ap_register_log_hooks()
 * 20110329.2 (2.3.12-dev) Add child_status and end_generation hooks.
 */

#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -326,7 +327,7 @@
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20110329
#endif
#define MODULE_MAGIC_NUMBER_MINOR 1                    /* 0...n */
#define MODULE_MAGIC_NUMBER_MINOR 2                    /* 0...n */

/**
 * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
+38 −0
Changes for include/ap_mpm.h: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

#include "apr_thread_proc.h"
#include "httpd.h"
#include "scoreboard.h"

#ifdef __cplusplus
extern "C" {
@@ -166,6 +167,43 @@ AP_DECLARE(apr_status_t) ap_mpm_register_timed_callback(apr_time_t t,
                                                       ap_mpm_callback_fn_t *cbfn,
                                                       void *baton);

typedef enum mpm_child_status {
    MPM_CHILD_STARTED,
    MPM_CHILD_EXITED,
    MPM_CHILD_LOST_SLOT
} mpm_child_status;

/**
 * Allow a module to remain aware of MPM child process state changes,
 * along with the generation and scoreboard slot of the process changing
 * state.
 *
 * With some MPMs (event and worker), an active MPM child process may lose
 * its scoreboard slot if the child process is exiting and the scoreboard
 * slot is needed by other processes.  When this occurs, the hook will be
 * called with the MPM_CHILD_LOST_SLOT state.
 *
 * @param s The main server_rec.
 * @param pid The id of the MPM child process.
 * @param gen The server generation of that child process.
 * @param slot The scoreboard slot number, or -1.  It will be -1 when an
 * MPM child process exits, and that child had previously lost its
 * scoreboard slot.
 * @param state One of the mpm_child_status values.  Modules should ignore
 * unrecognized values.
 */
AP_DECLARE_HOOK(void,child_status,(server_rec *s, pid_t pid, ap_generation_t gen,
                                   int slot, mpm_child_status state))

/**
 * Allow a module to be notified when the last child process of a generation
 * exits.
 *
 * @param s The main server_rec.
 * @param gen The server generation which is now completely finished.
 */
AP_DECLARE_HOOK(void,end_generation,(server_rec *s, ap_generation_t gen))

/* Defining GPROF when compiling uses the moncontrol() function to
 * disable gprof profiling in the parent, and enable it only for
 * request processing in children (or in one_process mode).  It's
+11 −3
Changes for include/mpm_common.h: 11 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@

#include "ap_config.h"
#include "ap_mpm.h"
#include "scoreboard.h"

#if APR_HAVE_NETINET_TCP_H
#include <netinet/tcp.h>    /* for TCP_NODELAY */
@@ -85,7 +86,8 @@ extern "C" {
 * ap_relieve_child_processes().  The callback function will be
 * called for each terminated child process.
 */
typedef void ap_reclaim_callback_fn_t(int childnum);
typedef void ap_reclaim_callback_fn_t(int childnum, pid_t pid,
                                      ap_generation_t gen);

/**
 * Make sure all child processes that have been spawned by the parent process
@@ -116,21 +118,23 @@ void ap_relieve_child_processes(ap_reclaim_callback_fn_t *mpm_callback);
 * an MPM child process which has no entry in the scoreboard.
 * @param pid The process id of an MPM child process which should be
 * reclaimed when ap_reclaim_child_processes() is called.
 * @param gen The generation of this MPM child process.
 *
 * @note If an extra MPM child process terminates prior to calling
 * ap_reclaim_child_processes(), remove it from the list of such processes
 * by calling ap_unregister_extra_mpm_process().
 */
void ap_register_extra_mpm_process(pid_t pid);
void ap_register_extra_mpm_process(pid_t pid, ap_generation_t gen);

/**
 * Unregister an MPM child process which was previously registered by a
 * call to ap_register_extra_mpm_process().
 * @param pid The process id of an MPM child process which no longer needs to
 * be reclaimed.
 * @param old_gen Set to the server generation of the process, if found.
 * @return 1 if the process was found and removed, 0 otherwise
 */
int ap_unregister_extra_mpm_process(pid_t pid);
int ap_unregister_extra_mpm_process(pid_t pid, ap_generation_t *old_gen);

/**
 * Safely signal an MPM child process, if the process is in the
@@ -321,6 +325,10 @@ extern const char *ap_mpm_set_thread_stacksize(cmd_parms *cmd, void *dummy,
extern apr_status_t ap_fatal_signal_setup(server_rec *s, apr_pool_t *pconf);
extern apr_status_t ap_fatal_signal_child_setup(server_rec *s);

/* core's implementation of child_status hook */
extern void ap_core_child_status(server_rec *s, pid_t pid, ap_generation_t gen,
                                 int slot, mpm_child_status status);

#if AP_ENABLE_EXCEPTION_HOOK
extern const char *ap_mpm_set_exception_hook(cmd_parms *cmd, void *dummy,
                                             const char *arg);
+1 −0
Changes for server/core.c: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -4407,6 +4407,7 @@ static void register_hooks(apr_pool_t *p)
    APR_OPTIONAL_HOOK(proxy, create_req, core_create_proxy_req, NULL, NULL,
                      APR_HOOK_MIDDLE);
    ap_hook_pre_mpm(ap_create_scoreboard, NULL, NULL, APR_HOOK_MIDDLE);
    ap_hook_child_status(ap_core_child_status, NULL, NULL, APR_HOOK_MIDDLE);

    /* register the core's insert_filter hook and register core-provided
     * filters
Loading