# HG changeset patch # User Timo Sirainen # Date 1497773645 -10800 # Node ID 06b45ab1ae72ee457e80b5136d726d6d2af72871 # Parent 9be64b864597fe9ca747204a804c6295b732fbab imap: NOTIFY - Fix crash due to not hooking into commands correctly The pre/post hooks aren't always called immediately when commands are created. They're called only after the command input is being read. Call notify hooks explicitly now immediately when commands are allocated. Fixes a panic with for example: a notify set (selected (Messagenew (uid flags) MessageExpunge FlagChange) personal (MessageNew MessageExpunge FlagChange)) b select inbox c store 1 +flags \deleted d expunge e append inbox {10} Which crashed with: Panic: file imap-notify.c: line 397 (imap_notify_callback): assertion failed: (client->command_queue_size == 0) diff -r 9be64b864597 -r 06b45ab1ae72 src/imap/imap-client.c --- a/src/imap/imap-client.c Sun Jun 18 11:19:28 2017 +0300 +++ b/src/imap/imap-client.c Sun Jun 18 11:14:05 2017 +0300 @@ -833,6 +833,8 @@ DLLIST_PREPEND(&client->command_queue, cmd); client->command_queue_size++; + + imap_client_notify_command_allocated(client); return cmd; } diff -r 9be64b864597 -r 06b45ab1ae72 src/imap/imap-notify.c --- a/src/imap/imap-notify.c Sun Jun 18 11:19:28 2017 +0300 +++ b/src/imap/imap-notify.c Sun Jun 18 11:14:05 2017 +0300 @@ -16,8 +16,6 @@ #define IMAP_NOTIFY_WATCH_ADD_DELAY_MSECS 1000 -static bool notify_hook_registered; - static int imap_notify_list(struct imap_notify_namespace *notify_ns, const struct mailbox_list_notify_rec *rec, enum mailbox_info_flags flags) @@ -451,16 +449,16 @@ } } -static void imap_notify_cmd_hook_pre(struct client_command_context *cmd) +void imap_client_notify_command_allocated(struct client *client) { - struct imap_notify_context *ctx = cmd->client->notify_ctx; + struct imap_notify_context *ctx = client->notify_ctx; if (ctx == NULL) return; /* remove mailbox watcher before starting any commands */ if (ctx->watching_mailbox) { - mailbox_notify_changes_stop(cmd->client->mailbox); + mailbox_notify_changes_stop(client->mailbox); ctx->watching_mailbox = FALSE; } if (ctx->to_watch != NULL) @@ -474,11 +472,6 @@ enum mailbox_list_notify_event notify_events; int ret = -1; - if (!notify_hook_registered) { - notify_hook_registered = TRUE; - command_hook_register(imap_notify_cmd_hook_pre, NULL); - } - array_foreach_modifiable(&ctx->namespaces, notify_ns) { notify_events = 0; array_foreach(¬ify_ns->mailboxes, notify_boxes) { diff -r 9be64b864597 -r 06b45ab1ae72 src/imap/imap-notify.h --- a/src/imap/imap-notify.h Sun Jun 18 11:19:28 2017 +0300 +++ b/src/imap/imap-notify.h Sun Jun 18 11:14:05 2017 +0300 @@ -64,6 +64,7 @@ int imap_client_notify_newmails(struct client *client); void imap_client_notify_finished(struct client *client); +void imap_client_notify_command_allocated(struct client *client); void imap_client_notify_command_freed(struct client *client); int imap_notify_begin(struct imap_notify_context *ctx);