attempts to handle ENFILE conditions better
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Thu, 18 Mar 1993 02:35:24 +0000 (18:35 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Thu, 18 Mar 1993 02:35:24 +0000 (18:35 -0800)
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 6.29
SCCS-vsn: usr.sbin/sendmail/src/main.c 6.39
SCCS-vsn: usr.sbin/sendmail/src/err.c 6.8
SCCS-vsn: usr.sbin/sendmail/src/collect.c 6.10
SCCS-vsn: usr.sbin/sendmail/src/queue.c 6.28

usr/src/usr.sbin/sendmail/src/collect.c
usr/src/usr.sbin/sendmail/src/err.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/queue.c
usr/src/usr.sbin/sendmail/src/recipient.c

index 3f230e0..61ddf87 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)collect.c  6.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)collect.c  6.10 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <errno.h>
 #endif /* not lint */
 
 # include <errno.h>
@@ -299,7 +299,11 @@ readerr:
        }
 
        if ((e->e_dfp = fopen(e->e_df, "r")) == NULL)
        }
 
        if ((e->e_dfp = fopen(e->e_df, "r")) == NULL)
+       {
+               /* we haven't acked receipt yet, so just chuck this */
                syserr("Cannot reopen %s", e->e_df);
                syserr("Cannot reopen %s", e->e_df);
+               finis();
+       }
 }
 \f/*
 **  FLUSHEOL -- if not at EOL, throw away rest of input line.
 }
 \f/*
 **  FLUSHEOL -- if not at EOL, throw away rest of input line.
index 0645fd9..ed68064 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)err.c      6.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)err.c      6.8 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -20,6 +20,11 @@ static char sccsid[] = "@(#)err.c    6.7 (Berkeley) %G%";
 **     Prints an error message via printf to the diagnostic
 **     output.  If LOG is defined, it logs it also.
 **
 **     Prints an error message via printf to the diagnostic
 **     output.  If LOG is defined, it logs it also.
 **
+**     If the first character of the syserr message is `!' it will
+**     log this as an ALERT message and exit immediately.  This can
+**     leave queue files in an indeterminate state, so it should not
+**     be used lightly.
+**
 **     Parameters:
 **             f -- the format string
 **             a, b, c, d, e -- parameters
 **     Parameters:
 **             f -- the format string
 **             a, b, c, d, e -- parameters
@@ -52,8 +57,13 @@ syserr(fmt, va_alist)
 {
        register char *p;
        int olderrno = errno;
 {
        register char *p;
        int olderrno = errno;
+       bool panic;
        VA_LOCAL_DECL
 
        VA_LOCAL_DECL
 
+       panic = *fmt == '!';
+       if (panic)
+               fmt++;
+
        /* format and output the error message */
        if (olderrno == 0)
                p = "554";
        /* format and output the error message */
        if (olderrno == 0)
                p = "554";
@@ -75,10 +85,12 @@ syserr(fmt, va_alist)
 
 # ifdef LOG
        if (LogLevel > 0)
 
 # ifdef LOG
        if (LogLevel > 0)
-               syslog(LOG_CRIT, "%s: SYSERR: %s",
+               syslog(panic ? LOG_ALERT : LOG_CRIT, "%s: SYSERR: %s",
                        CurEnv->e_id == NULL ? "NOQUEUE" : CurEnv->e_id,
                        &MsgBuf[4]);
 # endif /* LOG */
                        CurEnv->e_id == NULL ? "NOQUEUE" : CurEnv->e_id,
                        &MsgBuf[4]);
 # endif /* LOG */
+       if (panic)
+               exit(EX_OSERR);
        errno = 0;
        if (QuickAbort)
                longjmp(TopFrame, 2);
        errno = 0;
        if (QuickAbort)
                longjmp(TopFrame, 2);
index 7fb3989..dd9e7ff 100644 (file)
@@ -13,7 +13,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     6.38 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     6.39 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 #endif /* not lint */
 
 #define        _DEFINE
@@ -117,6 +117,7 @@ main(argc, argv, envp)
        bool safecf = TRUE;
        static bool reenter = FALSE;
        char *argv0 = argv[0];
        bool safecf = TRUE;
        static bool reenter = FALSE;
        char *argv0 = argv[0];
