Index: src/include/httpd.h =================================================================== RCS file: /home/cvs/apache-1.3/src/include/httpd.h,v retrieving revision 1.375 diff -u -r1.375 httpd.h --- src/include/httpd.h 1 Jan 2004 13:32:53 -0000 1.375 +++ src/include/httpd.h 21 Jan 2004 15:40:10 -0000 @@ -1226,6 +1226,15 @@ #endif #define strtoul strtoul_is_not_a_portable_function_use_strtol_instead +#ifdef AP_ENABLE_EXCEPTION_HOOK +typedef struct ap_exception_info_t { + int sig; + pid_t pid; +} ap_exception_info_t; + +API_EXPORT(extern void) ap_add_fatal_exception_hook(void (*fn)(ap_exception_info_t *)); +#endif + #ifdef __cplusplus } #endif Index: src/main/http_main.c =================================================================== RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v retrieving revision 1.607 diff -u -r1.607 http_main.c --- src/main/http_main.c 13 Jan 2004 19:09:40 -0000 1.607 +++ src/main/http_main.c 21 Jan 2004 15:40:15 -0000 @@ -3110,12 +3110,56 @@ } #endif /* platform has sys_siglist[] */ +#ifdef AP_ENABLE_EXCEPTION_HOOK +typedef struct except_hook_t { + struct except_hook_t *next; + void (*fn)(ap_exception_info_t *); +} except_hook_t; + +static except_hook_t *except_hooks; + +static void except_hook_cleanup(void *ignored) +{ + except_hooks = NULL; +} + +void ap_add_fatal_exception_hook(void (*fn)(ap_exception_info_t *)) +{ + except_hook_t *new; + + ap_assert(pconf); + + new = ap_palloc(pconf, sizeof(except_hook_t)); + new->next = except_hooks; + new->fn = fn; + except_hooks = new; +} + +static void run_fatal_exception_hook(int sig) +{ + except_hook_t *cur_hook = except_hooks; + ap_exception_info_t ei = {0}; + + if (geteuid() != 0) { + ei.sig = sig; + ei.pid = getpid(); + + while (cur_hook) { + cur_hook->fn(&ei); + cur_hook = cur_hook->next; + } + } +} +#endif /* AP_ENABLE_EXCEPTION_HOOK */ /* handle all varieties of core dumping signals */ static void sig_coredump(int sig) { chdir(ap_coredump_dir); signal(sig, SIG_DFL); +#ifdef AP_ENABLE_EXCEPTION_HOOK + run_fatal_exception_hook(sig); +#endif #if !defined(WIN32) && !defined(NETWARE) kill(getpid(), sig); #else @@ -4188,6 +4232,9 @@ pglobal = ap_init_alloc(); pconf = ap_make_sub_pool(pglobal); +#ifdef AP_ENABLE_EXCEPTION_HOOK + ap_register_cleanup(pconf, NULL, except_hook_cleanup, ap_null_cleanup); +#endif plog = ap_make_sub_pool(pglobal); ptrans = ap_make_sub_pool(pconf); @@ -5121,6 +5168,9 @@ } #endif ap_clear_pool(pconf); +#ifdef AP_ENABLE_EXCEPTION_HOOK + ap_register_cleanup(pconf, NULL, except_hook_cleanup, ap_null_cleanup); +#endif ptrans = ap_make_sub_pool(pconf); ap_init_mutex_method(ap_default_mutex_method());