xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 295)
1*295Seric # include <stdio.h>
2*295Seric # include "dlvrmail.h"
3*295Seric # ifdef LOG
4*295Seric # include <log.h>
5*295Seric # endif LOG
6*295Seric 
7*295Seric /*
8*295Seric **  ERR -- Print error message.
9*295Seric **
10*295Seric **	Prints an error message via printf to the diagnostic
11*295Seric **	output.  If LOG is defined, it logs it also.
12*295Seric **
13*295Seric **	Parameters:
14*295Seric **		f -- the format string
15*295Seric **		a, b, c, d, e -- parameters
16*295Seric **
17*295Seric **	Returns:
18*295Seric **		-1 always
19*295Seric **
20*295Seric **	Side Effects:
21*295Seric **		Sets Error.
22*295Seric **		Sets ExitStat.
23*295Seric **
24*295Seric **	Requires:
25*295Seric **		sprintf (sys)
26*295Seric **		printf (sys)
27*295Seric **		logmsg
28*295Seric **
29*295Seric **	History:
30*295Seric **		12/29/79 -- written.
31*295Seric */
32*295Seric 
33*295Seric /*VARARGS1*/
34*295Seric syserr(fmt, a, b, c, d, e)
35*295Seric 	char *fmt;
36*295Seric {
37*295Seric 	extern int errno;
38*295Seric 	static char errbuf[MAXLINE+1];
39*295Seric 	register char *p;
40*295Seric 	extern char *sys_errlist[];
41*295Seric 	extern int sys_nerr;
42*295Seric 
43*295Seric 	sprintf(errbuf, fmt, a, b, c, d, e);
44*295Seric 	if (errno != 0)
45*295Seric 	{
46*295Seric 		p = &errbuf[strlen(errbuf)];
47*295Seric 		if (errno < sys_nerr && errno > 0)
48*295Seric 			sprintf(p, ": %s", sys_errlist[errno]);
49*295Seric 		else
50*295Seric 			sprintf(p, ": error %d", errno);
51*295Seric 	}
52*295Seric 	printf("delivermail: %s\n", errbuf);
53*295Seric 	Error++;
54*295Seric 
55*295Seric 	/* determine exit status if not already set */
56*295Seric 	if (ExitStat == EX_OK)
57*295Seric 	{
58*295Seric 		if (errno == 0)
59*295Seric 			ExitStat = EX_SOFTWARE;
60*295Seric 		else
61*295Seric 			ExitStat = EX_UNAVAIL;
62*295Seric 	}
63*295Seric 
64*295Seric # ifdef LOG
65*295Seric 	logmsg(LOG_ERR, "%s->%s: %s", From.q_paddr, To, errbuf);
66*295Seric # endif LOG
67*295Seric 	errno = 0;
68*295Seric 	return (-1);
69*295Seric }
70*295Seric /*
71*295Seric **  USRERR -- Signal user error.
72*295Seric **
73*295Seric **	This is much like syserr except it is for user errors.
74*295Seric **
75*295Seric **	Parameters:
76*295Seric **		fmt, a, b, c, d -- printf strings
77*295Seric **
78*295Seric **	Returns:
79*295Seric **		-1
80*295Seric **
81*295Seric **	Side Effects:
82*295Seric **		sets Error.
83*295Seric **
84*295Seric **	Requires:
85*295Seric **		printf (sys)
86*295Seric **
87*295Seric **	History:
88*295Seric **		1/1/80 -- written.
89*295Seric */
90*295Seric 
91*295Seric /*VARARGS1*/
92*295Seric usrerr(fmt, a, b, c, d, e)
93*295Seric 	char *fmt;
94*295Seric {
95*295Seric 	extern char SuprErrs;
96*295Seric 
97*295Seric 	if (SuprErrs)
98*295Seric 		return;
99*295Seric 
100*295Seric 	Error++;
101*295Seric 	if (To != NULL)
102*295Seric 		printf("%s... ", To);
103*295Seric 	printf(fmt, a, b, c, d, e);
104*295Seric 	printf("\n");
105*295Seric 	return (-1);
106*295Seric }
107