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"
20 static char *title_progname_full;
21 static char *proctitle_argv=NULL;
23 module AP_MODULE_DECLARE_DATA proctitle_module;
25 static void apache_setproctitle(char *arg) {
27 int name_len = strlen(title_progname_full);
28 memcpy(proctitle_argv, title_progname_full, name_len);
34 sep_len = strlen(sep);
36 arg_len = strlen(arg);
40 memcpy(proctitle_argv+name_len,sep,sep_len);
41 memcpy(proctitle_argv+name_len+sep_len,arg,arg_len);
42 proctitle_argv[arg_len+name_len+sep_len]='\0';
44 proctitle_argv[name_len]='\0';
49 static int apache_proctitle_enter (request_rec *r) {
50 /* We only call change_hat for the main request, not subrequests */
53 apache_setproctitle(r->server->server_hostname);
57 static int apache_proctitle_exit (request_rec *r) {
58 apache_setproctitle(NULL);
62 static int apache_proctitle_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
65 symbol=dlsym(NULL,"ap_server_argv0");
67 proctitle_argv=*symbol;
68 title_progname_full = strdup(proctitle_argv);
69 if (!title_progname_full)
70 proctitle_argv = NULL;
75 static void register_hooks (apr_pool_t *p) {
76 ap_hook_post_config (apache_proctitle_init, NULL, NULL, APR_HOOK_MIDDLE);
77 ap_hook_access_checker(apache_proctitle_enter, NULL, NULL, APR_HOOK_FIRST);
78 ap_hook_log_transaction(apache_proctitle_exit, NULL, NULL, APR_HOOK_LAST);
81 module AP_MODULE_DECLARE_DATA proctitle_module = {
82 STANDARD20_MODULE_STUFF,
83 NULL, /* dir config creater */
84 NULL, /* dir merger --- default is to override */
85 NULL, /* server config */
86 NULL, /* merge server config */
87 NULL, /* command table */
88 register_hooks /* register hooks */