From: Jeff Trawick Date: Wed, 26 Nov 2003 03:45:34 +0000 (+0000) Subject: Add fatal exception hook for use by debug modules. The hook is only X-Git-Tag: pre_ajp_proxy~995 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d0f25613180cbdd07873969beaefb8e88168d61;p=apache Add fatal exception hook for use by debug modules. The hook is only available if the --enable-exception-hook configure parm is used. Sample users at http://httpd.apache.org/~trawick/exception_hook.html git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101899 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 2937e9517a..368597b7ce 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Add fatal exception hook for use by debug modules. The hook is only + available if the --enable-exception-hook configure parm is used. + [Jeff Trawick] + *) mod_ssl/mod_status: Re-enable support for output of SSL session cache information in server-status page. [Joe Orton] diff --git a/configure.in b/configure.in index e930890fc2..1fdffc165b 100644 --- a/configure.in +++ b/configure.in @@ -365,6 +365,12 @@ if test $v4mapped = "yes" -a $ac_cv_define_APR_HAVE_IPV6 = "yes"; then [Allow IPv4 connections on IPv6 listening sockets]) fi +AC_ARG_ENABLE(exception-hook,APACHE_HELP_STRING(--enable-exception-hook,Enable fatal exception hook), +[ + AC_DEFINE(AP_ENABLE_EXCEPTION_HOOK, 1, + [Allow modules to run hook after a fatal exception]) +])dnl + AC_ARG_ENABLE(maintainer-mode,APACHE_HELP_STRING(--enable-maintainer-mode,Turn on debugging and compile time warnings), [ APR_ADDTO(CPPFLAGS, -DAP_DEBUG) diff --git a/include/ap_mpm.h b/include/ap_mpm.h index 5896cbe976..691f8124c1 100644 --- a/include/ap_mpm.h +++ b/include/ap_mpm.h @@ -197,4 +197,13 @@ extern void moncontrol(int); #define AP_MONCONTROL(x) #endif +#if AP_ENABLE_EXCEPTION_HOOK +typedef struct ap_exception_info_t { + int sig; + pid_t pid; +} ap_exception_info_t; + +AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei)) +#endif /*AP_ENABLE_EXCEPTION_HOOK*/ + #endif diff --git a/server/mpm_common.c b/server/mpm_common.c index 51ba206e77..efaceaa739 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -919,11 +919,35 @@ const char *ap_mpm_set_max_mem_free(cmd_parms *cmd, void *dummy, static pid_t parent_pid, my_pid; apr_pool_t *pconf; +#if AP_ENABLE_EXCEPTION_HOOK +APR_HOOK_STRUCT( + APR_HOOK_LINK(fatal_exception) +) + +AP_IMPLEMENT_HOOK_RUN_ALL(int, fatal_exception, + (ap_exception_info_t *ei), (ei), OK, DECLINED) + +static void run_fatal_exception_hook(int sig) +{ + ap_exception_info_t ei = {0}; + + if (geteuid() != 0 && + my_pid != parent_pid) { + ei.sig = sig; + ei.pid = my_pid; + ap_run_fatal_exception(&ei); + } +} +#endif /* AP_ENABLE_EXCEPTION_HOOK */ + /* handle all varieties of core dumping signals */ static void sig_coredump(int sig) { apr_filepath_set(ap_coredump_dir, pconf); apr_signal(sig, SIG_DFL); +#if AP_ENABLE_EXCEPTION_HOOK + run_fatal_exception_hook(sig); +#endif if (my_pid == parent_pid) { ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,