global error handling; fix problem leaving incoming SMTP connection
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 17 Jul 1993 01:33:15 +0000 (17:33 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 17 Jul 1993 01:33:15 +0000 (17:33 -0800)
in FIN_WAIT_2 for extended periods; bug in -X setvbuf call

SCCS-vsn: usr.sbin/sendmail/src/main.c 8.4

usr/src/usr.sbin/sendmail/src/main.c

index 338cade..8f7895f 100644 (file)
@@ -13,7 +13,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     8.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     8.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #define        _DEFINE
 #endif /* not lint */
 
 #define        _DEFINE
@@ -29,7 +29,7 @@ static char sccsid[] = "@(#)main.c    8.3 (Berkeley) %G%";
 
 # ifdef lint
 char   edata, end;
 
 # ifdef lint
 char   edata, end;
-# endif lint
+# endif /* lint */
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -540,7 +540,7 @@ main(argc, argv, envp)
                                break;
                        }
 #ifdef HASSETVBUF
                                break;
                        }
 #ifdef HASSETVBUF
-                       setvbuf(TrafficLogFile, NULL, _IOLBF, BUFSIZ);
+                       setvbuf(TrafficLogFile, NULL, _IOLBF, 0);
 #else
                        setlinebuf(TrafficLogFile);
 #endif
 #else
                        setlinebuf(TrafficLogFile);
 #endif
@@ -896,7 +896,7 @@ main(argc, argv, envp)
                                exit(0);
 
                        /* disconnect from our controlling tty */
                                exit(0);
 
                        /* disconnect from our controlling tty */
-                       disconnect(TRUE, CurEnv);
+                       disconnect(2, CurEnv);
                }
 
                dtype[0] = '\0';
                }
 
                dtype[0] = '\0';
@@ -972,6 +972,7 @@ main(argc, argv, envp)
 
        if (*av == NULL && !GrabTo)
        {
 
        if (*av == NULL && !GrabTo)
        {
+               CurEnv->e_flags |= EF_GLOBALERRS;
                usrerr("Recipient names must be specified");
 
                /* collect body for UUCP return */
                usrerr("Recipient names must be specified");
 
                /* collect body for UUCP return */
@@ -1001,7 +1002,10 @@ main(argc, argv, envp)
 
        CurEnv->e_to = NULL;
        if (OpMode != MD_VERIFY || GrabTo)
 
        CurEnv->e_to = NULL;
        if (OpMode != MD_VERIFY || GrabTo)
+       {
+               CurEnv->e_flags |= EF_GLOBALERRS;
                collect(FALSE, FALSE, CurEnv);
                collect(FALSE, FALSE, CurEnv);
+       }
        errno = 0;
 
        /* collect statistics */
        errno = 0;
 
        /* collect statistics */
@@ -1352,11 +1356,13 @@ thaw(freezefile, binfile)
 **  DISCONNECT -- remove our connection with any foreground process
 **
 **     Parameters:
 **  DISCONNECT -- remove our connection with any foreground process
 **
 **     Parameters:
-**             fulldrop -- if set, we should also drop the controlling
-**                     TTY if possible -- this should only be done when
-**                     setting up the daemon since otherwise UUCP can
-**                     leave us trying to open a dialin, and we will
-**                     wait for the carrier.
+**             droplev -- how "deeply" we should drop the line.
+**                     0 -- ignore signals, mail back errors, make sure
+**                          output goes to stdout.
+**                     1 -- also, make stdout go to transcript.
+**                     2 -- also, disconnect from controlling terminal
+**                          (only for daemon mode).
+**             e -- the current envelope.
 **
 **     Returns:
 **             none
 **
 **     Returns:
 **             none
@@ -1366,8 +1372,8 @@ thaw(freezefile, binfile)
 **             the controlling tty.
 */
 
 **             the controlling tty.
 */
 
-disconnect(fulldrop, e)
-       bool fulldrop;
+disconnect(droplev, e)
+       int droplev;
        register ENVELOPE *e;
 {
        int fd;
        register ENVELOPE *e;
 {
        int fd;
@@ -1405,18 +1411,21 @@ disconnect(fulldrop, e)
                (void) fclose(OutChannel);
                OutChannel = stdout;
        }
                (void) fclose(OutChannel);
                OutChannel = stdout;
        }
-       if (e->e_xfp == NULL)
-               fd = open("/dev/null", O_WRONLY, 0666);
-       else
-               fd = fileno(e->e_xfp);
-       (void) fflush(stdout);
-       dup2(fd, STDOUT_FILENO);
-       dup2(fd, STDERR_FILENO);
-       if (e->e_xfp == NULL)
-               close(fd);
+       if (droplev > 0)
+       {
+               if (e->e_xfp == NULL)
+                       fd = open("/dev/null", O_WRONLY, 0666);
+               else
+                       fd = fileno(e->e_xfp);
+               (void) fflush(stdout);
+               dup2(fd, STDOUT_FILENO);
+               dup2(fd, STDERR_FILENO);
+               if (e->e_xfp == NULL)
+                       close(fd);
+       }
 
        /* drop our controlling TTY completely if possible */
 
        /* drop our controlling TTY completely if possible */
-       if (fulldrop)
+       if (droplev > 1)
        {
                (void) setsid();
 #ifdef TIOCNOTTY
        {
                (void) setsid();
 #ifdef TIOCNOTTY