]> git.pld-linux.org Git - packages/apache-mod_proctitle.git/blob - mod_proctitle.c
- very experimental module for changing apache process name to currently served vhost
[packages/apache-mod_proctitle.git] / mod_proctitle.c
1 /* 
2  * set process name to currently served vhost
3  * 2008, Arkadiusz Miskiewicz <arekm/maven.pl>
4  * apache license
5  */
6
7 #include "ap_config.h"
8 #include "httpd.h"
9 #include "http_config.h"
10 #include "http_request.h"
11 #include "http_log.h"
12 #include "http_protocol.h"
13 #include "util_filter.h"
14 #include "apr.h"
15 #include "apr_strings.h"
16 #include "apr_lib.h"
17
18 #define MAXTITLE 1024
19
20 static char *title_progname_full;
21 static char *proctitle_argv=NULL;
22
23 module AP_MODULE_DECLARE_DATA proctitle_module;
24
25 static void apache_setproctitle(char *arg) {
26         if (proctitle_argv) {
27                 int name_len = strlen(title_progname_full);
28                 memcpy(proctitle_argv, title_progname_full, name_len);
29                 if (arg) {
30                         int arg_len, sep_len;
31                         char *sep;
32
33                         sep = ": ";
34                         sep_len = strlen(sep);
35
36                         arg_len = strlen(arg);
37                         if (arg_len>MAXTITLE)
38                                 arg_len=MAXTITLE;
39
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';
43                 } else {
44                         proctitle_argv[name_len]='\0';
45                 }
46         }
47 }
48
49 static int apache_proctitle_enter (request_rec *r) {
50         /* We only call change_hat for the main request, not subrequests */
51         if (r->main) 
52                 return OK;
53         apache_setproctitle(r->server->server_hostname);
54         return OK;
55 }
56
57 static int apache_proctitle_exit (request_rec *r) {
58         apache_setproctitle(NULL);
59         return OK;
60 }
61
62 static int apache_proctitle_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
63         char **symbol=NULL;
64         if(!proctitle_argv) {
65                 symbol=dlsym(NULL,"ap_server_argv0");
66                 if (symbol)
67                         proctitle_argv=*symbol;
68                 title_progname_full = strdup(proctitle_argv);
69                 if (!title_progname_full)
70                         proctitle_argv = NULL;
71         }
72         return OK;
73 }
74
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);
79 }
80
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 */
89 };
This page took 0.092215 seconds and 4 git commands to generate.