dovecot-1.2: Pass the created mail process PID back to login pro...

dovecot at dovecot.org dovecot at dovecot.org
Wed Aug 13 21:36:19 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/29b623366e1e
changeset: 8092:29b623366e1e
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 13 14:36:11 2008 -0400
description:
Pass the created mail process PID back to login process so it can log it.
Added %e log format element for it.

diffstat:

10 files changed, 32 insertions(+), 16 deletions(-)
src/login-common/client-common.c    |    2 ++
src/login-common/client-common.h    |    1 +
src/login-common/master.c           |   12 ++++++++----
src/login-common/master.h           |    2 +-
src/login-common/sasl-server.c      |   13 +++++++------
src/master/login-process.c          |    3 ++-
src/master/mail-process.c           |    4 +++-
src/master/mail-process.h           |    3 ++-
src/master/master-login-interface.h |    2 ++
src/master/master-settings.c        |    6 ++++--

diffs (213 lines):

diff -r ceca59aaae89 -r 29b623366e1e src/login-common/client-common.c
--- a/src/login-common/client-common.c	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/login-common/client-common.c	Wed Aug 13 14:36:11 2008 -0400
@@ -49,6 +49,7 @@ get_var_expand_table(struct client *clie
 		{ 'a', NULL },
 		{ 'b', NULL },
 		{ 'c', NULL },
+		{ 'e', NULL },
 		{ '\0', NULL }
 	};
 	struct var_expand_table *tab;
@@ -85,6 +86,7 @@ get_var_expand_table(struct client *clie
 		tab[11].value = ssl_error == NULL ? ssl_state :
 			t_strdup_printf("%s: %s", ssl_state, ssl_error);
 	}
+	tab[12].value = dec2str(client->mail_pid);
 
 	return tab;
 }
