[comp.bugs.4bsd] error handling bug in sendoff

demizu@nff.ncl.omron.co.jp (DEMIZU Noritoshi) (05/04/91)

sendoff() defined in deliver.c calls openmailer().  If the return
value of openmailer() was negative, sendoff() returns -1.  This will
cause fatal error.  The E-mail will be sent back to sender.  But
openmailer() returns negative value even if the error is not fatal.
For example, when it failed to create pipe, or when it failed to fork.

So I think sendoff() returns ExitStat in stead of -1.  And the global
variable ExitStat should be set to have proper status in openmailer().

Excuse my English.

 --- DEMIZU Noritoshi    OMRON Corporation

=====================================================================
*** src/deliver.c.ORG	Sat May  4 14:32:51 1991
--- src/deliver.c	Sat May  4 14:33:45 1991
***************
*** 600,606 ****
  
  	pid = openmailer(m, pvp, ctladdr, FALSE, &mfile, &rfile);
  	if (pid < 0)
! 		return (-1);
  
  	/*
  	**  Format and send message.
--- 600,606 ----
  
  	pid = openmailer(m, pvp, ctladdr, FALSE, &mfile, &rfile);
  	if (pid < 0)
! 		return ExitStat;
  
  	/*
  	**  Format and send message.
***************
*** 799,804 ****
--- 799,805 ----
  	if (pipe(mpvect) < 0)
  	{
  		syserr("openmailer: pipe (to mailer)");
+ 		ExitStat = EX_TEMPFAIL;
  		return (-1);
  	}
  
***************
*** 809,814 ****
--- 810,816 ----
  		syserr("openmailer: pipe (from mailer)");
  		(void) close(mpvect[0]);
  		(void) close(mpvect[1]);
+ 		ExitStat = EX_TEMPFAIL;
  		return (-1);
  	}
  #endif SMTP
***************
*** 842,847 ****
--- 844,850 ----
  			(void) close(rpvect[1]);
  		}
  #endif SMTP
+ 		ExitStat = EX_TEMPFAIL;
  		return (-1);
  	}
  	else if (pid == 0)
*** support/getloadavg.c.ORG	Sat May  4 15:58:47 1991
--- support/getloadavg.c	Sat May  4 15:58:59 1991
***************
*** 42,47 ****
  			return (-1);
  	}
  	if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 ||
! 	    read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
  		return (-1);
  }
--- 42,47 ----
  			return (-1);
  	}
  	if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 ||
! 	    read(kmem, (char *) avenrun, sizeof(*avenrun)) < sizeof(*avenrun))
  		return (-1);
  }
=====================================================================
--
;  DEMIZU, Noritoshi		OMRON Computer Systems R&D laboratory
;  demizu@nff.ncl.omron.co.jp	tel: 075-951-5111  fax: 075-956-7403

e07@nikhefh.nikhef.nl (Eric Wassenaar) (05/07/91)

In article <DEMIZU.91May4162444@freezer.nff.ncl.omron.co.jp>, demizu@nff.ncl.omron.co.jp (DEMIZU Noritoshi) writes:
> So I think sendoff() returns ExitStat in stead of -1.  And the global
> variable ExitStat should be set to have proper status in openmailer().

sendoff() should indeed return ExitStat instead of -1 if the call
to openmailer() fails.
However, openmailer() will already have stored a proper status
in ExitStat because it calls syserr() before failing, and syserr()
sets ExitStat to EX_OSERR or EX_SOFTWARE.
It makes sense though, to override this by EX_TEMPFAIL in case of
a failing fork().

Eric Wassenaar
-- 
Organization: NIKHEF-H, National Institute for Nuclear and High-Energy Physics
Address: Kruislaan 409, P.O. Box 41882, 1009 DB Amsterdam, the Netherlands
Phone: +31 20 592 0412, Home: +31 20 6909449, Telefax: +31 20 592 5155
Internet: e07@nikhef.nl

rickert@mp.cs.niu.edu (Neil Rickert) (05/07/91)

In article <1225@nikhefh.nikhef.nl> e07@nikhefh.nikhef.nl (Eric Wassenaar) writes:
>However, openmailer() will already have stored a proper status
>in ExitStat because it calls syserr() before failing, and syserr()
>sets ExitStat to EX_OSERR or EX_SOFTWARE.
>It makes sense though, to override this by EX_TEMPFAIL in case of
>a failing fork().

 Why exactly does this make sense?  EX_OSERR already causes the message to
be requeued, so what is the benefit of changing toe EX_TEMPFAIL ?

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115                                   +1-815-753-6940

e07@nikhefh.nikhef.nl (Eric Wassenaar) (05/07/91)

In article <1991May7.114948.16201@mp.cs.niu.edu>, rickert@mp.cs.niu.edu (Neil Rickert) writes:
> In article <1225@nikhefh.nikhef.nl> e07@nikhefh.nikhef.nl (Eric Wassenaar) writes:
> > It makes sense though, to override this by EX_TEMPFAIL in case of
> > a failing fork().
> Why exactly does this make sense?  EX_OSERR already causes the message to
> be requeued, so what is the benefit of changing toe EX_TEMPFAIL ?

Because unfortunately I was looking at an old version of sendmail,
in which messages were requeued by markfailure() only for EX_TEMPFAIL.
The latest versions indeed will requeue on status codes EX_TEMPFAIL,
EX_IOERR, and EX_OSERR in markfailure().

Eric Wassenaar
-- 
Organization: NIKHEF-H, National Institute for Nuclear and High-Energy Physics
Address: Kruislaan 409, P.O. Box 41882, 1009 DB Amsterdam, the Netherlands
Phone: +31 20 592 0412, Home: +31 20 6909449, Telefax: +31 20 592 5155
Internet: e07@nikhef.nl

demizu@nff.ncl.omron.co.jp (DEMIZU Noritoshi) (05/18/91)

In article <1227@nikhefh.nikhef.nl>
	e07@nikhefh.nikhef.nl (Eric Wassenaar) writes:

 |Because unfortunately I was looking at an old version of sendmail,
 |in which messages were requeued by markfailure() only for EX_TEMPFAIL.
 |The latest versions indeed will requeue on status codes EX_TEMPFAIL,
 |EX_IOERR, and EX_OSERR in markfailure().

I should say again that I did not check sendmail 5.65 source code
carefully.  I only looked at 5.61 source code.

I'll post patch again to avoid confusion.  Is this correct patch?

 --- DEMIZU Noritoshi    OMRON Corporation

=====================================================================
*** src/deliver.c.ORG	Sat May  4 14:32:51 1991
--- src/deliver.c	Sat May  4 14:33:45 1991
***************
*** 600,606 ****
  
  	pid = openmailer(m, pvp, ctladdr, FALSE, &mfile, &rfile);
  	if (pid < 0)
! 		return (-1);
  
  	/*
  	**  Format and send message.
--- 600,606 ----
  
  	pid = openmailer(m, pvp, ctladdr, FALSE, &mfile, &rfile);
  	if (pid < 0)
! 		return ExitStat;
  
  	/*
  	**  Format and send message.
*** support/getloadavg.c.ORG	Sat May  4 15:58:47 1991
--- support/getloadavg.c	Sat May  4 15:58:59 1991
***************
*** 42,47 ****
  			return (-1);
  	}
  	if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 ||
! 	    read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
  		return (-1);
  }
--- 42,47 ----
  			return (-1);
  	}
  	if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, 0) == -1 ||
! 	    read(kmem, (char *) avenrun, sizeof(*avenrun)) < sizeof(*avenrun))
  		return (-1);
  }
=====================================================================
--
;  DEMIZU, Noritoshi		OMRON Computer Systems R&D laboratory
;  demizu@nff.ncl.omron.co.jp	tel: 075-951-5111  fax: 075-956-7403