xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 7957)
13311Seric # include "sendmail.h"
2295Seric 
3*7957Seric SCCSID(@(#)err.c	3.29		08/29/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 {
34*7957Seric 	extern char Arpa_PSyserr[];
35*7957Seric 	extern char Arpa_TSyserr[];
36*7957Seric 	register char *p;
37295Seric 
387525Seric 	/* format and output the error message */
39*7957Seric 	if (errno == 0)
40*7957Seric 		p = Arpa_PSyserr;
41*7957Seric 	else
42*7957Seric 		p = Arpa_TSyserr;
43*7957Seric 	fmtmsg(MsgBuf, (char *) NULL, p, fmt, a, b, c, d, e);
447613Seric 	putmsg(MsgBuf);
454063Seric 
467525Seric 	/* mark the error as having occured */
471514Seric 	Errors++;
486048Seric 	FatalErrors = TRUE;
49295Seric 
50295Seric 	/* determine exit status if not already set */
51295Seric 	if (ExitStat == EX_OK)
52295Seric 	{
53295Seric 		if (errno == 0)
54295Seric 			ExitStat = EX_SOFTWARE;
55295Seric 		else
561598Seric 			ExitStat = EX_OSERR;
57295Seric 	}
58295Seric 
597810Seric 	(void) queuename(CurEnv, '\0');
60295Seric # ifdef LOG
617674Seric 	if (LogLevel > 0)
627810Seric 		syslog(LOG_ERR, "%s: %s", CurEnv->e_id, &MsgBuf[4]);
63295Seric # endif LOG
64295Seric 	errno = 0;
657762Seric 	if (QuickAbort)
667762Seric 		longjmp(TopFrame, 2);
67295Seric }
68295Seric /*
69295Seric **  USRERR -- Signal user error.
70295Seric **
71295Seric **	This is much like syserr except it is for user errors.
72295Seric **
73295Seric **	Parameters:
74295Seric **		fmt, a, b, c, d -- printf strings
75295Seric **
76295Seric **	Returns:
774084Seric **		none
787762Seric **		Through TopFrame if QuickAbort is set.
79295Seric **
80295Seric **	Side Effects:
811514Seric **		increments Errors.
82295Seric */
83295Seric 
84295Seric /*VARARGS1*/
85295Seric usrerr(fmt, a, b, c, d, e)
86295Seric 	char *fmt;
87295Seric {
88295Seric 	extern char SuprErrs;
894167Seric 	extern char Arpa_Usrerr[];
90295Seric 
91295Seric 	if (SuprErrs)
924084Seric 		return;
934063Seric 	Errors++;
946048Seric 	FatalErrors = TRUE;
95295Seric 
967613Seric 	fmtmsg(MsgBuf, CurEnv->e_to, Arpa_Usrerr, fmt, a, b, c, d, e);
977613Seric 	putmsg(MsgBuf);
987762Seric 	if (QuickAbort)
997762Seric 		longjmp(TopFrame, 1);
1004063Seric }
1014063Seric /*
1024063Seric **  MESSAGE -- print message (not necessarily an error)
1034063Seric **
1044063Seric **	Parameters:
1054063Seric **		num -- the default ARPANET error number (in ascii)
1064063Seric **		msg -- the message (printf fmt) -- if it begins
1074063Seric **			with a digit, this number overrides num.
1084063Seric **		a, b, c, d, e -- printf arguments
1094063Seric **
1104063Seric **	Returns:
1114063Seric **		none
1124063Seric **
1134063Seric **	Side Effects:
1144063Seric **		none.
1154063Seric */
1164063Seric 
1174084Seric /*VARARGS2*/
1184063Seric message(num, msg, a, b, c, d, e)
1194063Seric 	register char *num;
1204063Seric 	register char *msg;
1214063Seric {
1224711Seric 	errno = 0;
1237525Seric 	fmtmsg(MsgBuf, CurEnv->e_to, num, msg, a, b, c, d, e);
1247613Seric 	putmsg(MsgBuf);
1257613Seric }
1267613Seric /*
1277613Seric **  PUTMSG -- output error message to transcript and channel
1287613Seric **
1297613Seric **	Parameters:
1307613Seric **		msg -- message to output (in SMTP format).
1317613Seric **
1327613Seric **	Returns:
1337613Seric **		none.
1347613Seric **
1357613Seric **	Side Effects:
1367613Seric **		Outputs msg to the transcript.
1377613Seric **		If appropriate, outputs it to the channel.
1387613Seric **		Deletes SMTP reply code number as appropriate.
1397613Seric */
1404711Seric 
1417613Seric putmsg(msg)
1427613Seric 	char *msg;
1437613Seric {
1444711Seric 	/* output to transcript */
1457613Seric 	fprintf(Xscript, "%s\n", Smtp ? msg : &msg[4]);
1464711Seric 
1474711Seric 	/* output to channel if appropriate */
1487613Seric 	if (!HoldErrs && (Verbose || msg[0] != '0'))
1494063Seric 	{
1507275Seric 		(void) fflush(stdout);
1514711Seric 		if (ArpaMode)
1527613Seric 			fprintf(OutChannel, "%s\r\n", msg);
1534711Seric 		else
1547613Seric 			fprintf(OutChannel, "%s\n", &msg[4]);
1554711Seric 		(void) fflush(OutChannel);
1564063Seric 	}
1574711Seric }
1584711Seric /*
1594711Seric **  FMTMSG -- format a message into buffer.
1604711Seric **
1614711Seric **	Parameters:
1624711Seric **		eb -- error buffer to get result.
1634711Seric **		to -- the recipient tag for this message.
1644711Seric **		num -- arpanet error number.
1654711Seric **		fmt -- format of string.
1664711Seric **		a, b, c, d, e -- arguments.
1674711Seric **
1684711Seric **	Returns:
1694711Seric **		none.
1704711Seric **
1714711Seric **	Side Effects:
1724711Seric **		none.
1734711Seric */
1744063Seric 
1754834Seric /*VARARGS4*/
1764711Seric static
1774711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e)
1784711Seric 	register char *eb;
1794711Seric 	char *to;
1804711Seric 	char *num;
1814711Seric 	char *fmt;
1824711Seric {
1834711Seric 	char del;
1844711Seric 
1854711Seric 	/* output the reply code */
1864711Seric 	if (isdigit(*fmt))
1874577Seric 	{
1884711Seric 		num = fmt;
1894711Seric 		fmt += 4;
1904711Seric 	}
1914711Seric 	if (num[3] == '-')
1924711Seric 		del = '-';
1934711Seric 	else
1944711Seric 		del = ' ';
1954711Seric 	(void) sprintf(eb, "%3.3s%c", num, del);
1964711Seric 	eb += 4;
1974063Seric 
1984711Seric 	/* output the "to" person */
1994711Seric 	if (to != NULL && to[0] != '\0')
2004711Seric 	{
2014711Seric 		(void) sprintf(eb, "%s... ", to);
2025201Seric 		while (*eb != '\0')
2035201Seric 			*eb++ &= 0177;
2044711Seric 	}
2054711Seric 
2064711Seric 	/* output the message */
2074711Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
2085201Seric 	while (*eb != '\0')
2095201Seric 		*eb++ &= 0177;
2104711Seric 
2114711Seric 	/* output the error code, if any */
2124711Seric 	if (errno != 0)
2134711Seric 	{
2144711Seric 		extern int sys_nerr;
2154711Seric 		extern char *sys_errlist[];
2164711Seric 		if (errno < sys_nerr && errno > 0)
2174711Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
2184577Seric 		else
2194711Seric 			(void) sprintf(eb, ": error %d", errno);
2204711Seric 		eb += strlen(eb);
2214577Seric 	}
222295Seric }
223