[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zmailer shortcomings (re pop/imap clients)



In dist.zmailer, article <92Dec17.200048eet.91266-2@nic.funet.fi>,
  Matti Aarnio <mea@nic.funet.fi> writes:
> > While we're on this subject...
> > 
> > I just found a problem with MX handling. 
> > Assume that the MX for somebody points to me. Therefore, the MX lookup
> > returns an error. Unfortunately, that host has an A record, therefore
> > smtp_neighbour returns a pointer to that host. Not good.
> > 
> > I can't just trash the A lookup because many idiots out there don't know 
> > what MXes are.  :-(
> > 
> > The system in question has an A record because they're using UUCP over TCP
> > to pick up their mail. SMTP delivery must take precedence over UUCP delivery
> > because otherwise we would run into serious problems.
> 
>   Isn't this the case for the   $MAILSHARE/db/routes -database ?
> At least I have used it for that purpose..
> 
"routes" could conceivably be used for the same purpose. 
However, I'd prefer a solution which causes smtp_neighbour to do the
Right Thing instead of using a workaround. I might eithet not have control
over the DNS entries which show the problem, or simply forget to update
the routes database. :-/

PS: Systems which either don't have rename() or where rename() is implemented
in terms of link/unlink can't run concurrent routers because if two routers
erename() the same file, both succeed: suddenly the mail is duplicated.
Solution: Use lockf()/flock(). (Stolen from transports/mailbox, which
probably should use this code.)

--- esyslib.c.orig	Fri Dec 18 11:31:36 1992
+++ esyslib.c	Fri Dec 18 12:26:54 1992
@@ -13,7 +13,24 @@
 #include "hostenv.h"
 #include "mailer.h"
 #include <errno.h>
+#include <sys/file.h>
 
+#ifdef  USE_LOCKF
+#ifdef  F_OK
+#undef  F_OK
+#endif  /* F_OK */
+#ifdef  X_OK
+#undef  X_OK
+#endif  /* X_OK */
+#ifdef  W_OK
+#undef  W_OK
+#endif  /* W_OK */
+#ifdef  R_OK
+#undef  R_OK
+#endif  /* R_OK */
+#include <unistd.h>
+#endif  /* USE_LOCKF */
+
 extern char	*progname;
 extern int	errno;
 extern char	*strerror();
@@ -245,7 +262,11 @@
 	char *from, *to;
 {
 	int	r;
+	int	fd;
+	int	oerrno;
 
+	if((fd = elockfile(from)) < 0)
+	    return -1;
 #ifdef	USE_RENAME
 	
 	if ((r = rename(from, to)) < 0) {
@@ -261,5 +282,78 @@
 	else
 		(void) unlink(from);
 #endif	/* !USE_RENAME */
+	oerrno = errno;
+	eunlockfile(fd);
+	errno = oerrno;
 	return r;
+}
+
+int
+elockfd(fd)
+	int fd;
+{
+#ifdef  USE_LOCKF
+	long fpos;
+
+	fpos = elseek(fd,0,1);
+        if (elseek(fd, 0,0) < 0 ||
+            lockf(fd, F_LOCK, 0) < 0)
+#else   /* !USE_LOCKF */
+        if (flock(fd, LOCK_EX) < 0)
+#endif  /* USE_LOCKF */
+	{
+            (void) fprintf(stderr, "%s: lockfile(%d): %s\n", progname,
+                    fd, strerror(errno));
+#ifdef USE_LOCKF
+	    (void) elseek(fd,fpos,0);
+#endif
+	    return -1;
+	}
+#ifdef USE_LOCKF
+	(void) elseek(fd,fpos,0);
+#endif
+	return 0;
+}
+
+int
+eunlockfd(fd)
+	int fd;
+{
+#ifdef  USE_LOCKF
+        {
+	    long fpos = elseek(fd,0,1);
+            (void) lseek(fd,0,0);
+            (void) lockf(fd, F_ULOCK, 0);
+	    (void) elseek(fd,fpos,0);
+        }
+#else   /* !USE_LOCKF */
+        (void) flock(fd, LOCK_UN);
+#endif  /* USE_LOCKF */
+	return 0;
+}
+
+int
+elockfile(fname)
+	char *fname;
+{
+	int fd;
+
+	if((fd = eopen(fname,O_RDWR,0)) < 0) 
+	    return -1;
+	if(elockfd(fd) < 0) {
+	    int oerrno = errno;
+	    (void) eclose(fd);
+	    errno = oerrno;
+	    return -1;
+	}
+	return fd;
+}
+
+int
+eunlockfile(fd)
+	int fd;
+{
+	(void) eunlockfd(fd);
+	(void) eclose(fd);
+	return 0;
 }

-- 
The key to Springfield is Elm Street.  The Greeks knew it.  The Carthaginians
knew it, and now you know it ...
               -- Herman (?) in _Bart_the_General_, from The Simpsons
-- 
Matthias Urlichs  --  urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de   /(o\
Humboldtstrasse 7 -- 7500 Karlsruhe 1 -- Germany  --  +49-721-9612521     \o)/