From c9b9c7a23daa62084d588a393ba0329ef601e71f Mon Sep 17 00:00:00 2001 From: Mark Horton Date: Fri, 17 Oct 1980 21:41:57 -0800 Subject: [PATCH] uses dbm package for alias file to make it faster SCCS-vsn: usr.sbin/sendmail/src/alias.c 1.4 SCCS-vsn: usr.sbin/sendmail/src/deliver.c 1.6 --- usr/src/usr.sbin/sendmail/src/alias.c | 52 ++++++++++++++++++++----- usr/src/usr.sbin/sendmail/src/deliver.c | 19 ++++++++- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/usr/src/usr.sbin/sendmail/src/alias.c b/usr/src/usr.sbin/sendmail/src/alias.c index 63bbb97a3c..2503bcfa44 100644 --- a/usr/src/usr.sbin/sendmail/src/alias.c +++ b/usr/src/usr.sbin/sendmail/src/alias.c @@ -3,14 +3,14 @@ # include # include "dlvrmail.h" -static char SccsId[] = "@(#)alias.c 1.3 %G%"; +static char SccsId[] = "@(#)alias.c 1.4 %G%"; /* ** ALIAS -- Compute aliases. ** -** Scans the file /usr/lib/mailaliases for a set of aliases. +** Scans the file ALIASFILE for a set of aliases. ** If found, it arranges to deliver to them by inserting the -** new names onto the SendQ queue. +** new names onto the SendQ queue. Uses libdbm database if -DDBM. ** ** Parameters: ** none @@ -37,6 +37,9 @@ static char SccsId[] = "@(#)alias.c 1.3 %G%"; ** where 'alias' expands to all of ** 'name[i]'. Continuations begin with ** space or tab. +** ALIASFILE.pag, ALIASFILE.dir: libdbm version +** of alias file. Keys are aliases, datums +** (data?) are name1,name2, ... ** ** Notes: ** If NoAlias (the "-n" flag) is set, no aliasing is @@ -52,6 +55,11 @@ static char SccsId[] = "@(#)alias.c 1.3 %G%"; # define ALIASFILE "/usr/lib/mailaliases" # define MAXRCRSN 10 +#ifdef DBM +typedef struct {char *dptr; int dsize;} datum; +datum lhs, rhs; +datum fetch(); +#endif DBM alias() { @@ -74,6 +82,7 @@ alias() # endif /* open alias file if not already open */ +#ifndef DBM # ifdef DEBUG if (Debug && (af = fopen("mailaliases", "r")) != NULL) printf(" [using local alias file]\n"); @@ -88,7 +97,11 @@ alias() errno = 0; return; } +#else DBM + dbminit(ALIASFILE); +#endif DBM +#ifndef DBM /* ** Scan alias file. ** If we find any user that any line matches any user, we @@ -102,8 +115,7 @@ alias() ** continuation lines. */ - didalias = TRUE; - while (didalias) + do { didalias = FALSE; gotmatch = FALSE; @@ -119,10 +131,6 @@ alias() { if (gotmatch) { -# ifdef DEBUG - if (Debug) - printf(" ... also aliased to %s", line); -# endif sendto(line, 1); } continue; @@ -160,6 +168,28 @@ alias() } if (q != NULL) { +#else DBM + /* + ** Scan SendQ + ** We pass through the queue several times. Didalias tells + ** us if we took some alias on this pass through the queue; + ** when it goes false at the top of the loop we don't have + ** to scan any more. + */ + + do + { + didalias = FALSE; + /* Scan SendQ for that canonical form. */ + for (q = &SendQ; (q = nxtinq(q)) != NULL; ) + { + lhs.dptr = q -> q_paddr; + lhs.dsize = strlen(lhs.dptr)+1; + rhs = fetch(lhs); + p = rhs.dptr; + if (p != NULL) + { +#endif /* ** Match on Alias. ** Deliver to the target list. @@ -180,8 +210,10 @@ alias() sendto(p, 1); } } - } + } while (didalias); +#ifndef DBM fclose(af); +#endif } /* ** FORWARD -- Try to forward mail diff --git a/usr/src/usr.sbin/sendmail/src/deliver.c b/usr/src/usr.sbin/sendmail/src/deliver.c index 8df64112be..f6dc68d969 100644 --- a/usr/src/usr.sbin/sendmail/src/deliver.c +++ b/usr/src/usr.sbin/sendmail/src/deliver.c @@ -6,7 +6,7 @@ # include # endif LOG -static char SccsId[] = "@(#)deliver.c 1.5 %G%"; +static char SccsId[] = "@(#)deliver.c 1.6 %G%"; /* ** DELIVER -- Deliver a message to a particular address. @@ -182,7 +182,11 @@ deliver(to, editfcn) syserr("pipe"); return (-1); } +# ifdef VFORK + pid = vfork(); +# else pid = fork(); +# endif if (pid < 0) { syserr("Cannot fork"); @@ -213,7 +217,20 @@ deliver(to, editfcn) # ifdef LOG initlog(NULL, 0, LOG_CLOSE); # endif LOG +# ifndef VFORK + /* + * We have to be careful with vfork - we can't mung up the + * memory but we don't want the mailer to inherit any extra + * open files. Chances are the mailer won't + * care about an extra file, but then again you never know. + * Actually, we would like to close(fileno(pwf)), but it's + * declared static so we can't. But if we fclose(pwf), which + * is what endpwent does, it closes it in the parent too and + * the next getpwnam will be slower. If you have a weird mailer + * that chokes on the extra file you should do the endpwent(). + */ endpwent(); +# endif execv(m->m_mailer, pvp); /* syserr fails because log is closed */ /* syserr("Cannot exec %s", m->m_mailer); */ -- 2.20.1