From 1f90e5c5a3c7cb029ce1ac3c2e760c368fd2ce92 Mon Sep 17 00:00:00 2001 From: Dan Harkless Date: Wed, 31 May 2000 02:27:40 +0000 Subject: [PATCH] Applied Alec Wolman 's dropsbr.c patch: In the map_write routine, a call is made to map_open and this call is supposed to set the "clear" variable to 0 or 1, depending on whether the map file is empty or not. In mh6.8.3, this worked because map_open would set "clear" by calling the mbx_Xopen routine. In nmh, the code for mbx_Xopen was merged into mbx_open, but the interface for mbx_open doesn't support the clear variable, so that functionality was lost. The map_open interface still contains "int *clear" in the prototype, but never sets it. My patch eliminates "clear" from the map_open interface (I checked to make sure that map_write is the only client of map_open). Furthermore, my patch also sets the "clear" variable properly at the beginning of map_write by calling fstat(). This eliminates the bug in that the value of "clear" being used later in the routine was just stack garbage. Having a bad value of clear causes this next bug to be triggered: The fp file pointer was being opened with fdopen, but in two of the three switch cases it wasn't being closed. In certain cases, this was causing packf to run out of file descriptors if you attempted to pack a large folder. --- ChangeLog | 27 ++++++++++++++++++++++++++- uip/dropsbr.c | 16 ++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2abd85..6fbfa72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -Fri May 30 17:51:48 2000 Dan Harkless +Fri May 30 19:21:48 2000 Dan Harkless * etc/Makefile.in was incorrectly installing mts.conf.in and sendfiles.in -- fixed. Generated sendfiles script was not a @@ -13,6 +13,31 @@ Fri May 30 17:51:48 2000 Dan Harkless * INSTALL never documented the etc/*.old thing. Documented the new etc/*.prev thing (including a note to watch for diff output). + * Applied Alec Wolman 's dropsbr.c patch: + + In the map_write routine, a call is made to map_open and this + call is supposed to set the "clear" variable to 0 or 1, + depending on whether the map file is empty or not. In + mh6.8.3, this worked because map_open would set "clear" by + calling the mbx_Xopen routine. In nmh, the code for mbx_Xopen + was merged into mbx_open, but the interface for mbx_open + doesn't support the clear variable, so that functionality was + lost. The map_open interface still contains "int *clear" in + the prototype, but never sets it. + + My patch eliminates "clear" from the map_open interface (I + checked to make sure that map_write is the only client of + map_open). Furthermore, my patch also sets the "clear" + variable properly at the beginning of map_write by calling + fstat(). This eliminates the bug in that the value of "clear" + being used later in the routine was just stack garbage. + + Having a bad value of clear causes this next bug to be + triggered: The fp file pointer was being opened with fdopen, + but in two of the three switch cases it wasn't being closed. + In certain cases, this was causing packf to run out of file + descriptors if you attempted to pack a large folder. + Mon May 29 7:48:15 2000 Shantonu Sen * Moved the date parsing routines from zotnet/tws to sbr/ (and diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 6089a22..5cf4ee3 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -38,7 +38,7 @@ extern int errno; */ static int mbx_chk_mbox (int); static int mbx_chk_mmdf (int); -static int map_open (char *, int *, int); +static int map_open (char *, int); /* @@ -565,14 +565,20 @@ map_write (char *mailbox, int md, int id, long last, off_t start, register struct drop *dp; struct drop d1, d2, *rp; register FILE *fp; + struct stat st; - if ((fd = map_open (file = map_name (mailbox), &clear, md)) == NOTOK) + if ((fd = map_open (file = map_name (mailbox), md)) == NOTOK) return NOTOK; + if ((fstat (fd, &st) == OK) && (st.st_size > 0)) + clear = 0; + else + clear = 1; + if (!clear && map_chk (file, fd, &d1, pos, noisy)) { unlink (file); mbx_close (file, fd); - if ((fd = map_open (file, &clear, md)) == NOTOK) + if ((fd = map_open (file, md)) == NOTOK) return NOTOK; clear++; } @@ -594,6 +600,7 @@ map_write (char *mailbox, int md, int id, long last, off_t start, return NOTOK; case OK: + fclose (fp); break; default: @@ -611,6 +618,7 @@ map_write (char *mailbox, int md, int id, long last, off_t start, } } free ((char *) rp); + fclose (fp); break; } } @@ -651,7 +659,7 @@ map_write (char *mailbox, int md, int id, long last, off_t start, static int -map_open (char *file, int *clear, int md) +map_open (char *file, int md) { mode_t mode; struct stat st; -- 1.7.10.4