+       struct stat stb;
        char jbuf[MAXHOSTNAMELEN];      /* holds MyHostName */
        extern int DtableSize;
        extern int optind;
        char jbuf[MAXHOSTNAMELEN];      /* holds MyHostName */
        extern int DtableSize;
        extern int optind;
@@ -161,8 +162,13 @@ main(argc, argv, envp)
        */
 
        i = open("/dev/null", O_RDWR);
        */
 
        i = open("/dev/null", O_RDWR);
-       while (i >= 0 && i < 2)
-               i = dup(i);
+       if (fstat(STDIN_FILENO, &stb) < 0)
+               (void) dup2(i, STDIN_FILENO);
+       if (fstat(STDOUT_FILENO, &stb) < 0)
+               (void) dup2(i, STDOUT_FILENO);
+       if (fstat(STDERR_FILENO, &stb) < 0)
+               (void) dup2(i, STDERR_FILENO);
+       (void) close(i);
 
        i = DtableSize;
        while (--i > 0)
 
        i = DtableSize;
        while (--i > 0)
index a24b290..b73dc50 100644 (file)
@@ -10,9 +10,9 @@
 
 #ifndef lint
 #ifdef QUEUE
 
 #ifndef lint
 #ifdef QUEUE
-static char sccsid[] = "@(#)queue.c    6.27 (Berkeley) %G% (with queueing)";
+static char sccsid[] = "@(#)queue.c    6.28 (Berkeley) %G% (with queueing)";
 #else
 #else
-static char sccsid[] = "@(#)queue.c    6.27 (Berkeley) %G% (without queueing)";
+static char sccsid[] = "@(#)queue.c    6.28 (Berkeley) %G% (without queueing)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -115,8 +115,7 @@ queueup(e, queueall, announce)
                        {
                                if (errno == EEXIST)
                                        continue;
                        {
                                if (errno == EEXIST)
                                        continue;
-                               syserr("queueup: cannot create temp file %s", tf);
-                               return;
+                               syserr("!queueup: cannot create temp file %s", tf);
                        }
 
                        if (lockfile(fd, tf, LOCK_EX|LOCK_NB))
                        }
 
                        if (lockfile(fd, tf, LOCK_EX|LOCK_NB))
@@ -143,12 +142,7 @@ queueup(e, queueall, announce)
                e->e_df = newstr(queuename(e, 'd'));
                fd = open(e->e_df, O_WRONLY|O_CREAT, FileMode);
                if (fd < 0)
                e->e_df = newstr(queuename(e, 'd'));
                fd = open(e->e_df, O_WRONLY|O_CREAT, FileMode);
                if (fd < 0)
-               {
-                       syserr("queueup: cannot create %s", e->e_df);
-                       if (!newid)
-                               (void) xfclose(tfp, "queueup tfp", e->e_id);
-                       return;
-               }
+                       syserr("!queueup: cannot create %s", e->e_df);
                dfp = fdopen(fd, "w");
                (*e->e_putbody)(dfp, ProgMailer, e);
                (void) xfclose(dfp, "queueup dfp", e->e_id);
                dfp = fdopen(fd, "w");
                (*e->e_putbody)(dfp, ProgMailer, e);
                (void) xfclose(dfp, "queueup dfp", e->e_id);
index c8915d2..9fcfbd1 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)recipient.c        6.28 (Berkeley) %G%";
+static char sccsid[] = "@(#)recipient.c        6.29 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -664,7 +664,16 @@ include(fname, forwarding, ctladdr, sendq, e)
                int ret = errno;
 
                clrevent(ev);
                int ret = errno;
 
                clrevent(ev);
-               usrerr("550 Cannot open %s: %s", fname, errstring(ret));
+               if (transienterror(ret))
+               {
+                       ctladdr->q_flags |= QQUEUEUP|QDONTSEND;
+                       errno = 0;
+                       usrerr("451 Cannot open %s: %s", fname, errstring(ret));
+               }
+               else
+               {
+                       usrerr("550 Cannot open %s: %s", fname, errstring(ret));
+               }
                return ret;
        }
 
                return ret;
        }