]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Pass the created mail process PID back to login process so it can log it.
authorTimo Sirainen <tss@iki.fi>
Wed, 13 Aug 2008 18:36:11 +0000 (14:36 -0400)
committerTimo Sirainen <tss@iki.fi>
Wed, 13 Aug 2008 18:36:11 +0000 (14:36 -0400)
Added %e log format element for it.

--HG--
branch : HEAD

src/login-common/client-common.c
src/login-common/client-common.h
src/login-common/master.c
src/login-common/master.h
src/login-common/sasl-server.c
src/master/login-process.c
src/master/mail-process.c
src/master/mail-process.h
src/master/master-login-interface.h
src/master/master-settings.c

index 2e476cec9403419b0cc7349d92ccd11b516db33b..409f77db90edb12fa5dc5f5afc5e0d4b4d83ecf9 100644 (file)
@@ -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;
 }
index cd711f5c4cf9a5b761359aabe12e31c8a348af14..dfda3fb2693e8b1ffe15d6c8a2b202d4880406a5 100644 (file)
@@ -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;
index 057104896412c3c696cd1bc551d50deea1063535..5b0526e2e9e72b8a0552da294f92bb03ef2f5f0e 100644 (file)
@@ -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)
index 49351ba77f1c17738a11b4bcfb68dd1b74a10e43..2c990a0dc5b1257f6d474e7e37da32c007e47838 100644 (file)
@@ -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);
index 75c2f1eaf942d0d8cc010909ada9db9b7789a6af..0ab48d985e053ff30dd02fc4080944dce7242790 100644 (file)
@@ -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,
index 7d529a1112abbe06ea941976f6c3f3a8ef941db3..94d231fbc731088965a0cc5f0bbb9cf8f78a88a1 100644 (file)
@@ -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 */
index 586b942f771d6e77f8ba4a0779adbd5ba23e558d..c5d464667d6a2dbb9a7ef514d0d1f8245febddaf 100644 (file)
@@ -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;
        }
 
index 3d9ffbe84ee6796b4ed2aea06bc976892f6e117f..f85a605ef01dcdce1a78e74a26d68f4836763378 100644 (file)
@@ -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);
index 03f68aabfff4d2089590396548ec6d169bdb64e5..5186d03a48d5121b12d2214da8ca502c773ab05d 100644 (file)
@@ -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
index cca4fa55b794577c38ccab9f05399b1dcce6584e..8d210b22eb81b4238cebbb27295543ea0a243ceb 100644 (file)
@@ -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) {