SOURCES: mod_proctitle.c (NEW) - very experimental module for changing apac...

arekm arekm at pld-linux.org
Mon Jul 7 10:46:47 CEST 2008


Author: arekm                        Date: Mon Jul  7 08:46:47 2008 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- very experimental module for changing apache process name to currently served vhost

---- Files affected:
SOURCES:
   mod_proctitle.c (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/mod_proctitle.c
diff -u /dev/null SOURCES/mod_proctitle.c:1.1
--- /dev/null	Mon Jul  7 10:46:48 2008
+++ SOURCES/mod_proctitle.c	Mon Jul  7 10:46:42 2008
@@ -0,0 +1,89 @@
+/* 
+ * set process name to currently served vhost
+ * 2008, Arkadiusz Miskiewicz <arekm/maven.pl>
+ * apache license
+ */
+
+#include "ap_config.h"
+#include "httpd.h"
+#include "http_config.h"
+#include "http_request.h"
+#include "http_log.h"
+#include "http_protocol.h"
+#include "util_filter.h"
+#include "apr.h"
+#include "apr_strings.h"
+#include "apr_lib.h"
+
+#define MAXTITLE 1024
+
+static char *title_progname_full;
+static char *proctitle_argv=NULL;
+
+module AP_MODULE_DECLARE_DATA proctitle_module;
+
+static void apache_setproctitle(char *arg) {
+	if (proctitle_argv) {
+		int name_len = strlen(title_progname_full);
+		memcpy(proctitle_argv, title_progname_full, name_len);
+		if (arg) {
+			int arg_len, sep_len;
+			char *sep;
+
+			sep = ": ";
+			sep_len = strlen(sep);
+
+			arg_len = strlen(arg);
+			if (arg_len>MAXTITLE)
+				arg_len=MAXTITLE;
+
+			memcpy(proctitle_argv+name_len,sep,sep_len);
+			memcpy(proctitle_argv+name_len+sep_len,arg,arg_len);
+			proctitle_argv[arg_len+name_len+sep_len]='\0';
+		} else {
+			proctitle_argv[name_len]='\0';
+		}
+	}
+}
+
+static int apache_proctitle_enter (request_rec *r) {
+	/* We only call change_hat for the main request, not subrequests */
+	if (r->main) 
+		return OK;
+	apache_setproctitle(r->server->server_hostname);
+	return OK;
+}
+
+static int apache_proctitle_exit (request_rec *r) {
+	apache_setproctitle(NULL);
+	return OK;
+}
+
+static int apache_proctitle_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
+	char **symbol=NULL;
+	if(!proctitle_argv) {
+		symbol=dlsym(NULL,"ap_server_argv0");
+		if (symbol)
+			proctitle_argv=*symbol;
+		title_progname_full = strdup(proctitle_argv);
+		if (!title_progname_full)
+			proctitle_argv = NULL;
+	}
+	return OK;
+}
+
+static void register_hooks (apr_pool_t *p) {
+	ap_hook_post_config (apache_proctitle_init, NULL, NULL, APR_HOOK_MIDDLE);
+	ap_hook_access_checker(apache_proctitle_enter, NULL, NULL, APR_HOOK_FIRST);
+	ap_hook_log_transaction(apache_proctitle_exit, NULL, NULL, APR_HOOK_LAST);
+}
+
+module AP_MODULE_DECLARE_DATA proctitle_module = {
+	STANDARD20_MODULE_STUFF,
+	NULL,			/* dir config creater */
+	NULL,			/* dir merger --- default is to override */
+	NULL,			/* server config */
+	NULL,			/* merge server config */
+	NULL,			/* command table */
+	register_hooks		/* register hooks */
+};
================================================================


More information about the pld-cvs-commit mailing list