src.lock_maildirsize
changeset 26 1a5f0c5987d0
parent 24 053ea8d7305d
equal deleted inserted replaced
25:9b0dcedaddc2 26:1a5f0c5987d0
     1 # HG changeset patch
     1 # HG changeset patch
     2 # Parent 725ab374f90553e848d1c418c11003dab45ec07c
     2 # Parent 713d8d0301931a88aad6f7dec3adb838ac15f51f
     3 
     3 
     4 diff -r 725ab374f905 src/transports/appendfile.c
     4 diff -r 713d8d030193 src/transports/appendfile.c
     5 --- a/src/transports/appendfile.c	Wed Apr 13 12:08:31 2011 +0200
     5 --- a/src/transports/appendfile.c	Tue May 17 15:55:42 2011 +0200
     6 +++ b/src/transports/appendfile.c	Wed Apr 13 12:08:39 2011 +0200
     6 +++ b/src/transports/appendfile.c	Tue May 17 16:17:21 2011 +0200
     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
    69  
    69  
    70 -
    70 -
    71  #ifdef SUPPORT_MBX
    71  #ifdef SUPPORT_MBX
    72  /*************************************************
    72  /*************************************************
    73  *         Copy message into MBX mailbox          *
    73  *         Copy message into MBX mailbox          *
    74 @@ -2433,18 +2457,19 @@
    74 @@ -2433,15 +2457,15 @@
    75        {
    75        {
    76        off_t size;
    76        off_t size;
    77        int filecount;
    77        int filecount;
    78 +      uschar *excuse;
    78 +      uschar *excuse;
    79  
    79  
    87 -        addr->message = string_sprintf("while opening or reading "
    87 -        addr->message = string_sprintf("while opening or reading "
    88 -          "%s/maildirsize", check_path);
    88 -          "%s/maildirsize", check_path);
    89 +        addr->message = excuse;
    89 +        addr->message = excuse;
    90          return FALSE;
    90          return FALSE;
    91          }
    91          }
    92  
    92        /* can also return -2, which means that the file was removed because of
    93 +
    93 @@ -3171,6 +3195,12 @@
    94        if (mailbox_size < 0) mailbox_size = size;
       
    95        if (mailbox_filecount < 0) mailbox_filecount = filecount;
       
    96        }
       
    97 @@ -3154,6 +3179,12 @@
       
    98        uschar *renamename = newname;
    94        uschar *renamename = newname;
    99        fd = -1;
    95        fd = -1;
   100  
    96  
   101 +			/* we could get a timeout here, but we don't check for it. Thus it *may*
    97 +			/* 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
    98 +			happen, that we deliver during an active RECALC process. Shit happens and it
   105 +			if (lockfd >= 0) hs12_lock(lockfd, F_RDLCK, "for renaming temporary file");
   101 +			if (lockfd >= 0) hs12_lock(lockfd, F_RDLCK, "for renaming temporary file");
   106 +
   102 +
   107        DEBUG(D_transport) debug_printf("renaming temporary file\n");
   103        DEBUG(D_transport) debug_printf("renaming temporary file\n");
   108  
   104  
   109        /* 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
   110 @@ -3274,6 +3305,7 @@
   106 @@ -3291,6 +3321,7 @@
   111            filename = dataname = NULL;   /* Prevents attempt to unlink at end */
   107            filename = dataname = NULL;   /* Prevents attempt to unlink at end */
   112            }
   108            }
   113          }        /* maildir or mailstore */
   109          }        /* maildir or mailstore */
   114 +
   110 +
   115        }          /* successful write + close */
   111        }          /* successful write + close */
   116      }            /* isdirectory */
   112      }            /* isdirectory */
   117    }              /* write success */
   113    }              /* write success */
   118 @@ -3309,6 +3341,11 @@
   114 @@ -3326,6 +3357,11 @@
   119  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. */
   120  
   116  
   121  RETURN:
   117  RETURN:
   122 +if (lockfd >= 0) 
   118 +if (lockfd >= 0) 
   123 +  {
   119 +  {
   125 +	(void)close(lockfd);
   121 +	(void)close(lockfd);
   126 +	}
   122 +	}
   127  
   123  
   128  #ifdef SUPPORT_MBX
   124  #ifdef SUPPORT_MBX
   129  if (mbx_lockfd >= 0)
   125  if (mbx_lockfd >= 0)
   130 diff -r 725ab374f905 src/transports/appendfile.h
   126 diff -r 713d8d030193 src/transports/appendfile.h
   131 --- a/src/transports/appendfile.h	Wed Apr 13 12:08:31 2011 +0200
   127 --- a/src/transports/appendfile.h	Tue May 17 15:55:42 2011 +0200
   132 +++ b/src/transports/appendfile.h	Wed Apr 13 12:08:39 2011 +0200
   128 +++ b/src/transports/appendfile.h	Tue May 17 16:17:21 2011 +0200
   133 @@ -97,5 +97,8 @@
   129 @@ -97,5 +97,8 @@
   134  /* Function that is shared with tf_maildir.c */
   130  /* Function that is shared with tf_maildir.c */
   135  
   131  
   136  extern off_t  check_dir_size(uschar *, int *, const pcre *);
   132  extern off_t  check_dir_size(uschar *, int *, const pcre *);
   137 +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,
   138 +    int flocktime);
   134 +    int flocktime);
   139 +
   135 +
   140  
   136  
   141  /* End of transports/appendfile.h */
   137  /* End of transports/appendfile.h */
   142 diff -r 725ab374f905 src/transports/tf_maildir.c
   138 diff -r 713d8d030193 src/transports/tf_maildir.c
   143 --- a/src/transports/tf_maildir.c	Wed Apr 13 12:08:31 2011 +0200
   139 --- a/src/transports/tf_maildir.c	Tue May 17 15:55:42 2011 +0200
   144 +++ b/src/transports/tf_maildir.c	Wed Apr 13 12:08:39 2011 +0200
   140 +++ b/src/transports/tf_maildir.c	Tue May 17 16:17:21 2011 +0200
   145 @@ -367,13 +367,16 @@
   141 @@ -367,13 +367,16 @@
   146  
   142  
   147  Returns:           >=0  a file descriptor for an open maildirsize file
   143  Returns:           >=0  a file descriptor for an open maildirsize file
   148                     -1   there was an error opening or accessing the file
   144                     -1   there was an error opening or accessing the file
   149 +				        or locking
   145 +				        or locking
   246  /* Return the sizes and the file descriptor, if any */
   242  /* Return the sizes and the file descriptor, if any */
   247 -
   243 -
   248  DEBUG(D_transport) debug_printf("returning maildir size=" OFF_T_FMT
   244  DEBUG(D_transport) debug_printf("returning maildir size=" OFF_T_FMT
   249    " filecount=%d\n", size, filecount);
   245    " filecount=%d\n", size, filecount);
   250  *returned_size = size;
   246  *returned_size = size;
   251 diff -r 725ab374f905 src/transports/tf_maildir.h
   247 diff -r 713d8d030193 src/transports/tf_maildir.h
   252 --- a/src/transports/tf_maildir.h	Wed Apr 13 12:08:31 2011 +0200
   248 --- a/src/transports/tf_maildir.h	Tue May 17 15:55:42 2011 +0200
   253 +++ b/src/transports/tf_maildir.h	Wed Apr 13 12:08:39 2011 +0200
   249 +++ b/src/transports/tf_maildir.h	Tue May 17 16:17:21 2011 +0200
   254 @@ -16,7 +16,7 @@
   250 @@ -16,7 +16,7 @@
   255                  uschar *);
   251                  uschar *);
   256  extern int    maildir_ensure_sizefile(uschar *,
   252  extern int    maildir_ensure_sizefile(uschar *,
   257                  appendfile_transport_options_block *, const pcre *,
   253                  appendfile_transport_options_block *, const pcre *,
   258 -                const pcre *, off_t *, int *);
   254 -                const pcre *, off_t *, int *);