From: Timo Sirainen Date: Wed, 13 Aug 2008 18:36:11 +0000 (-0400) Subject: Pass the created mail process PID back to login process so it can log it. X-Git-Tag: 1.2.alpha1~69 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=087939d3fa9c4056419386c9d6c81f147de534cd;p=thirdparty%2Fdovecot%2Fcore.git Pass the created mail process PID back to login process so it can log it. Added %e log format element for it. --HG-- branch : HEAD --- diff --git a/src/login-common/client-common.c b/src/login-common/client-common.c index 2e476cec94..409f77db90 100644 --- a/src/login-common/client-common.c +++ b/src/login-common/client-common.c @@ -49,6 +49,7 @@ get_var_expand_table(struct client *client) { '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 *client) 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 --git a/src/login-common/client-common.h b/src/login-common/client-common.h index cd711f5c4c..dfda3fb269 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -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 --git a/src/login-common/master.c b/src/login-common/master.c index 0571048964..5b0526e2e9 100644 --- a/src/login-common/master.c +++ b/src/login-common/master.c @@ -24,7 +24,7 @@ static char master_buf[sizeof(struct master_login_reply)]; 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(struct client *client, 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_login_reply *reply) 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 *client, master_callback_t *callback, 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 --git a/src/login-common/master.h b/src/login-common/master.h index 49351ba77f..2c990a0dc5 100644 --- a/src/login-common/master.h +++ b/src/login-common/master.h @@ -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 --git a/src/login-common/sasl-server.c b/src/login-common/sasl-server.c index 75c2f1eaf9..0ab48d985e 100644 --- a/src/login-common/sasl-server.c +++ b/src/login-common/sasl-server.c @@ -38,15 +38,15 @@ call_client_callback(struct client *client, enum sasl_server_reply reply, } static void -master_callback(struct client *client, enum master_login_status status) +master_callback(struct client *client, const struct master_login_reply *reply) { - enum sasl_server_reply reply = SASL_SERVER_REPLY_MASTER_FAILED; + 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, enum master_login_status status) 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 --git a/src/master/login-process.c b/src/master/login-process.c index 7d529a1112..94d231fbc7 100644 --- a/src/master/login-process.c +++ b/src/master/login-process.c @@ -102,7 +102,8 @@ void auth_master_callback(const char *user, const char *const *args, 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 --git a/src/master/mail-process.c b/src/master/mail-process.c index 586b942f77..c5d464667d 100644 --- a/src/master/mail-process.c +++ b/src/master/mail-process.c @@ -523,7 +523,8 @@ enum master_login_status 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 process_type, struct settings *set, mail_process_group_add(process_group, pid); } (void)close(log_fd); + *pid_r = pid; return MASTER_LOGIN_STATUS_OK; } diff --git a/src/master/mail-process.h b/src/master/mail-process.h index 3d9ffbe84e..f85a605ef0 100644 --- a/src/master/mail-process.h +++ b/src/master/mail-process.h @@ -20,7 +20,8 @@ enum master_login_status 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 --git a/src/master/master-login-interface.h b/src/master/master-login-interface.h index 03f68aabff..5186d03a48 100644 --- a/src/master/master-login-interface.h +++ b/src/master/master-login-interface.h @@ -51,6 +51,8 @@ enum master_login_status { 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 --git a/src/master/master-settings.c b/src/master/master-settings.c index cca4fa55b7..8d210b22eb 100644 --- a/src/master/master-settings.c +++ b/src/master/master-settings.c @@ -620,6 +620,7 @@ static bool get_imap_capability(struct settings *set) 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 settings *set) 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 settings *set) 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) {