]> git.pld-linux.org Git - packages/apache-mod_proctitle.git/blob - mod_proctitle.c
- fix config dir
[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 #include <dlfcn.h>
19
20 #define MAXTITLE 1024
21
22 static char *title_progname_full;
23 static char *proctitle_argv=NULL;
24
25 module AP_MODULE_DECLARE_DATA proctitle_module;
26
27 static void apache_setproctitle(char *arg) {
28         if (proctitle_argv) {
29                 int name_len = strlen(title_progname_full);
30                 memcpy(proctitle_argv, title_progname_full, name_len);
31                 if (arg) {
32                         int arg_len, sep_len;
33                         char *sep;
34
35                         sep = ": ";
36                         sep_len = strlen(sep);
37
38                         arg_len = strlen(arg);
39                         if (arg_len>MAXTITLE)
40                                 arg_len=MAXTITLE;
41
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';
45                 } else {
46                         proctitle_argv[name_len]='\0';
47                 }
48         }
49 }
50
51 static int apache_proctitle_enter (request_rec *r) {
52         /* We only change title for main request, not subrequests */
53         if (r->main) 
54                 return OK;
55         apache_setproctitle(r->server->server_hostname);
56         return OK;
57 }
58
59 static int apache_proctitle_exit (request_rec *r) {
60         apache_setproctitle(NULL);
61         return OK;
62 }
63
64 static int apache_proctitle_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
65         char **symbol=NULL;
66         if(!proctitle_argv) {
67                 symbol=dlsym(NULL,"ap_server_argv0");
68                 if (symbol)
69                         proctitle_argv=*symbol;
70                 title_progname_full = strdup(proctitle_argv);
71                 if (!title_progname_full)
72                         proctitle_argv = NULL;
73         }
74         return OK;
75 }
76
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);
81 }
82
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 */
91 };
This page took 0.03343 seconds and 3 git commands to generate.