additional debugging information for too many open files problem
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 18 Oct 1993 02:00:16 +0000 (18:00 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Mon, 18 Oct 1993 02:00:16 +0000 (18:00 -0800)
SCCS-vsn: usr.sbin/sendmail/src/err.c 8.11
SCCS-vsn: usr.sbin/sendmail/src/daemon.c 8.17
SCCS-vsn: usr.sbin/sendmail/src/util.c 8.12
SCCS-vsn: usr.sbin/sendmail/src/deliver.c 8.33

usr/src/usr.sbin/sendmail/src/daemon.c
usr/src/usr.sbin/sendmail/src/deliver.c
usr/src/usr.sbin/sendmail/src/err.c
usr/src/usr.sbin/sendmail/src/util.c

index 532c838..259883d 100644 (file)
@@ -12,9 +12,9 @@
 
 #ifndef lint
 #ifdef DAEMON
 
 #ifndef lint
 #ifdef DAEMON
-static char sccsid[] = "@(#)daemon.c   8.16 (Berkeley) %G% (with daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.17 (Berkeley) %G% (with daemon mode)";
 #else
 #else
-static char sccsid[] = "@(#)daemon.c   8.16 (Berkeley) %G% (without daemon mode)";
+static char sccsid[] = "@(#)daemon.c   8.17 (Berkeley) %G% (without daemon mode)";
 #endif
 #endif /* not lint */
 
 #endif
 #endif /* not lint */
 
@@ -467,7 +467,7 @@ gothostent:
        /* connection ok, put it into canonical form */
        if ((mci->mci_out = fdopen(s, "w")) == NULL ||
            (s = dup(s)) < 0 ||
        /* connection ok, put it into canonical form */
        if ((mci->mci_out = fdopen(s, "w")) == NULL ||
            (s = dup(s)) < 0 ||
-           (mci->mci_in = fdopen(dup(s), "r")) == NULL)
+           (mci->mci_in = fdopen(s, "r")) == NULL)
        {
                syserr("cannot open SMTP client channel, fd=%d", s);
                return EX_TEMPFAIL;
        {
                syserr("cannot open SMTP client channel, fd=%d", s);
                return EX_TEMPFAIL;
index 5ba7cc2..df60829 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)deliver.c  8.32 (Berkeley) %G%";
+static char sccsid[] = "@(#)deliver.c  8.33 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "sendmail.h"
 #endif /* not lint */
 
 #include "sendmail.h"
@@ -613,6 +613,8 @@ deliver(e, firstto)
        if (tTd(10, 1))
                printf("\n--deliver, mailer=%d, host=`%s', first user=`%s'\n",
                        m->m_mno, host, to->q_user);
        if (tTd(10, 1))
                printf("\n--deliver, mailer=%d, host=`%s', first user=`%s'\n",
                        m->m_mno, host, to->q_user);
+       if (tTd(10, 100))
+               printopenfds(FALSE);
 
        /*
        **  If this mailer is expensive, and if we don't want to make
 
        /*
        **  If this mailer is expensive, and if we don't want to make
index c43bfeb..3098d75 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)err.c      8.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)err.c      8.11 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -90,6 +90,8 @@ syserr(fmt, va_alist)
                        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 (olderrno == EMFILE)
+               printopenfds(TRUE);
        if (panic)
        {
 #ifdef XLA
        if (panic)
        {
 #ifdef XLA
index 613002e..568734d 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     8.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     8.12 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -1142,3 +1142,90 @@ checkfd012(where)
        }
 #endif /* XDEBUG */
 }
        }
 #endif /* XDEBUG */
 }
+\f/*
+**  PRINTOPENFDS -- print the open file descriptors (for debugging)
+**
+**     Parameters:
+**             logit -- if set, send output to syslog; otherwise
+**                     print for debugging.
+**
+**     Returns:
+**             none.
+*/
+
+#include <netdb.h>
+#include <arpa/inet.h>
+
+printopenfds(logit)
+       bool logit;
+{
+       register int fd;
+       struct stat st;
+       register struct hostent *hp;
+       register char *p;
+       char buf[200];
+       extern int DtableSize;
+
+       for (fd = 0; fd < DtableSize; fd++)
+       {
+               struct sockaddr_in sin;
+               auto int slen;
+
+               if (fstat(fd, &st) < 0)
+                       continue;
+
+               p = buf;
+               sprintf(p, "%3d: mode=%o: ", fd, st.st_mode);
+               p += strlen(p);
+               switch (st.st_mode & S_IFMT)
+               {
+                 case S_IFSOCK:
+                       sprintf(p, "SOCK ");
+                       p += strlen(p);
+                       slen = sizeof sin;
+                       if (getsockname(fd, (struct sockaddr *) &sin, &slen) < 0)
+                               sprintf(p, "(badsock)");
+                       else
+                       {
+                               hp = gethostbyaddr((char *) &sin.sin_addr, slen, AF_INET);
+                               sprintf(p, "%s/%d", hp == NULL ? inet_ntoa(sin.sin_addr)
+                                                          : hp->h_name, ntohs(sin.sin_port));
+                       }
+                       p += strlen(p);
+                       sprintf(p, "->");
+                       p += strlen(p);
+                       slen = sizeof sin;
+                       if (getpeername(fd, (struct sockaddr *) &sin, &slen) < 0)
+                               sprintf(p, "(badsock)");
+                       else
+                       {
+                               hp = gethostbyaddr((char *) &sin.sin_addr, slen, AF_INET);
+                               sprintf(p, "%s/%d", hp == NULL ? inet_ntoa(sin.sin_addr)
+                                                          : hp->h_name, ntohs(sin.sin_port));
+                       }
+                       break;
+
+                 case S_IFCHR:
+                       sprintf(p, "CHR: ");
+                       p += strlen(p);
+                       goto defprint;
+
+                 case S_IFBLK:
+                       sprintf(p, "BLK: ");
+                       p += strlen(p);
+                       goto defprint;
+
+                 default:
+defprint:
+                       sprintf(p, "rdev=%d/%d, ino=%d, nlink=%d, u/gid=%d/%d, size=%ld",
+                               major(st.st_rdev), minor(st.st_rdev), st.st_ino,
+                               st.st_nlink, st.st_uid, st.st_gid, st.st_size);
+                       break;
+               }
+
+               if (logit)
+                       syslog(LOG_INFO, "%s", buf);
+               else
+                       printf("%s\n", buf);
+       }
+}