Watching hook processing order


While perusing through the Apache source code, I came across this nifty little nugget of code in config.c:

if (getenv("SHOW_HOOKS")) {
printf("Registering hooks for %sn", m->name);
apr_hook_debug_enabled = 1;
}

The getenv() call will check for an environment variable names SHOW_HOOKS. If the variable is set, Apache will display the hook processing order on stdout:

$ export SHOW_HOOKS=1

$ httpd -X |more

Registering hooks for core.c
Hooked create_connection
Hooked pre_connection
Hooked post_config
Hooked translate_name
Hooked map_to_storage
Hooked open_logs
Hooked child_init
Hooked handler
Hooked type_checker
Hooked fixups
Hooked access_checker
Hooked create_request
Hooked create_req
Hooked pre_mpm
Hooked insert_filter
Registering hooks for prefork.c

This information can be useful when debugging hook placement (e.g., APR_HOOK_FIRST, APR_HOOK_LAST) issues, and is great for understanding the order in which hooks are executed.

This article was posted by Matty on 2006-02-06 14:56:00 -0400 -0400