[comp.mail.sendmail] sendmail generates bogus error messages

wisner@zug.AI.MIT.EDU (Bill Wisner) (10/02/88)

When sending mail to a host that isn't currently reachable, I should
be seeing error messages like

  Deferred: Connection timed out during user open with basel.ai.mit.edu

Instead, I get this:

  Deferred: Not a typewriter

I think that somewhere between the time the connection actually times
out and the time the error message is generated, something happens to
change errno to ENOTTY. But what? Anyone know how to fix this?

dsc@izimbra.CSS.GOV (card carrying aclu member) (10/04/88)

In article <3153@hermes.ai.mit.edu> wisner@zug.AI.MIT.EDU (Bill Wisner) writes:
>When sending mail to a host that isn't currently reachable, I should
>be seeing error messages like
>  Deferred: Connection timed out during user open with basel.ai.mit.edu
>Instead, I get this:
>  Deferred: Not a typewriter
>I think that somewhere between the time the connection actually times
>out and the time the error message is generated, something happens to
>change errno to ENOTTY. But what? Anyone know how to fix this?

i believe the problem you are seeing is that errno gets clobbered
during a fprintf() call in usersmtp.c.  look in smtpinit() for the
fprintf() call where one of the arguments is errstring(errno) and add
two assignments to save & restore errno before calling fprintf, ala

				r = errno;
  				fprintf(CurEnv->e_xfp,
  					"421 %s.%s... Deferred: %s\n",
  					pvp[1], m->m_name, errstring(errno));
				errno = r;

of course, why errno is getting set to ENOTTY or some other value by
fprintf is in itself an interesting question ...

dsc

chris@mimsy.UUCP (Chris Torek) (10/05/88)

-In article <3153@hermes.ai.mit.edu> wisner@zug.AI.MIT.EDU (Bill Wisner) writes:
->... I should be seeing error messages like
->  Deferred: Connection timed out during user open with basel.ai.mit.edu
->Instead, I get this:
->  Deferred: Not a typewriter

In article <30999@uunet.UU.NET> dsc@izimbra.CSS.GOV
(card carrying aclu member) writes:
-i believe the problem you are seeing is that errno gets clobbered
-during a fprintf() call in usersmtp.c.  look in smtpinit() for the
-fprintf() call where one of the arguments is errstring(errno) and add
-two assignments to save & restore errno before calling fprintf, ala
-
-				r = errno;
-  				fprintf(CurEnv->e_xfp,
-  					"421 %s.%s... Deferred: %s\n",
-  					pvp[1], m->m_name, errstring(errno));
-				errno = r;

This will work, but there are other fixes.

-of course, why errno is getting set to ENOTTY or some other value by
-fprintf is in itself an interesting question ...

fprintf calls isatty when printing the first character to a FILE.
isatty calls ioctl(fd, TIOCGETP) and checks for errors.  TIOCGETP
succeeds only on terminals.  The error, of course, is ENOTTY.

I fixed(?) this by changing the C library routine isatty() to itself
save and restore errno; but a proper program should never check errno
except immediately after a failing system call.  A better fix to
sendmail itself (with or without the change in the C library) is to
have it retain the error number (or string) in the envelope structure.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris