i wrote:
|But well, if it's really like that. Thanks again for reporting
|the fix is on [master] and also attached; it fits for v14.8.6.
Terrible dinner, i have indeed forgotten to attach the patch,
please find it below!
Thanks again, and have a nice weekend,
Ciao!
--steffen
commit 0c30b14
Author: Steffen (Daode) Nurpmeso <[email protected]>
Date: 2016-01-16 16:31:13 +0100
FIX Maildir code on BSD (Sergey Matveev)..
Sergey Matveev (stargrave at stargrave dot org) reported that
Maildir on (Free)BSD systems doesn't work because
|Running s-nail under truss gives the following output (part of it, where
|Maildir is checked):
| lseek(3,0x0,SEEK_END) = 142 (0x8e)
and it turns out it is an issue of undefined standard behaviour
regarding file offsets and files that have been opened append-only
with O_APPEND. It was briefly handled by POSIX in May 2009 ([1-3]),
the most remarkable sentences being from Eric Blake
The standard is silent, both behaviors are permitted. In fact,
this is the very bug that bit me when I released GNU M4 1.4.10,
which worked on Linux but failed under BSD.
and Don Cragun
[.] the above output is one correct result. The other correct
result would be for all three reported values to be 0.
http://permalink.gmane.org/gmane.comp.standards.posix.austin.general/
plus [1] 433, [2] 434, [3] 435
It is unlikely that the behaviour will change, but i for one do
consider the output of the following terrible.
cd /tmp
cat > test.c <<-EOT
#include <stdio.h>
#include <unistd.h>
int
main(int argc, char **argv){
int c;
FILE *fp;
fp = fopen("/tmp/bsd-seek-ouch.txt", "a+");
fputs("Hello, BSD!\n", fp);
fseek(fp, 0, SEEK_SET);
if(argc != 1)
printf("OFFSET %ld\n", ftell(fp));
while((c = fgetc(fp)) != EOF)
putchar(c);
fclose(fp);
unlink("/tmp/bsd-seek-ouch.txt");
return 0;
}
EOT
cc -o test test.c
echo one; ./test; echo two; ./test sigh
Add a minimal-invasive fix that should cover the problem.
However, Zopen() is a disaster and it should all be done
completely different than from what we have.
---
maildir.c | 4 ++--
nailfuns.h | 2 +-
popen.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/maildir.c b/maildir.c
index 0bf7f88..375a5c3 100644
--- a/maildir.c
+++ b/maildir.c
@@ -833,7 +833,7 @@ jleave:
}
FL enum okay
-maildir_append(char const *name, FILE *fp)
+maildir_append(char const *name, FILE *fp, long offset)
{
char *buf, *bp, *lp;
size_t bufsize, buflen, cnt;
@@ -850,7 +850,7 @@ maildir_append(char const *name, FILE *fp)
buf = smalloc(bufsize = LINESIZE); /* TODO line pool; signals */
buflen = 0;
cnt = fsize(fp);
- offs = ftell(fp);
+ offs = offset /* BSD will move due to O_APPEND! ftell(fp) */;
size = 0;
srelax_hold();
diff --git a/nailfuns.h b/nailfuns.h
index 0f5fff5..3db6dfa 100644
--- a/nailfuns.h
+++ b/nailfuns.h
@@ -1219,7 +1219,7 @@ FL int maildir_setfile(char const *name, enum fedit_mode fm);
FL void maildir_quit(void);
-FL enum okay maildir_append(char const *name, FILE *fp);
+FL enum okay maildir_append(char const *name, FILE *fp, long offset);
FL enum okay maildir_remove(char const *name);
diff --git a/popen.c b/popen.c
index 6ed0c36..7ea46b3 100644
--- a/popen.c
+++ b/popen.c
@@ -175,7 +175,7 @@ _file_save(struct fp *fpp)
}
#endif
if ((fpp->flags & FP_MASK) == FP_MAILDIR) {
- rv = maildir_append(fpp->realfile, fpp->fp);
+ rv = maildir_append(fpp->realfile, fpp->fp, fpp->offset);
goto jleave;
}
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
S-nail-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/s-nail-users