xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 4084)
1295Seric # include <stdio.h>
24063Seric # include <ctype.h>
33311Seric # include "sendmail.h"
4295Seric # ifdef LOG
52775Seric # include <syslog.h>
6295Seric # endif LOG
7295Seric 
8*4084Seric static char	SccsId[] = "@(#)err.c	3.6	08/09/81";
9406Seric 
10295Seric /*
111514Seric **  SYSERR -- Print error message.
12295Seric **
13295Seric **	Prints an error message via printf to the diagnostic
14295Seric **	output.  If LOG is defined, it logs it also.
15295Seric **
16295Seric **	Parameters:
17295Seric **		f -- the format string
18295Seric **		a, b, c, d, e -- parameters
19295Seric **
20295Seric **	Returns:
21*4084Seric **		none
22295Seric **
23295Seric **	Side Effects:
241514Seric **		increments Errors.
251514Seric **		sets ExitStat.
26295Seric */
27295Seric 
28*4084Seric # ifdef lint
29*4084Seric int	sys_nerr;
30*4084Seric char	*sys_errlist[];
31*4084Seric # endif lint
32*4084Seric 
33295Seric /*VARARGS1*/
34295Seric syserr(fmt, a, b, c, d, e)
35295Seric 	char *fmt;
36295Seric {
37295Seric 	static char errbuf[MAXLINE+1];
38295Seric 	extern char *sys_errlist[];
39295Seric 	extern int sys_nerr;
404063Seric 	register char *eb = errbuf;
41295Seric 
424063Seric 	/* add arpanet error number if not present */
434063Seric 	if (!isdigit(*fmt))
444063Seric 	{
45*4084Seric 		(void) strcpy(eb, "455 ");
464063Seric 		eb += 4;
474063Seric 	}
484063Seric 
494063Seric 	/* put error message into buffer */
50*4084Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
51295Seric 	if (errno != 0)
52295Seric 	{
534063Seric 		eb += strlen(eb);
54295Seric 		if (errno < sys_nerr && errno > 0)
55*4084Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
56295Seric 		else
57*4084Seric 			(void) sprintf(eb, ": error %d", errno);
58295Seric 	}
594063Seric 
604063Seric 	if (ArpaFmt)
614077Seric 		printf("%s\r\n", errbuf);
624063Seric 	else
634063Seric 		printf("sendmail: %s\n", &errbuf[4]);
64*4084Seric 	(void) fflush(stdout);
651514Seric 	Errors++;
66295Seric 
67295Seric 	/* determine exit status if not already set */
68295Seric 	if (ExitStat == EX_OK)
69295Seric 	{
70295Seric 		if (errno == 0)
71295Seric 			ExitStat = EX_SOFTWARE;
72295Seric 		else
731598Seric 			ExitStat = EX_OSERR;
74295Seric 	}
75295Seric 
76295Seric # ifdef LOG
772775Seric 	syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, errbuf);
78295Seric # endif LOG
79295Seric 	errno = 0;
80295Seric }
81295Seric /*
82295Seric **  USRERR -- Signal user error.
83295Seric **
84295Seric **	This is much like syserr except it is for user errors.
85295Seric **
86295Seric **	Parameters:
87295Seric **		fmt, a, b, c, d -- printf strings
88295Seric **
89295Seric **	Returns:
90*4084Seric **		none
91295Seric **
92295Seric **	Side Effects:
931514Seric **		increments Errors.
94295Seric */
95295Seric 
96295Seric /*VARARGS1*/
97295Seric usrerr(fmt, a, b, c, d, e)
98295Seric 	char *fmt;
99295Seric {
100295Seric 	extern char SuprErrs;
101295Seric 
102295Seric 	if (SuprErrs)
103*4084Seric 		return;
1044063Seric 	Errors++;
105295Seric 
1064063Seric 	message("450", fmt, a, b, c, d, e);
1074063Seric }
1084063Seric /*
1094063Seric **  MESSAGE -- print message (not necessarily an error)
1104063Seric **
1114063Seric **	Parameters:
1124063Seric **		num -- the default ARPANET error number (in ascii)
1134063Seric **		msg -- the message (printf fmt) -- if it begins
1144063Seric **			with a digit, this number overrides num.
1154063Seric **		a, b, c, d, e -- printf arguments
1164063Seric **
1174063Seric **	Returns:
1184063Seric **		none
1194063Seric **
1204063Seric **	Side Effects:
1214063Seric **		none.
1224063Seric */
1234063Seric 
124*4084Seric /*VARARGS2*/
1254063Seric message(num, msg, a, b, c, d, e)
1264063Seric 	register char *num;
1274063Seric 	register char *msg;
1284063Seric {
1294063Seric 	/* compute error number */
1304063Seric 	if (isdigit(*msg))
1314063Seric 	{
1324063Seric 		num = msg;
1334063Seric 		msg += 4;
1344063Seric 	}
1354063Seric 
1364063Seric 	/* print arpa format header if needed */
1374063Seric 	if (ArpaFmt)
1384063Seric 		printf("%.3s ", num);
1394063Seric 
1404063Seric 	if (To != NULL && To[0] != '\0')
141295Seric 		printf("%s... ", To);
1424063Seric 	printf(msg, a, b, c, d, e);
1434077Seric 	if (ArpaFmt)
1444077Seric 		printf("\r");
145295Seric 	printf("\n");
146*4084Seric 	(void) fflush(stdout);
147295Seric }
148