Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/index-mailbox-check.c @ 9266:cd29b745c8dd HEAD
configure: clock_gettime()'s -lrt adding dropped everything else from $LIBS.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 27 Jul 2009 06:32:42 -0400 |
parents | b9faf4db2a9f |
children | abbb153d4643 |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
7292
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "index-storage.h" |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include <stdlib.h> |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1733
diff
changeset
|
8 #include <unistd.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1733
diff
changeset
|
9 #include <fcntl.h> |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include <sys/stat.h> |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
12 struct index_notify_file { |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
13 struct index_notify_file *next; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
14 |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
15 char *path; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
16 time_t last_stamp; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
17 }; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
18 |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
19 struct index_notify_io { |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
20 struct index_notify_io *next; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
21 struct io *io; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
22 }; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
23 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
24 static void check_timeout(struct index_mailbox *ibox) |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 { |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
26 struct index_notify_file *file; |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 struct stat st; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3534
diff
changeset
|
28 bool notify; |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
30 notify = ibox->notify_pending; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
31 for (file = ibox->notify_files; file != NULL; file = file->next) { |
1172 | 32 if (stat(file->path, &st) == 0 && |
2478
87b6d3303031
Timeout/stat() based mailbox change checker didn't actually ever send
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
33 file->last_stamp != st.st_mtime) { |
1172 | 34 file->last_stamp = st.st_mtime; |
2478
87b6d3303031
Timeout/stat() based mailbox change checker didn't actually ever send
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
35 notify = TRUE; |
87b6d3303031
Timeout/stat() based mailbox change checker didn't actually ever send
Timo Sirainen <tss@iki.fi>
parents:
2322
diff
changeset
|
36 } |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
37 } |
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
38 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
39 if (notify) { |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
40 ibox->notify_last_sent = ioloop_time; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
41 ibox->notify_pending = FALSE; |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
42 ibox->box.notify_callback(&ibox->box, ibox->box.notify_context); |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
43 } |
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
44 } |
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
45 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
46 static void notify_callback(struct index_mailbox *ibox) |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
47 { |
7292
d0520bb9177f
mailbox_notify_changes(): Don't trigger the timeout once a second to see if
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
48 timeout_reset(ibox->notify_to); |
d0520bb9177f
mailbox_notify_changes(): Don't trigger the timeout once a second to see if
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
49 |
6469
416973e853db
Dropped interval between mailbox change notifies from
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
50 /* don't notify more often than once a second */ |
6470 | 51 if (ioloop_time > ibox->notify_last_sent) { |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
52 ibox->notify_last_sent = ioloop_time; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
53 ibox->notify_pending = FALSE; |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
54 ibox->box.notify_callback(&ibox->box, ibox->box.notify_context); |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
55 } else { |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
56 ibox->notify_pending = TRUE; |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 } |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 } |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
60 void index_mailbox_check_add(struct index_mailbox *ibox, |
3534
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
61 const char *path) |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 { |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
63 struct index_notify_file *file; |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 struct stat st; |
2780
4ff5b3e8ee51
If we can't add file to I/O notify list, close the fd so we don't leak.
Timo Sirainen <tss@iki.fi>
parents:
2478
diff
changeset
|
65 struct io *io = NULL; |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
66 struct index_notify_io *aio; |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
67 |
5937
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5465
diff
changeset
|
68 (void)io_add_notify(path, notify_callback, ibox, &io); |
3534
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
69 if (io != NULL) { |
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
70 aio = i_new(struct index_notify_io, 1); |
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
71 aio->io = io; |
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
72 aio->next = ibox->notify_ios; |
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
73 ibox->notify_ios = aio; |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
74 } |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
76 file = i_new(struct index_notify_file, 1); |
1172 | 77 file->path = i_strdup(path); |
3534
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
78 file->last_stamp = stat(path, &st) < 0 ? 0 : st.st_mtime; |
2780
4ff5b3e8ee51
If we can't add file to I/O notify list, close the fd so we don't leak.
Timo Sirainen <tss@iki.fi>
parents:
2478
diff
changeset
|
79 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
80 file->next = ibox->notify_files; |
3534
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
81 ibox->notify_files = file; |
1172 | 82 |
3534
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
83 /* we still add a timeout if we don't have one already, |
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
84 * because we don't know what happens with [di]notify |
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
2780
diff
changeset
|
85 * when the filesystem is remote (NFS, ...) */ |
7292
d0520bb9177f
mailbox_notify_changes(): Don't trigger the timeout once a second to see if
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
86 if (ibox->notify_to == NULL) { |
d0520bb9177f
mailbox_notify_changes(): Don't trigger the timeout once a second to see if
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
87 ibox->notify_to = |
d0520bb9177f
mailbox_notify_changes(): Don't trigger the timeout once a second to see if
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
88 timeout_add(ibox->box.notify_min_interval * 1000, |
d0520bb9177f
mailbox_notify_changes(): Don't trigger the timeout once a second to see if
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
89 check_timeout, ibox); |
d0520bb9177f
mailbox_notify_changes(): Don't trigger the timeout once a second to see if
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
90 } |
1172 | 91 } |
92 | |
93 void index_mailbox_check_remove_all(struct index_mailbox *ibox) | |
94 { | |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
95 struct index_notify_file *file; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
96 struct index_notify_io *aio; |
1172 | 97 |
1733 | 98 /* reset notify stamp */ |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
99 ibox->notify_last_sent = 0; |
1733 | 100 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
101 while (ibox->notify_files != NULL) { |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
102 file = ibox->notify_files; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
103 ibox->notify_files = file->next; |
1172 | 104 |
105 i_free(file->path); | |
106 i_free(file); | |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 } |
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
109 while (ibox->notify_ios != NULL) { |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
110 aio = ibox->notify_ios; |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
111 ibox->notify_ios = aio->next; |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
112 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
113 io_remove(&aio->io); |
1730
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
114 i_free(aio); |
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
115 } |
8480f945e270
IDLE uses now IO_*_NOTIFY to get instant notifying of mails.
Timo Sirainen <tss@iki.fi>
parents:
1172
diff
changeset
|
116 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
117 if (ibox->notify_to != NULL) |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
118 timeout_remove(&ibox->notify_to); |
600
3b44bc64afd4
mailbox_check_interval setting: Dovecot can notify client of new mail in
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 } |