dovecot-2.0: auth: If verbose_proctitle=yes, show auth request c...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 3 16:58:41 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/6243376eff60
changeset: 11251:6243376eff60
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 03 16:58:36 2010 +0300
description:
auth: If verbose_proctitle=yes, show auth request counts in ps.

 - wait: waiting for auth client to do something (either continue multistep
auth mechanism or issue master request for a finished auth)
 - passdb: waiting for passdb lookup to finish
 - userdb: waiting for userdb lookup to finish

diffstat:

 src/auth/auth-common.h            |   2 +
 src/auth/auth-master-connection.c |   5 +-
 src/auth/auth-request-handler.c   |   4 +-
 src/auth/auth-request.c           |  51 ++++++++++++++++++-------
 src/auth/auth-request.h           |   9 ++++-
 src/auth/auth-settings.c          |   9 ++++-
 src/auth/auth-settings.h          |   2 +
 src/auth/main.c                   |  16 ++++++++
 src/auth/userdb-static.c          |   5 +-
 9 files changed, 81 insertions(+), 22 deletions(-)

diffs (truncated from 333 to 300 lines):

diff -r d8dd3149a98b -r 6243376eff60 src/auth/auth-common.h
--- a/src/auth/auth-common.h	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/auth-common.h	Mon May 03 16:58:36 2010 +0300
@@ -8,4 +8,6 @@
 extern time_t process_start_time;
 extern struct auth_penalty *auth_penalty;
 
+void auth_refresh_proctitle(void);
+
 #endif
diff -r d8dd3149a98b -r 6243376eff60 src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/auth-master-connection.c	Mon May 03 16:58:36 2010 +0300
@@ -214,7 +214,7 @@
 		auth_request_log_info(auth_request, "userdb", "%s", error);
 		user_callback(USERDB_RESULT_USER_UNKNOWN, auth_request);
 	} else {
-		auth_request->state = AUTH_REQUEST_STATE_USERDB;
+		auth_request_set_state(auth_request, AUTH_REQUEST_STATE_USERDB);
 		auth_request_lookup_user(auth_request, user_callback);
 	}
 	return TRUE;
@@ -274,7 +274,8 @@
 		pass_callback(PASSDB_RESULT_USER_UNKNOWN,
 			      NULL, 0, auth_request);
 	} else {
-		auth_request->state = AUTH_REQUEST_STATE_MECH_CONTINUE;
+		auth_request_set_state(auth_request,
+				       AUTH_REQUEST_STATE_MECH_CONTINUE);
 		auth_request_lookup_credentials(auth_request, "",
 						pass_callback);
 	}
diff -r d8dd3149a98b -r 6243376eff60 src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/auth-request-handler.c	Mon May 03 16:58:36 2010 +0300
@@ -491,7 +491,7 @@
 
 	i_assert(request->state == AUTH_REQUEST_STATE_USERDB);
 
-	request->state = AUTH_REQUEST_STATE_FINISHED;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_FINISHED);
 
 	if (request->userdb_lookup_failed)
 		result = USERDB_RESULT_INTERNAL_FAILURE;
@@ -566,7 +566,7 @@
 		/* the request isn't being referenced anywhere anymore,
 		   so we can do a bit of kludging.. replace the request's
 		   old client_id with master's id. */
-		request->state = AUTH_REQUEST_STATE_USERDB;
+		auth_request_set_state(request, AUTH_REQUEST_STATE_USERDB);
 		request->id = id;
 		request->context = handler;
 		request->master = master;
diff -r d8dd3149a98b -r 6243376eff60 src/auth/auth-request.c
--- a/src/auth/auth-request.c	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/auth-request.c	Mon May 03 16:58:36 2010 +0300
@@ -26,6 +26,8 @@
 
 #define CACHED_PASSWORD_SCHEME "SHA1"
 
+enum auth_request_state auth_request_state_count[AUTH_REQUEST_STATE_MAX];
+
 static void get_log_prefix(string_t *str, struct auth_request *auth_request,
 			   const char *subsystem);
 
@@ -36,7 +38,9 @@
 	struct auth_request *request;
 
 	request = mech->auth_new();
+
 	request->state = AUTH_REQUEST_STATE_NEW;
+	auth_request_state_count[AUTH_REQUEST_STATE_NEW]++;
 
 	request->refcount = 1;
 	request->last_access = ioloop_time;
