From: vixie@pa.dec.com (Paul A Vixie)
Newsgroups: comp.mail.mh,comp.mail.sendmail
Subject: Re: MH 6.8 sendmail/smtp uses "ONEX" (w. fix for IDA sendmail)
Date: 19 Dec 92 15:29:11
Organization: DEC Network Software Lab
Distribution: world
NNTP-Posting-Host: cognition.pa.dec.com
In-reply-to: paul@uxc.cso.uiuc.edu's message of Fri, 18 Dec 1992 04:36:30 GMT

In the October 1 release of King James Sendmail, we find in README.decwrl...

>option O (OO in .cf or -oO on command line) sets SynchRcv which is also set
>by SMTP's ONEX command; if set, we will not fork on MAIL FROM commands.  we
>(lovstrand and vixie) believe that we can recover the previous state without
>having to isolate ourselves to a subprocess. this has performance implications
>and also helps avoid the shared-input bug for brain-dead PC mailers that do
>not wait for result codes and instead fill up the TCP pipe with their entire
>conversation before reading back any result codes.

...and if you turn this on, sendmail never forks -- i.e., it does what ONEX
causes now, and has the side-effect that ONEX followed by multiple MAIL's is
not an error.  lennart and i chose "O" as the option to remind us of "ONEX";
this actually shipped with NeXT-Step 3.0 as far as I know.

Note that this has the effect of creating all the [qdtx]f[A-Z][A-Z]\d\d\d\d\d
files in the mail queue directory with the same \d\d\d\d\d (PID) field, which
is not a huge problem until you start using BSMTP or otherwise sending a lot
of transactions in the same session.  Finding out that you need to be creating
qfAL12345 requires 11 IO-intensive system calls.  This is not the average case
for us, so this is still a big performance win.  However, it's clear that more
thought (a lot more!) is needed.

Diffs follow.  Before you yell about the apparently-permanent effects of ONEX
on the global variable SynchRcv, think about which forks have _already_
happened by the time this code gets run.  Note, also, that these diffs are
very similar to Paul Pomes', and there's a reason for that :-)..

*** 1.8	1992/05/04 18:03:24
--- 1.9	1992/10/01 18:06:53
***************
*** 20,26 ****
  
  #ifndef lint
  static char sccsid[] = "@(#)readcf.c	5.21 (Berkeley) 6/1/90";
! static char rcsid[] = "$Id: readcf.c,v 1.8 1992/05/04 18:03:24 vixie Exp $";
  #endif /* not lint */
  
  # include "sendmail.h"
--- 20,26 ----
  
  #ifndef lint
  static char sccsid[] = "@(#)readcf.c	5.21 (Berkeley) 6/1/90";
! static char rcsid[] = "$Id: readcf.c,v 1.9 1992/10/01 18:06:53 vixie Exp $";
  #endif /* not lint */
  
  # include "sendmail.h"
***************
*** 701,706 ****
--- 701,707 ----
  	extern time_t convtime();
  	extern int QueueLA;
  	extern int RefuseLA;
+ 	extern bool SynchRcv;
  	extern bool trusteduser();
  	extern char *username();
  
***************
*** 901,906 ****
--- 902,911 ----
  			CurEnv->e_flags |= EF_OLDSTYLE;
  		else
  			CurEnv->e_flags &= ~EF_OLDSTYLE;
+ 		break;
+ 
+ 	  case 'O':		/* Do synchronous receive in srvrsmtp */
+ 		SynchRcv = atobool(val);
  		break;
  
  	  case 'P':		/* postmaster copy address for returned mail */
*** 1.8	1992/05/04 18:05:40
--- srvrsmtp.c	1992/10/01 18:07:49
***************
*** 25,36 ****
  static char sccsid[] =
    "@(#)srvrsmtp.c	5.28 (Berkeley) 6/1/90 (with SMTP)";
  static char rcsid[] =
