2 * set process name to currently served vhost
3 * 2008, Arkadiusz Miskiewicz <arekm/maven.pl>
9 #include "http_config.h"
10 #include "http_request.h"
12 #include "http_protocol.h"
13 #include "util_filter.h"
15 #include "apr_strings.h"
22 static char *title_progname_full;
23 static char *proctitle_argv=NULL;
25 module AP_MODULE_DECLARE_DATA proctitle_module;
27 static void apache_setproctitle(char *arg) {
29 int name_len = strlen(title_progname_full);
30 memcpy(proctitle_argv, title_progname_full, name_len);
36 sep_len = strlen(sep);
38 arg_len = strlen(arg);
42 memcpy(proctitle_argv+name_len,sep,sep_len);
43 memcpy(proctitle_argv+name_len+sep_len,arg,arg_len);
44 proctitle_argv[arg_len+name_len+sep_len]='\0';
46 proctitle_argv[name_len]='\0';
51 static int apache_proctitle_enter (request_rec *r) {
52 /* We only call change_hat for the main request, not subrequests */
55 apache_setproctitle(r->server->server_hostname);
59 static int apache_proctitle_exit (request_rec *r) {
60 apache_setproctitle(NULL);
64 static int apache_proctitle_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
67 symbol=dlsym(NULL,"ap_server_argv0");
69 proctitle_argv=*symbol;
70 title_progname_full = strdup(proctitle_argv);
71 if (!title_progname_full)
72 proctitle_argv = NULL;
77 static void register_hooks (apr_pool_t *p) {
78 ap_hook_post_config (apache_proctitle_init, NULL, NULL, APR_HOOK_MIDDLE);
79 ap_hook_access_checker(apache_proctitle_enter, NULL, NULL, APR_HOOK_FIRST);
80 ap_hook_log_transaction(apache_proctitle_exit, NULL, NULL, APR_HOOK_LAST);
83 module AP_MODULE_DECLARE_DATA proctitle_module = {
84 STANDARD20_MODULE_STUFF,
85 NULL, /* dir config creater */
86 NULL, /* dir merger --- default is to override */
87 NULL, /* server config */
88 NULL, /* merge server config */
89 NULL, /* command table */
90 register_hooks /* register hooks */