@@ -51,18 +55,34 @@
 
 struct auth_request *auth_request_new_dummy(void)
 {
-	struct auth_request *auth_request;
+	struct auth_request *request;
 	pool_t pool;
 
 	pool = pool_alloconly_create("auth_request", 1024);
-	auth_request = p_new(pool, struct auth_request, 1);
-	auth_request->pool = pool;
+	request = p_new(pool, struct auth_request, 1);
+	request->pool = pool;
 
-	auth_request->refcount = 1;
-	auth_request->last_access = ioloop_time;
-	auth_request->set = global_auth_settings;
+	request->state = AUTH_REQUEST_STATE_NEW;
+	auth_request_state_count[AUTH_REQUEST_STATE_NEW]++;
 
-	return auth_request;
+	request->refcount = 1;
+	request->last_access = ioloop_time;
+	request->set = global_auth_settings;
+	return request;
+}
+
+void auth_request_set_state(struct auth_request *request,
+			    enum auth_request_state state)
+{
+	if (request->state == state)
+		return;
+
+	i_assert(auth_request_state_count[request->state] > 0);
+	auth_request_state_count[request->state]--;
+	auth_request_state_count[state]++;
+
+	request->state = state;
+	auth_refresh_proctitle();
 }
 
 void auth_request_init(struct auth_request *request)
@@ -91,7 +111,7 @@
 		return;
 	}
 
-	request->state = AUTH_REQUEST_STATE_FINISHED;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_FINISHED);
 	request->successful = TRUE;
 	auth_request_refresh_last_access(request);
 	request->callback(request, AUTH_CLIENT_RESULT_SUCCESS,
@@ -102,7 +122,7 @@
 {
 	i_assert(request->state == AUTH_REQUEST_STATE_MECH_CONTINUE);
 
-	request->state = AUTH_REQUEST_STATE_FINISHED;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_FINISHED);
 	auth_request_refresh_last_access(request);
 	request->callback(request, AUTH_CLIENT_RESULT_FAILURE, NULL, 0);
 }
@@ -127,6 +147,9 @@
 	if (--request->refcount > 0)
 		return;
 
+	auth_request_state_count[request->state]--;
+	auth_refresh_proctitle();
+
 	if (request->to_abort != NULL)
 		timeout_remove(&request->to_abort);
 	if (request->to_penalty != NULL)
@@ -224,7 +247,7 @@
 {
 	i_assert(request->state == AUTH_REQUEST_STATE_NEW);
 
-	request->state = AUTH_REQUEST_STATE_MECH_CONTINUE;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_MECH_CONTINUE);
 	request->mech->auth_initial(request, request->initial_response,
 				    request->initial_response_len);
 }
@@ -446,7 +469,7 @@
 {
 	i_assert(request->state == AUTH_REQUEST_STATE_PASSDB);
 
-	request->state = AUTH_REQUEST_STATE_MECH_CONTINUE;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_MECH_CONTINUE);
 
 	if (result != PASSDB_RESULT_INTERNAL_FAILURE)
 		auth_request_save_cache(request, result);
@@ -526,7 +549,7 @@
 		return;
 	}
 
-	request->state = AUTH_REQUEST_STATE_PASSDB;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_PASSDB);
 	request->credentials_scheme = NULL;
 
 	if (passdb->blocking)
@@ -569,7 +592,7 @@
 
 	i_assert(request->state == AUTH_REQUEST_STATE_PASSDB);
 
-	request->state = AUTH_REQUEST_STATE_MECH_CONTINUE;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_MECH_CONTINUE);
 
 	if (result != PASSDB_RESULT_INTERNAL_FAILURE)
 		auth_request_save_cache(request, result);
@@ -622,7 +645,7 @@
 		}
 	}
 
-	request->state = AUTH_REQUEST_STATE_PASSDB;
+	auth_request_set_state(request, AUTH_REQUEST_STATE_PASSDB);
 
 	if (passdb->iface.lookup_credentials == NULL) {
 		/* this passdb doesn't support credentials */
diff -r d8dd3149a98b -r 6243376eff60 src/auth/auth-request.h
--- a/src/auth/auth-request.h	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/auth-request.h	Mon May 03 16:58:36 2010 +0300
@@ -13,7 +13,9 @@
 	AUTH_REQUEST_STATE_PASSDB,
 	AUTH_REQUEST_STATE_MECH_CONTINUE,
 	AUTH_REQUEST_STATE_FINISHED,
-	AUTH_REQUEST_STATE_USERDB
+	AUTH_REQUEST_STATE_USERDB,
+
+	AUTH_REQUEST_STATE_MAX
 };
 
 typedef const char *