!   "$Id: srvrsmtp.c,v 1.8 1992/05/04 18:05:40 vixie Exp $ (with SMTP)";
  #else
  static char sccsid[] =
    "@(#)srvrsmtp.c	5.28 (Berkeley) 6/1/90 (without SMTP)";
  static char rcsid[] =
!   "$Id: srvrsmtp.c,v 1.8 1992/05/04 18:05:40 vixie Exp $ (without SMTP)";
  #endif
  #endif /* not lint */
  
--- 25,36 ----
  static char sccsid[] =
    "@(#)srvrsmtp.c	5.28 (Berkeley) 6/1/90 (with SMTP)";
  static char rcsid[] =
!   "$Id: srvrsmtp.c,v 1.9 1992/10/01 18:07:49 vixie Exp $ (with SMTP)";
  #else
  static char sccsid[] =
    "@(#)srvrsmtp.c	5.28 (Berkeley) 6/1/90 (without SMTP)";
  static char rcsid[] =
!   "$Id: srvrsmtp.c,v 1.9 1992/10/01 18:07:49 vixie Exp $ (without SMTP)";
  #endif
  #endif /* not lint */
  
***************
*** 100,106 ****
  };
  
  bool	InChild = FALSE;		/* true if running in a subprocess */
! bool	OneXact = FALSE;		/* one xaction only this run */
  
  #define EX_QUIT		22		/* special code for QUIT command */
  
--- 100,106 ----
  };
  
  bool	InChild = FALSE;		/* true if running in a subprocess */
! bool	SynchRcv = FALSE;		/* one xaction only this run */
  
  #define EX_QUIT		22		/* special code for QUIT command */
  
***************
*** 398,403 ****
--- 398,411 ----
  			else
  				CurEnv->e_flags &= ~EF_FATALERRS;
  
+ 			/*FALLTHROUGH*/
+ 
+ 		  case CMDRSET:
+ 			if (c->cmdcode == CMDRSET) {
+ 				/* not a fallthrough from DATA */
+ 				message("250", "Reset state");
+ 			}
+ 
  			/* if in a child, pop back to our parent */
  			if (InChild) {
  #ifdef DECWRL
***************
*** 407,413 ****
  			}
  
  			/* clean up a bit */
! 			hasmail = 0;
  			dropenvelope(CurEnv);
  			CurEnv = newenvelope(CurEnv);
  			CurEnv->e_flags = BlankEnvelope.e_flags;
--- 415,421 ----
  			}
  
  			/* clean up a bit */
! 			hasmail = FALSE;
  			dropenvelope(CurEnv);
  			CurEnv = newenvelope(CurEnv);
  			CurEnv->e_flags = BlankEnvelope.e_flags;
***************
*** 416,427 ****
  #endif
  			break;
  
- 		  case CMDRSET:		/* rset -- reset state */
- 			message("250", "Reset state");
- 			if (InChild)
- 				finis();
- 			break;
- 
  		  case CMDVRFY:		/* vrfy -- verify address */
  #ifndef DECWRL
  			if (!batched && !runinchild("SMTP-VRFY") > 0)
--- 424,429 ----
***************
*** 491,497 ****
  			break;
  
  		  case CMDONEX:		/* doing one transaction only */
! 			OneXact = TRUE;
  			message("200", "Only one transaction");
  			break;
  
--- 493,499 ----
  			break;
  
  		  case CMDONEX:		/* doing one transaction only */
! 			SynchRcv = TRUE;
  			message("200", "Only one transaction");
  			break;
  
***************
*** 656,662 ****
  {
  	int childpid;
  
! 	if (!OneXact)
  	{
  		childpid = dofork();
  		if (childpid < 0)
--- 658,664 ----
  {
  	int childpid;
  
! 	if (!SynchRcv)
  	{
  		childpid = dofork();
  		if (childpid < 0)
--
Paul Vixie, DEC Network Systems Lab	
Palo Alto, California, USA         	"Don't be a rebel, or a conformist;
<vixie@pa.dec.com> decwrl!vixie		they're the same thing, anyway.  Find
<paul@vix.com>     vixie!paul		your own path, and stay on it."  -me