|      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	Sat Feb 26 22:51:42 2011 +0100 |      6 +++ b/src/transports/appendfile.c	Sun Feb 27 21:51:22 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 | 
|     92   |     92   | 
|     93 + |     93 + | 
|     94        if (mailbox_size < 0) mailbox_size = size; |     94        if (mailbox_size < 0) mailbox_size = size; | 
|     95        if (mailbox_filecount < 0) mailbox_filecount = filecount; |     95        if (mailbox_filecount < 0) mailbox_filecount = filecount; | 
|     96        } |     96        } | 
|     97 @@ -3125,6 +3150,8 @@ |     97 @@ -3125,6 +3150,12 @@ | 
|     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, "for delivery"); |    101 +			/* we could get a timeout here, but we don't check for it. Thus it *may* | 
|         |    102 +			happen, that we deliver during an active RECALC process. Shit happens and it | 
|         |    103 +			will cause the RECALC to discard its result... */ | 
|         |    104 + | 
|         |    105 +			if (lockfd >= 0) hs12_lock(lockfd, F_RDLCK, "for renaming temporary file"); | 
|    102 + |    106 + | 
|    103        DEBUG(D_transport) debug_printf("renaming temporary file\n"); |    107        DEBUG(D_transport) debug_printf("renaming temporary file\n"); | 
|    104   |    108   | 
|    105        /* If there is no rename name set, we are in a non-maildir, non-mailstore |    109        /* If there is no rename name set, we are in a non-maildir, non-mailstore | 
|    106 @@ -3245,6 +3272,7 @@ |    110 @@ -3245,6 +3276,7 @@ | 
|    107            filename = dataname = NULL;   /* Prevents attempt to unlink at end */ |    111            filename = dataname = NULL;   /* Prevents attempt to unlink at end */ | 
|    108            } |    112            } | 
|    109          }        /* maildir or mailstore */ |    113          }        /* maildir or mailstore */ | 
|    110 + |    114 + | 
|    111        }          /* successful write + close */ |    115        }          /* successful write + close */ | 
|    112      }            /* isdirectory */ |    116      }            /* isdirectory */ | 
|    113    }              /* write success */ |    117    }              /* write success */ | 
|    114 @@ -3280,6 +3308,11 @@ |    118 @@ -3280,6 +3312,11 @@ | 
|    115  detected, in order to get the file closed and the lock file tidied away. */ |    119  detected, in order to get the file closed and the lock file tidied away. */ | 
|    116   |    120   | 
|    117  RETURN: |    121  RETURN: | 
|    118 +if (lockfd >= 0)  |    122 +if (lockfd >= 0)  | 
|    119 +  { |    123 +  { | 
|    123   |    127   | 
|    124  #ifdef SUPPORT_MBX |    128  #ifdef SUPPORT_MBX | 
|    125  if (mbx_lockfd >= 0) |    129  if (mbx_lockfd >= 0) | 
|    126 diff -r 64ab3b627703 src/transports/appendfile.h |    130 diff -r 64ab3b627703 src/transports/appendfile.h | 
|    127 --- a/src/transports/appendfile.h	Thu Feb 24 20:29:56 2011 +0100 |    131 --- a/src/transports/appendfile.h	Thu Feb 24 20:29:56 2011 +0100 | 
|    128 +++ b/src/transports/appendfile.h	Sat Feb 26 22:51:42 2011 +0100 |    132 +++ b/src/transports/appendfile.h	Sun Feb 27 21:51:22 2011 +0100 | 
|    129 @@ -95,5 +95,8 @@ |    133 @@ -95,5 +95,8 @@ | 
|    130  /* Function that is shared with tf_maildir.c */ |    134  /* Function that is shared with tf_maildir.c */ | 
|    131   |    135   | 
|    132  extern off_t  check_dir_size(uschar *, int *, const pcre *); |    136  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, |    137 +extern int apply_lock(int fd, int fcntltype, BOOL dofcntl, int fcntltime, BOOL doflock, | 
|    135 + |    139 + | 
|    136   |    140   | 
|    137  /* End of transports/appendfile.h */ |    141  /* End of transports/appendfile.h */ | 
|    138 diff -r 64ab3b627703 src/transports/tf_maildir.c |    142 diff -r 64ab3b627703 src/transports/tf_maildir.c | 
|    139 --- a/src/transports/tf_maildir.c	Thu Feb 24 20:29:56 2011 +0100 |    143 --- a/src/transports/tf_maildir.c	Thu Feb 24 20:29:56 2011 +0100 | 
|    140 +++ b/src/transports/tf_maildir.c	Sat Feb 26 22:51:42 2011 +0100 |    144 +++ b/src/transports/tf_maildir.c	Sun Feb 27 21:51:22 2011 +0100 | 
|    141 @@ -367,13 +367,16 @@ |    145 @@ -367,13 +367,16 @@ | 
|    142   |    146   | 
|    143  Returns:           >=0  a file descriptor for an open maildirsize file |    147  Returns:           >=0  a file descriptor for an open maildirsize file | 
|    144                     -1   there was an error opening or accessing the file |    148                     -1   there was an error opening or accessing the file | 
|    145 +				        or locking |    149 +				        or locking | 
|    244  DEBUG(D_transport) debug_printf("returning maildir size=" OFF_T_FMT |    248  DEBUG(D_transport) debug_printf("returning maildir size=" OFF_T_FMT | 
|    245    " filecount=%d\n", size, filecount); |    249    " filecount=%d\n", size, filecount); | 
|    246  *returned_size = size; |    250  *returned_size = size; | 
|    247 diff -r 64ab3b627703 src/transports/tf_maildir.h |    251 diff -r 64ab3b627703 src/transports/tf_maildir.h | 
|    248 --- a/src/transports/tf_maildir.h	Thu Feb 24 20:29:56 2011 +0100 |    252 --- a/src/transports/tf_maildir.h	Thu Feb 24 20:29:56 2011 +0100 | 
|    249 +++ b/src/transports/tf_maildir.h	Sat Feb 26 22:51:42 2011 +0100 |    253 +++ b/src/transports/tf_maildir.h	Sun Feb 27 21:51:22 2011 +0100 | 
|    250 @@ -16,7 +16,7 @@ |    254 @@ -16,7 +16,7 @@ | 
|    251                  uschar *); |    255                  uschar *); | 
|    252  extern int    maildir_ensure_sizefile(uschar *, |    256  extern int    maildir_ensure_sizefile(uschar *, | 
|    253                  appendfile_transport_options_block *, const pcre *, |    257                  appendfile_transport_options_block *, const pcre *, | 
|    254 -                const pcre *, off_t *, int *); |    258 -                const pcre *, off_t *, int *); |