1 # HG changeset patch |
1 # HG changeset patch |
2 # Parent 64ab3b6277037986519edb924069a75ba339de2a |
2 # Parent 64ab3b6277037986519edb924069a75ba339de2a |
3 |
3 |
4 diff -r 64ab3b627703 src/transports/appendfile.c |
4 diff -r 64ab3b627703 src/transports/appendfile.c |
5 --- a/src/transports/appendfile.c Thu Feb 24 20:29:56 2011 +0100 |
5 --- a/src/transports/appendfile.c Thu Feb 24 20:29:56 2011 +0100 |
6 +++ b/src/transports/appendfile.c Thu Feb 24 22:29:28 2011 +0100 |
6 +++ b/src/transports/appendfile.c Sat Feb 26 22:51:42 2011 +0100 |
7 @@ -13,6 +13,7 @@ |
7 @@ -13,6 +13,7 @@ |
8 |
8 |
9 #ifdef SUPPORT_MAILDIR |
9 #ifdef SUPPORT_MAILDIR |
10 #include "tf_maildir.h" |
10 #include "tf_maildir.h" |
11 +extern int lockfd; /* from tf_maildir */ // hs12 |
11 +extern int lockfd; /* from tf_maildir */ // hs12 |
96 } |
96 } |
97 @@ -3125,6 +3150,8 @@ |
97 @@ -3125,6 +3150,8 @@ |
98 uschar *renamename = newname; |
98 uschar *renamename = newname; |
99 fd = -1; |
99 fd = -1; |
100 |
100 |
101 + if (lockfd >= 0) hs12_lock(lockfd, F_RDLCK, "delivery"); |
101 + if (lockfd >= 0) hs12_lock(lockfd, F_RDLCK, "for delivery"); |
102 + |
102 + |
103 DEBUG(D_transport) debug_printf("renaming temporary file\n"); |
103 DEBUG(D_transport) debug_printf("renaming temporary file\n"); |
104 |
104 |
105 /* If there is no rename name set, we are in a non-maildir, non-mailstore |
105 /* If there is no rename name set, we are in a non-maildir, non-mailstore |
106 @@ -3245,6 +3272,7 @@ |
106 @@ -3245,6 +3272,7 @@ |
115 detected, in order to get the file closed and the lock file tidied away. */ |
115 detected, in order to get the file closed and the lock file tidied away. */ |
116 |
116 |
117 RETURN: |
117 RETURN: |
118 +if (lockfd >= 0) |
118 +if (lockfd >= 0) |
119 + { |
119 + { |
120 + hs12_lock(lockfd, F_UNLCK, "done delivery"); |
120 + hs12_lock(lockfd, F_UNLCK, "delivery"); |
121 + (void)close(lockfd); |
121 + (void)close(lockfd); |
122 + } |
122 + } |
123 |
123 |
124 #ifdef SUPPORT_MBX |
124 #ifdef SUPPORT_MBX |
125 if (mbx_lockfd >= 0) |
125 if (mbx_lockfd >= 0) |
126 diff -r 64ab3b627703 src/transports/appendfile.h |
126 diff -r 64ab3b627703 src/transports/appendfile.h |
127 --- a/src/transports/appendfile.h Thu Feb 24 20:29:56 2011 +0100 |
127 --- a/src/transports/appendfile.h Thu Feb 24 20:29:56 2011 +0100 |
128 +++ b/src/transports/appendfile.h Thu Feb 24 22:29:28 2011 +0100 |
128 +++ b/src/transports/appendfile.h Sat Feb 26 22:51:42 2011 +0100 |
129 @@ -95,5 +95,8 @@ |
129 @@ -95,5 +95,8 @@ |
130 /* Function that is shared with tf_maildir.c */ |
130 /* Function that is shared with tf_maildir.c */ |
131 |
131 |
132 extern off_t check_dir_size(uschar *, int *, const pcre *); |
132 extern off_t check_dir_size(uschar *, int *, const pcre *); |
133 +extern int apply_lock(int fd, int fcntltype, BOOL dofcntl, int fcntltime, BOOL doflock, |
133 +extern int apply_lock(int fd, int fcntltype, BOOL dofcntl, int fcntltime, BOOL doflock, |
135 + |
135 + |
136 |
136 |
137 /* End of transports/appendfile.h */ |
137 /* End of transports/appendfile.h */ |
138 diff -r 64ab3b627703 src/transports/tf_maildir.c |
138 diff -r 64ab3b627703 src/transports/tf_maildir.c |
139 --- a/src/transports/tf_maildir.c Thu Feb 24 20:29:56 2011 +0100 |
139 --- a/src/transports/tf_maildir.c Thu Feb 24 20:29:56 2011 +0100 |
140 +++ b/src/transports/tf_maildir.c Thu Feb 24 22:29:28 2011 +0100 |
140 +++ b/src/transports/tf_maildir.c Sat Feb 26 22:51:42 2011 +0100 |
141 @@ -367,13 +367,16 @@ |
141 @@ -367,13 +367,16 @@ |
142 |
142 |
143 Returns: >=0 a file descriptor for an open maildirsize file |
143 Returns: >=0 a file descriptor for an open maildirsize file |
144 -1 there was an error opening or accessing the file |
144 -1 there was an error opening or accessing the file |
145 + or locking |
145 + or locking |
186 +/* Before doing anything here we try to open and lock the maildirsize.lock |
186 +/* Before doing anything here we try to open and lock the maildirsize.lock |
187 +file. This should prevent/avoid races and parallel recalculations. We |
187 +file. This should prevent/avoid races and parallel recalculations. We |
188 +need to do this on an extra lockfile, since the maildirsize file itself |
188 +need to do this on an extra lockfile, since the maildirsize file itself |
189 +gets renamed during the recalculation. */ |
189 +gets renamed during the recalculation. */ |
190 + |
190 + |
191 +hs12_lock(lockfd, F_WRLCK, "checking"); |
191 +hs12_lock(lockfd, F_WRLCK, "for checking"); |
192 +if (sigalrm_seen) |
192 +if (sigalrm_seen) |
193 + { |
193 + { |
194 + *excuse = string_sprintf("timeout locking %s", lockname); |
194 + *excuse = string_sprintf("timeout locking %s", lockname); |
195 + return -1; |
195 + return -1; |
196 + } |
196 + } |
229 - struct timeval tv; |
229 - struct timeval tv; |
230 + struct timeval tv; |
230 + struct timeval tv; |
231 |
231 |
232 DEBUG(D_transport) |
232 DEBUG(D_transport) |
233 { |
233 { |
234 @@ -549,6 +571,13 @@ |
234 @@ -588,8 +610,11 @@ |
235 |
|
236 RECALCULATE: |
|
237 |
|
238 + //hs12_lock(lockfd, F_WRLCK, "recalc"); |
|
239 + if (sigalrm_seen) |
|
240 + { |
|
241 + *excuse = "timeout while locking for recalc"; |
|
242 + return -1; |
|
243 + } |
|
244 + |
|
245 if (fd >= 0) (void)close(fd); |
|
246 old_latest = 0; |
|
247 filecount = 0; |
|
248 @@ -588,8 +617,11 @@ |
|
249 } |
235 } |
250 } |
236 } |
251 |
237 |
252 + hs12_lock(lockfd, F_UNLCK, "done check"); |
238 + hs12_lock(lockfd, F_UNLCK, "check"); |
253 + |
239 + |
254 + |
240 + |
255 + |
241 + |
256 /* Return the sizes and the file descriptor, if any */ |
242 /* Return the sizes and the file descriptor, if any */ |
257 - |
243 - |
258 DEBUG(D_transport) debug_printf("returning maildir size=" OFF_T_FMT |
244 DEBUG(D_transport) debug_printf("returning maildir size=" OFF_T_FMT |
259 " filecount=%d\n", size, filecount); |
245 " filecount=%d\n", size, filecount); |
260 *returned_size = size; |
246 *returned_size = size; |
261 diff -r 64ab3b627703 src/transports/tf_maildir.h |
247 diff -r 64ab3b627703 src/transports/tf_maildir.h |
262 --- a/src/transports/tf_maildir.h Thu Feb 24 20:29:56 2011 +0100 |
248 --- a/src/transports/tf_maildir.h Thu Feb 24 20:29:56 2011 +0100 |
263 +++ b/src/transports/tf_maildir.h Thu Feb 24 22:29:28 2011 +0100 |
249 +++ b/src/transports/tf_maildir.h Sat Feb 26 22:51:42 2011 +0100 |
264 @@ -16,7 +16,7 @@ |
250 @@ -16,7 +16,7 @@ |
265 uschar *); |
251 uschar *); |
266 extern int maildir_ensure_sizefile(uschar *, |
252 extern int maildir_ensure_sizefile(uschar *, |
267 appendfile_transport_options_block *, const pcre *, |
253 appendfile_transport_options_block *, const pcre *, |
268 - const pcre *, off_t *, int *); |
254 - const pcre *, off_t *, int *); |