This document was hosted from my directory for many years. Latest information:

an exception hook for Apache 1.3 and a couple of modules that use it

These can be used in conjunction or individually or simply cut up into pieces as you see fit *on test systems*. It does appear to work :) If you find a problem, please let me know.

activating the hook

The required changes to Apache httpd 1.3 are in 1.3.30-dev. Wait for 1.3.30 to be released or check it out from cvs or pick up a daily snapshot.

You'll need to build Apache with the symbol AP_ENABLE_EXCEPTION_HOOK defined. This will allow plug-in modules to implement a call-back which will be called when a synchronous signal is generated.

Note: The symbol is already defined for AIX, Linux, and Solaris.

OPTIM=-DAP_ENABLE_EXCEPTION_HOOK ./configure --other-opts

The web server configuration file must also be changed to include

EnableExceptionHook On

at global scope. By default, exception hooks don't get to run just because the required support is compiled into the server.


Note: This is now in Apache 1.3's modules/experimental directory. See the file there for directions on how to activate it.

inspired by an ugly problem in 1.3 where we couldn't get a core dump and had no idea what type of request led to the segfault... only thing I could think to do was give them a module that wrote a log message near the beginning of the request to give all sorts of information about the request (url, ssl?, virtual host, etc.) in hopes of finding a pattern... but of course this filled up a big file

mod_whatkilledus keeps a little bit of state on each active connection, which allows it to know what a thread was handling in case the thread segfaults. If that happens, it writes a report to a log file.

Required configuration:

Here is an example entry written after a segfault:

(The data written by the latest level of code is actually a little different, but you get the idea ;))
[Wed Jan 21 10:38:32 2004] pid 2211 sig 11 crash
[Wed Jan 21 10:38:32 2004] pid 2211 active connection:>
[Wed Jan 21 10:38:32 2004] pid 2211 active request:
GET /silly?sigsegv
:sol9:8080|Keep-Alive:300|User-Agent:Mozilla/5.0 (X11; 
U; SunOS i86pc; en-US; rv:1.5) Gecko/20031020


Note: This is now in Apache 1.3's modules/experimental directory. See the file there for directions on how to activate it.

This is another diagnostic trick for situations where you can't get a core dump and/or can't get a backtrace.

mod_backtrace is a a module currently limited to Linux and FreeBSD which uses system library functions to format a backtrace to show what code did the dirty deed. By default the information is written to the error log, but a directive is provided for setting the name of a log file to which the backtrace will be appended.

Unfortunately the exact format and unfortunately the usefulness of the backtrace varies among library versions. Here is how it can look on Fedora Core 1. (Some experimentation with removing the httpd symbol stripping from the Apache install would be useful.)

[Mon Jan 19 17:09:10 2004] pid 10735 backtrace for signal 11
[Mon Jan 19 17:09:10 2004] pid 10735 main() is at 8076b93
[Mon Jan 19 17:09:10 2004] pid 10735 end of backtrace

I've seen just a series of hex addresses on an older SuSE distro on zSeries. The address of main() is logged too, so enterprising individuals will be able to make sense of those hex addresses by using "nm -n httpd" to display httpd symbols. For functions which are part of httpd, the hex addresses in the backtrace will correspond to instructions within the range of a function displayed by nm. (Enterprising zSeries folks will of course need to ignore the high-order bit of the addresses in the backtrace.)

I don't know how DSOs are laid out in storage, and mod_backtrace_13 doesn't display any known addresses for the DSOs to give a hint. Maybe mod_backtrace_13 needs to have an option to walk through the loaded DSOs and spit out the module name and some associated address to make this straightforward.

Required configuration:

LoadModule backtrace_13_module libexec/
BTFile /tmp/mod_backtrace_log

HP-UX offers a U_STACK_TRACE() function but I have not been able to get it to work from mod_backtrace_13. My notes:

The U_STACK_TRACE() function lives in in 11i 1.0. That library, or a shared library that links to it directly, cannot be loaded into Apache 1.3:

/usr/lib/ Can't shl_load() a library containing Thread Local Storage:   
/usr/lib/ Exec format error
Syntax error on line 1025 of /home/trawick/inst/13/conf/httpd.conf:
Cannot load /home/trawick/inst/13/libexec/ into server:
    Exec format error

Thus mod_backtrace_13 and HP-UX is on hold for now. Possibly the support can be implemented in the mod_backtrace for Apache 2, but I have not investigated that yet. Also, it may be possible to dynamically load U_STACK_TRACE() using a function other than shl_load(), but I have not investigated that yet either.