xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 7810)
13311Seric # include "sendmail.h"
2295Seric 
3*7810Seric SCCSID(@(#)err.c	3.28		08/22/82);
4406Seric 
5295Seric /*
61514Seric **  SYSERR -- Print error message.
7295Seric **
8295Seric **	Prints an error message via printf to the diagnostic
9295Seric **	output.  If LOG is defined, it logs it also.
10295Seric **
11295Seric **	Parameters:
12295Seric **		f -- the format string
13295Seric **		a, b, c, d, e -- parameters
14295Seric **
15295Seric **	Returns:
164084Seric **		none
177762Seric **		Through TopFrame if QuickAbort is set.
18295Seric **
19295Seric **	Side Effects:
201514Seric **		increments Errors.
211514Seric **		sets ExitStat.
22295Seric */
23295Seric 
244084Seric # ifdef lint
254084Seric int	sys_nerr;
264084Seric char	*sys_errlist[];
274084Seric # endif lint
287525Seric static char	MsgBuf[BUFSIZ*2];	/* text of most recent message */
294084Seric 
30295Seric /*VARARGS1*/
31295Seric syserr(fmt, a, b, c, d, e)
32295Seric 	char *fmt;
33295Seric {
344167Seric 	extern char Arpa_Syserr[];
35295Seric 
367525Seric 	/* format and output the error message */
377674Seric 	fmtmsg(MsgBuf, (char *) NULL, Arpa_Syserr, fmt, a, b, c, d, e);
387613Seric 	putmsg(MsgBuf);
394063Seric 
407525Seric 	/* mark the error as having occured */
411514Seric 	Errors++;
426048Seric 	FatalErrors = TRUE;
43295Seric 
44295Seric 	/* determine exit status if not already set */
45295Seric 	if (ExitStat == EX_OK)
46295Seric 	{
47295Seric 		if (errno == 0)
48295Seric 			ExitStat = EX_SOFTWARE;
49295Seric 		else
501598Seric 			ExitStat = EX_OSERR;
51295Seric 	}
52295Seric 
53*7810Seric 	(void) queuename(CurEnv, '\0');
54295Seric # ifdef LOG
557674Seric 	if (LogLevel > 0)
56*7810Seric 		syslog(LOG_ERR, "%s: %s", CurEnv->e_id, &MsgBuf[4]);
57295Seric # endif LOG
58295Seric 	errno = 0;
597762Seric 	if (QuickAbort)
607762Seric 		longjmp(TopFrame, 2);
61295Seric }
62295Seric /*
63295Seric **  USRERR -- Signal user error.
64295Seric **
65295Seric **	This is much like syserr except it is for user errors.
66295Seric **
67295Seric **	Parameters:
68295Seric **		fmt, a, b, c, d -- printf strings
69295Seric **
70295Seric **	Returns:
714084Seric **		none
727762Seric **		Through TopFrame if QuickAbort is set.
73295Seric **
74295Seric **	Side Effects:
751514Seric **		increments Errors.
76295Seric */
77295Seric 
78295Seric /*VARARGS1*/
79295Seric usrerr(fmt, a, b, c, d, e)
80295Seric 	char *fmt;
81295Seric {
82295Seric 	extern char SuprErrs;
834167Seric 	extern char Arpa_Usrerr[];
84295Seric 
85295Seric 	if (SuprErrs)
864084Seric 		return;
874063Seric 	Errors++;
886048Seric 	FatalErrors = TRUE;
89295Seric 
907613Seric 	fmtmsg(MsgBuf, CurEnv->e_to, Arpa_Usrerr, fmt, a, b, c, d, e);
917613Seric 	putmsg(MsgBuf);
927762Seric 	if (QuickAbort)
937762Seric 		longjmp(TopFrame, 1);
944063Seric }
954063Seric /*
964063Seric **  MESSAGE -- print message (not necessarily an error)
974063Seric **
984063Seric **	Parameters:
994063Seric **		num -- the default ARPANET error number (in ascii)
1004063Seric **		msg -- the message (printf fmt) -- if it begins
1014063Seric **			with a digit, this number overrides num.
1024063Seric **		a, b, c, d, e -- printf arguments
1034063Seric **
1044063Seric **	Returns:
1054063Seric **		none
1064063Seric **
1074063Seric **	Side Effects:
1084063Seric **		none.
1094063Seric */
1104063Seric 
1114084Seric /*VARARGS2*/
1124063Seric message(num, msg, a, b, c, d, e)
1134063Seric 	register char *num;
1144063Seric 	register char *msg;
1154063Seric {
1164711Seric 	errno = 0;
1177525Seric 	fmtmsg(MsgBuf, CurEnv->e_to, num, msg, a, b, c, d, e);
1187613Seric 	putmsg(MsgBuf);
1197613Seric }
1207613Seric /*
1217613Seric **  PUTMSG -- output error message to transcript and channel
1227613Seric **
1237613Seric **	Parameters:
1247613Seric **		msg -- message to output (in SMTP format).
1257613Seric **
1267613Seric **	Returns:
1277613Seric **		none.
1287613Seric **
1297613Seric **	Side Effects:
1307613Seric **		Outputs msg to the transcript.
1317613Seric **		If appropriate, outputs it to the channel.
1327613Seric **		Deletes SMTP reply code number as appropriate.
1337613Seric */
1344711Seric 
1357613Seric putmsg(msg)
1367613Seric 	char *msg;
1377613Seric {
1384711Seric 	/* output to transcript */
1397613Seric 	fprintf(Xscript, "%s\n", Smtp ? msg : &msg[4]);
1404711Seric 
1414711Seric 	/* output to channel if appropriate */
1427613Seric 	if (!HoldErrs && (Verbose || msg[0] != '0'))
1434063Seric 	{
1447275Seric 		(void) fflush(stdout);
1454711Seric 		if (ArpaMode)
1467613Seric 			fprintf(OutChannel, "%s\r\n", msg);
1474711Seric 		else
1487613Seric 			fprintf(OutChannel, "%s\n", &msg[4]);
1494711Seric 		(void) fflush(OutChannel);
1504063Seric 	}
1514711Seric }
1524711Seric /*
1534711Seric **  FMTMSG -- format a message into buffer.
1544711Seric **
1554711Seric **	Parameters:
1564711Seric **		eb -- error buffer to get result.
1574711Seric **		to -- the recipient tag for this message.
1584711Seric **		num -- arpanet error number.
1594711Seric **		fmt -- format of string.
1604711Seric **		a, b, c, d, e -- arguments.
1614711Seric **
1624711Seric **	Returns:
1634711Seric **		none.
1644711Seric **
1654711Seric **	Side Effects:
1664711Seric **		none.
1674711Seric */
1684063Seric 
1694834Seric /*VARARGS4*/
1704711Seric static
1714711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e)
1724711Seric 	register char *eb;
1734711Seric 	char *to;
1744711Seric 	char *num;
1754711Seric 	char *fmt;
1764711Seric {
1774711Seric 	char del;
1784711Seric 
1794711Seric 	/* output the reply code */
1804711Seric 	if (isdigit(*fmt))
1814577Seric 	{
1824711Seric 		num = fmt;
1834711Seric 		fmt += 4;
1844711Seric 	}
1854711Seric 	if (num[3] == '-')
1864711Seric 		del = '-';
1874711Seric 	else
1884711Seric 		del = ' ';
1894711Seric 	(void) sprintf(eb, "%3.3s%c", num, del);
1904711Seric 	eb += 4;
1914063Seric 
1924711Seric 	/* output the "to" person */
1934711Seric 	if (to != NULL && to[0] != '\0')
1944711Seric 	{
1954711Seric 		(void) sprintf(eb, "%s... ", to);
1965201Seric 		while (*eb != '\0')
1975201Seric 			*eb++ &= 0177;
1984711Seric 	}
1994711Seric 
2004711Seric 	/* output the message */
2014711Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
2025201Seric 	while (*eb != '\0')
2035201Seric 		*eb++ &= 0177;
2044711Seric 
2054711Seric 	/* output the error code, if any */
2064711Seric 	if (errno != 0)
2074711Seric 	{
2084711Seric 		extern int sys_nerr;
2094711Seric 		extern char *sys_errlist[];
2104711Seric 		if (errno < sys_nerr && errno > 0)
2114711Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
2124577Seric 		else
2134711Seric 			(void) sprintf(eb, ": error %d", errno);
2144711Seric 		eb += strlen(eb);
2154577Seric 	}
216295Seric }
217