@@ -110,6 +112,8 @@
 	/* ... mechanism specific data ... */
 };
 
+extern enum auth_request_state auth_request_state_count[AUTH_REQUEST_STATE_MAX];
+
 struct auth_request *
 auth_request_new(const struct mech_module *mech,
 		 mech_callback_t *callback, void *context);
@@ -117,6 +121,9 @@
 void auth_request_init(struct auth_request *request);
 struct auth *auth_request_get_auth(struct auth_request *request);
 
+void auth_request_set_state(struct auth_request *request,
+			    enum auth_request_state state);
+
 void auth_request_ref(struct auth_request *request);
 void auth_request_unref(struct auth_request **request);
 
diff -r d8dd3149a98b -r 6243376eff60 src/auth/auth-settings.c
--- a/src/auth/auth-settings.c	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/auth-settings.c	Mon May 03 16:58:36 2010 +0300
@@ -160,9 +160,12 @@
 
 /* we're kind of kludging here to avoid "auth_" prefix in the struct fields */
 #undef DEF
+#undef DEF_NOPREFIX
 #undef DEFLIST
 #define DEF(type, name) \
 	{ type, "auth_"#name, offsetof(struct auth_settings, name), NULL }
+#define DEF_NOPREFIX(type, name) \
+	{ type, #name, offsetof(struct auth_settings, name), NULL }
 #define DEFLIST(field, name, defines) \
 	{ SET_DEFLIST, name, offsetof(struct auth_settings, field), defines }
 
@@ -196,6 +199,8 @@
 	DEFLIST(passdbs, "passdb", &auth_passdb_setting_parser_info),
 	DEFLIST(userdbs, "userdb", &auth_userdb_setting_parser_info),
 
+	DEF_NOPREFIX(SET_BOOL, verbose_proctitle),
+
 	SETTING_DEFINE_LIST_END
 };
 
@@ -227,7 +232,9 @@
 	.worker_max_count = 30,
 
 	.passdbs = ARRAY_INIT,
-	.userdbs = ARRAY_INIT
+	.userdbs = ARRAY_INIT,
+
+	.verbose_proctitle = FALSE
 };
 
 const struct setting_parser_info auth_setting_parser_info = {
diff -r d8dd3149a98b -r 6243376eff60 src/auth/auth-settings.h
--- a/src/auth/auth-settings.h	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/auth-settings.h	Mon May 03 16:58:36 2010 +0300
@@ -45,6 +45,8 @@
 	ARRAY_DEFINE(passdbs, struct auth_passdb_settings *);
 	ARRAY_DEFINE(userdbs, struct auth_userdb_settings *);
 
+	bool verbose_proctitle;
+
 	/* generated: */
 	char username_chars_map[256];
 	char username_translation_map[256];
diff -r d8dd3149a98b -r 6243376eff60 src/auth/main.c
--- a/src/auth/main.c	Mon May 03 16:11:30 2010 +0300
+++ b/src/auth/main.c	Mon May 03 16:58:36 2010 +0300
@@ -10,6 +10,7 @@
 #include "sql-api.h"
 #include "module-dir.h"
 #include "randgen.h"
+#include "process-title.h"
 #include "settings-parser.h"
 #include "master-service.h"
 #include "master-service-settings.h"
@@ -45,6 +46,20 @@
 static struct mechanisms_register *mech_reg;
 static ARRAY_DEFINE(listen_fd_types, enum auth_socket_type);
 
+void auth_refresh_proctitle(void)
+{
+	if (!global_auth_settings->verbose_proctitle)
+		return;
+
+	process_title_set(t_strdup_printf(
+		"[%u wait, %u passdb, %u userdb]",
+		auth_request_state_count[AUTH_REQUEST_STATE_NEW] +
+		auth_request_state_count[AUTH_REQUEST_STATE_MECH_CONTINUE] +
+		auth_request_state_count[AUTH_REQUEST_STATE_FINISHED],
+		auth_request_state_count[AUTH_REQUEST_STATE_PASSDB],
+		auth_request_state_count[AUTH_REQUEST_STATE_USERDB]));
+}
+


More information about the dovecot-cvs mailing list