diff -r ceca59aaae89 -r 29b623366e1e src/login-common/client-common.h
--- a/src/login-common/client-common.h	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/login-common/client-common.h	Wed Aug 13 14:36:11 2008 -0400
@@ -33,6 +33,7 @@ struct client {
 	sasl_server_callback_t *sasl_callback;
 
 	unsigned int auth_attempts;
+	pid_t mail_pid;
 
 	char *virtual_user;
 	unsigned int tls:1;
diff -r ceca59aaae89 -r 29b623366e1e src/login-common/master.c
--- a/src/login-common/master.c	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/login-common/master.c	Wed Aug 13 14:36:11 2008 -0400
@@ -24,7 +24,7 @@ static struct client destroyed_client;
 static struct client destroyed_client;
 
 static void client_call_master_callback(struct client *client,
-					enum master_login_status status)
+					const struct master_login_reply *reply)
 {
 	master_callback_t *master_callback;
 
@@ -32,7 +32,7 @@ static void client_call_master_callback(
 	client->master_tag = 0;
 	client->master_callback = NULL;
 
-	master_callback(client, status);
+	master_callback(client, reply);
 }
 
 static void request_handle(struct master_login_reply *reply)
@@ -52,7 +52,7 @@ static void request_handle(struct master
 
 	hash_remove(master_requests, POINTER_CAST(reply->tag));
 	if (client != &destroyed_client) {
-		client_call_master_callback(client, reply->status);
+		client_call_master_callback(client, reply);
 		/* NOTE: client may be destroyed now */
 	}
 }
@@ -114,12 +114,16 @@ void master_request_login(struct client 
 
 void master_request_abort(struct client *client)
 {
+	struct master_login_reply reply;
+
 	/* we're still going to get the reply from the master, so just
 	   remember that we want to ignore it */
 	hash_update(master_requests, POINTER_CAST(client->master_tag),
 		    &destroyed_client);
 
-	client_call_master_callback(client, FALSE);
+	memset(&reply, 0, sizeof(reply));
+	reply.status = MASTER_LOGIN_STATUS_INTERNAL_ERROR;
+	client_call_master_callback(client, &reply);
 }
 
 void master_notify_state_change(enum master_login_state state)
diff -r ceca59aaae89 -r 29b623366e1e src/login-common/master.h
--- a/src/login-common/master.h	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/login-common/master.h	Wed Aug 13 14:36:11 2008 -0400
@@ -6,7 +6,7 @@ struct client;
 #include "../master/master-login-interface.h"
 
 typedef void master_callback_t(struct client *client,
-			       enum master_login_status status);
+			       const struct master_login_reply *reply);
 
 void master_request_login(struct client *client, master_callback_t *callback,
 			  unsigned int auth_pid, unsigned int auth_id);
diff -r ceca59aaae89 -r 29b623366e1e src/login-common/sasl-server.c
--- a/src/login-common/sasl-server.c	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/login-common/sasl-server.c	Wed Aug 13 14:36:11 2008 -0400
@@ -38,15 +38,15 @@ call_client_callback(struct client *clie
 }
 
 static void
-master_callback(struct client *client, enum master_login_status status)
-{
-	enum sasl_server_reply reply = SASL_SERVER_REPLY_MASTER_FAILED;
+master_callback(struct client *client, const struct master_login_reply *reply)
+{
+	enum sasl_server_reply sasl_reply = SASL_SERVER_REPLY_MASTER_FAILED;
 	const char *data = NULL;
 
 	client->authenticating = FALSE;
-	switch (status) {
+	switch (reply->status) {
 	case MASTER_LOGIN_STATUS_OK:
-		reply = SASL_SERVER_REPLY_SUCCESS;
+		sasl_reply = SASL_SERVER_REPLY_SUCCESS;
 		break;
 	case MASTER_LOGIN_STATUS_INTERNAL_ERROR:
 		break;
@@ -54,7 +54,8 @@ master_callback(struct client *client, e
 		data = "Maximum number of connections from user+IP exceeded";
 		break;
 	}
-	call_client_callback(client, reply, data, NULL);
+	client->mail_pid = reply->mail_pid;
+	call_client_callback(client, sasl_reply, data, NULL);
 }
 
 static void authenticate_callback(struct auth_request *request, int status,
diff -r ceca59aaae89 -r 29b623366e1e src/master/login-process.c
--- a/src/master/login-process.c	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/master/login-process.c	Wed Aug 13 14:36:11 2008 -0400
@@ -102,7 +102,8 @@ void auth_master_callback(const char *us
 		master_reply.status =
 			create_mail_process(group->mail_process_type,
 					    group->set, &request->mail_request,
-					    user, args, request->data, FALSE);
+					    user, args, request->data, FALSE,
+					    &master_reply.mail_pid);
 	} T_END;
 
 	/* reply to login */
diff -r ceca59aaae89 -r 29b623366e1e src/master/mail-process.c
--- a/src/master/mail-process.c	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/master/mail-process.c	Wed Aug 13 14:36:11 2008 -0400
@@ -523,7 +523,8 @@ create_mail_process(enum process_type pr
 create_mail_process(enum process_type process_type, struct settings *set,
 		    const struct mail_login_request *request,
 		    const char *user, const char *const *args,
-		    const unsigned char *data, bool dump_capability)
+		    const unsigned char *data, bool dump_capability,
+		    pid_t *pid_r)
 {
 	const struct var_expand_table *var_expand_table;
 	const char *p, *addr, *mail, *chroot_dir, *home_dir, *full_home_dir;
@@ -702,6 +703,7 @@ create_mail_process(enum process_type pr
 			mail_process_group_add(process_group, pid);
 		}
 		(void)close(log_fd);
+		*pid_r = pid;
 		return MASTER_LOGIN_STATUS_OK;
 	}
 
diff -r ceca59aaae89 -r 29b623366e1e src/master/mail-process.h
--- a/src/master/mail-process.h	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/master/mail-process.h	Wed Aug 13 14:36:11 2008 -0400
@@ -20,7 +20,8 @@ create_mail_process(enum process_type pr
 create_mail_process(enum process_type process_type, struct settings *set,
 		    const struct mail_login_request *request,
 		    const char *user, const char *const *args,
-		    const unsigned char *data, bool dump_capability);
+		    const unsigned char *data, bool dump_capability,
+		    pid_t *pid_r);
 
 void mail_processes_init(void);
 void mail_processes_deinit(void);
diff -r ceca59aaae89 -r 29b623366e1e src/master/master-login-interface.h
--- a/src/master/master-login-interface.h	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/master/master-login-interface.h	Wed Aug 13 14:36:11 2008 -0400
@@ -51,6 +51,8 @@ struct master_login_reply {
 struct master_login_reply {
 	unsigned int tag;
 	enum master_login_status status;
+	/* PID of the post-login mail process handling this connection */
+	pid_t mail_pid;
 };
 
 #endif
diff -r ceca59aaae89 -r 29b623366e1e src/master/master-settings.c
--- a/src/master/master-settings.c	Tue Aug 12 18:48:11 2008 -0400
+++ b/src/master/master-settings.c	Wed Aug 13 14:36:11 2008 -0400
@@ -620,6 +620,7 @@ static bool get_imap_capability(struct s
 	ssize_t ret;
 	unsigned int pos;
 	uid_t uid;
+	pid_t pid;
 
 	if (generated_capability != NULL) {
 		/* Reloading configuration. Don't try to execute the imap
@@ -648,7 +649,8 @@ static bool get_imap_capability(struct s
 	memset(&request, 0, sizeof(request));
 	request.fd = fd[1];
 	login_status = create_mail_process(PROCESS_TYPE_IMAP, set, &request,
-					   "dump-capability", args, NULL, TRUE);
+					   "dump-capability", args, NULL, TRUE,
+					   &pid);
 	if (login_status != MASTER_LOGIN_STATUS_OK) {
 		(void)close(fd[0]);
 		(void)close(fd[1]);
@@ -658,7 +660,7 @@ static bool get_imap_capability(struct s
 
 	alarm(5);
 	if (wait(&status) == -1)
-		i_fatal("imap dump-capability process got stuck");
+		i_fatal("imap dump-capability process %d got stuck", (int)pid);
 	alarm(0);
 
 	if (status != 0) {


More information about the dovecot-cvs mailing list