Electric Fence

Bruce Perens' Electric Fence is a fantastic debugging tool, and it has saved my skin on more than one occasion. In theory it is thread-safe, but unfortunately, due to a glibc bug, it has the potential to hang on pthread_exit(). The tarball below is a patched version of Efence that works around this bug by using a pthread_mutex, rather than a semaphore, to guard the Efence internals. It's been tested with success on a large multi-threaded app running on RedHat Linux 8.0 (glibc 2.2).

ElectricFence-2.2.2.mutex.tar.gz

Compilation: Just untar and compile (make; make install) as-is, or edit the Makefile to change the installation directory.

Technical note: The patch is compiled in using the -D_USE_MUTEX directive (see the Makefile and efence.c). Bruce's semaphore system is still there and can be compiled in using the original -D_USE_SEMAPHORE directive. You'll get a compliation-time error if you try to define both.

There are one or two other minor changes to Bruce's code. A full unified diff is here: ElectricFence-2.2.2.mutex.patch. I've submitted the mutex-related patch to Bruce, and posted it on RedHat's Buzilla (Bug 54368). Hopefully the patch will appear in the official distributions in the near future.


Robert Sim, 03 Feb 2003