xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 4167)
1295Seric # include <stdio.h>
24063Seric # include <ctype.h>
33311Seric # include "sendmail.h"
4295Seric # ifdef LOG
52775Seric # include <syslog.h>
6295Seric # endif LOG
7295Seric 
8*4167Seric static char	SccsId[] = "@(#)err.c	3.8	08/18/81";
9406Seric 
104162Seric extern bool	HasXscrpt;
114162Seric 
12295Seric /*
131514Seric **  SYSERR -- Print error message.
14295Seric **
15295Seric **	Prints an error message via printf to the diagnostic
16295Seric **	output.  If LOG is defined, it logs it also.
17295Seric **
18295Seric **	Parameters:
19295Seric **		f -- the format string
20295Seric **		a, b, c, d, e -- parameters
21295Seric **
22295Seric **	Returns:
234084Seric **		none
24295Seric **
25295Seric **	Side Effects:
261514Seric **		increments Errors.
271514Seric **		sets ExitStat.
28295Seric */
29295Seric 
304084Seric # ifdef lint
314084Seric int	sys_nerr;
324084Seric char	*sys_errlist[];
334084Seric # endif lint
344084Seric 
35295Seric /*VARARGS1*/
36295Seric syserr(fmt, a, b, c, d, e)
37295Seric 	char *fmt;
38295Seric {
39295Seric 	static char errbuf[MAXLINE+1];
40295Seric 	extern char *sys_errlist[];
41295Seric 	extern int sys_nerr;
424063Seric 	register char *eb = errbuf;
43*4167Seric 	extern char Arpa_Syserr[];
44295Seric 
454063Seric 	/* add arpanet error number if not present */
464063Seric 	if (!isdigit(*fmt))
474063Seric 	{
48*4167Seric 		(void) strcpy(eb, Arpa_Syserr);
49*4167Seric 		eb[3] = ' ';
504063Seric 		eb += 4;
514063Seric 	}
524063Seric 
534063Seric 	/* put error message into buffer */
544084Seric 	(void) sprintf(eb, fmt, a, b, c, d, e);
55295Seric 	if (errno != 0)
56295Seric 	{
574063Seric 		eb += strlen(eb);
58295Seric 		if (errno < sys_nerr && errno > 0)
594084Seric 			(void) sprintf(eb, ": %s", sys_errlist[errno]);
60295Seric 		else
614084Seric 			(void) sprintf(eb, ": error %d", errno);
62295Seric 	}
634063Seric 
644162Seric 	if (ArpaMode != ARPA_NONE && !HasXscrpt)
654077Seric 		printf("%s\r\n", errbuf);
664063Seric 	else
674063Seric 		printf("sendmail: %s\n", &errbuf[4]);
684084Seric 	(void) fflush(stdout);
691514Seric 	Errors++;
70295Seric 
71295Seric 	/* determine exit status if not already set */
72295Seric 	if (ExitStat == EX_OK)
73295Seric 	{
74295Seric 		if (errno == 0)
75295Seric 			ExitStat = EX_SOFTWARE;
76295Seric 		else
771598Seric 			ExitStat = EX_OSERR;
78295Seric 	}
79295Seric 
80295Seric # ifdef LOG
812775Seric 	syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, errbuf);
82295Seric # endif LOG
83295Seric 	errno = 0;
84295Seric }
85295Seric /*
86295Seric **  USRERR -- Signal user error.
87295Seric **
88295Seric **	This is much like syserr except it is for user errors.
89295Seric **
90295Seric **	Parameters:
91295Seric **		fmt, a, b, c, d -- printf strings
92295Seric **
93295Seric **	Returns:
944084Seric **		none
95295Seric **
96295Seric **	Side Effects:
971514Seric **		increments Errors.
98295Seric */
99295Seric 
100295Seric /*VARARGS1*/
101295Seric usrerr(fmt, a, b, c, d, e)
102295Seric 	char *fmt;
103295Seric {
104295Seric 	extern char SuprErrs;
105*4167Seric 	extern char Arpa_Usrerr[];
106295Seric 
107295Seric 	if (SuprErrs)
1084084Seric 		return;
1094063Seric 	Errors++;
110295Seric 
111*4167Seric 	message(Arpa_Usrerr, fmt, a, b, c, d, e);
1124063Seric }
1134063Seric /*
1144063Seric **  MESSAGE -- print message (not necessarily an error)
1154063Seric **
1164063Seric **	Parameters:
1174063Seric **		num -- the default ARPANET error number (in ascii)
1184063Seric **		msg -- the message (printf fmt) -- if it begins
1194063Seric **			with a digit, this number overrides num.
1204063Seric **		a, b, c, d, e -- printf arguments
1214063Seric **
1224063Seric **	Returns:
1234063Seric **		none
1244063Seric **
1254063Seric **	Side Effects:
1264063Seric **		none.
1274063Seric */
1284063Seric 
1294084Seric /*VARARGS2*/
1304063Seric message(num, msg, a, b, c, d, e)
1314063Seric 	register char *num;
1324063Seric 	register char *msg;
1334063Seric {
1344063Seric 	/* compute error number */
1354063Seric 	if (isdigit(*msg))
1364063Seric 	{
1374063Seric 		num = msg;
1384063Seric 		msg += 4;
1394063Seric 	}
1404063Seric 
1414063Seric 	/* print arpa format header if needed */
1424162Seric 	if (ArpaMode != ARPA_NONE && !HasXscrpt)
1434063Seric 		printf("%.3s ", num);
1444063Seric 
1454063Seric 	if (To != NULL && To[0] != '\0')
146295Seric 		printf("%s... ", To);
1474063Seric 	printf(msg, a, b, c, d, e);
1484162Seric 	if (ArpaMode != ARPA_NONE && !HasXscrpt)
1494077Seric 		printf("\r");
150295Seric 	printf("\n");
1514084Seric 	(void) fflush(stdout);
152295Seric }
153