On Fri, Nov 13, 2009 at 01:17:07PM -0500, Wietse Venema wrote:

> Mark Martinec:
> > On Friday 13 November 2009 18:52:03 Wietse Venema wrote:
> > > Thanks for the logging. If you have time, can you change the code
> > > to print information about the non-zero size? This could be a
> > > filesystem feature where ftruncate() does not reset st_size until
> > > the file is rewritten or closed (in which case my attempt to force
> > > easly release of disk blocks are in vain).
> 
> Victor found it (missing fflush before ftruncate). If you can back
> out the changes and apply the patch below.

We could also choose to rewind the proxy log stream in the "free"
code-path (and check that it is already re-wound in the re-use code-path),
which would look something like:

Index: src/smtpd/smtpd_proxy.c
--- src/smtpd/smtpd_proxy.c     11 Nov 2009 04:41:53 -0000      1.1.1.5
+++ src/smtpd/smtpd_proxy.c     13 Nov 2009 18:41:04 -0000
@@ -966,16 +966,13 @@
      * truncating the file redundantly.
      */
     if (smtpd_proxy_replay_stream != 0) {
-       if (vstream_fseek(smtpd_proxy_replay_stream, (off_t) 0, SEEK_SET) < 0) {
-           msg_warn("seek before-queue filter speed-adjust log: %m");
-           (void) vstream_fclose(smtpd_proxy_replay_stream);
-           smtpd_proxy_replay_stream = 0;
-       } else if (fstat(vstream_fileno(smtpd_proxy_replay_stream), &st) < 0) {
+       if (fstat(vstream_fileno(smtpd_proxy_replay_stream), &st) < 0) {
            msg_warn("fstat before-queue filter speed-adjust log: %m");
            (void) vstream_fclose(smtpd_proxy_replay_stream);
            smtpd_proxy_replay_stream = 0;
        } else {
-           if (st.st_size > 0)
+           if (st.st_size > 0
+               || vstream_ftell(smtpd_proxy_replay_stream) != 0)
                msg_panic("%s: non-empty before-queue filter speed-adjust log",
                          myname);
            vstream_clearerr(smtpd_proxy_replay_stream);
@@ -1126,6 +1123,17 @@
      */
     if (smtpd_proxy_replay_stream == 0)
        return;
+
+    /*
+     * Rewind the stream for re-use.
+     * NOTE: This has the side-effect of flushing any buffered data!
+     */
+    if (vstream_fseek(smtpd_proxy_replay_stream, (off_t) 0, SEEK_SET) < 0) {
+       msg_warn("seek before-queue filter speed-adjust log: %m");
+       (void) vstream_fclose(smtpd_proxy_replay_stream);
+       smtpd_proxy_replay_stream = 0;
+       return;
+    }
     if (vstream_ferror(smtpd_proxy_replay_stream)) {
        (void) vstream_fclose(smtpd_proxy_replay_stream);
        smtpd_proxy_replay_stream = 0;

-- 
        Viktor.

Disclaimer: off-list followups get on-list replies or get ignored.
Please do not ignore the "Reply-To" header.

To unsubscribe from the postfix-users list, visit
http://www.postfix.org/lists.html or click the link below:
<mailto:majord...@postfix.org?body=unsubscribe%20postfix-users>

If my response solves your problem, the best way to thank me is to not
send an "it worked, thanks" follow-up. If you must respond, please put
"It worked, thanks" in the "Subject" so I can delete these quickly.

Reply via email to