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