xref: /csrg-svn/usr.sbin/sendmail/src/err.c (revision 3311)
1295Seric # include <stdio.h>
2*3311Seric # include "sendmail.h"
3295Seric # ifdef LOG
42775Seric # include <syslog.h>
5295Seric # endif LOG
6295Seric 
7*3311Seric static char	SccsId[] = "@(#)err.c	3.3	03/20/81";
8406Seric 
9295Seric /*
101514Seric **  SYSERR -- Print error message.
11295Seric **
12295Seric **	Prints an error message via printf to the diagnostic
13295Seric **	output.  If LOG is defined, it logs it also.
14295Seric **
15295Seric **	Parameters:
16295Seric **		f -- the format string
17295Seric **		a, b, c, d, e -- parameters
18295Seric **
19295Seric **	Returns:
20295Seric **		-1 always
21295Seric **
22295Seric **	Side Effects:
231514Seric **		increments Errors.
241514Seric **		sets ExitStat.
25295Seric */
26295Seric 
27295Seric /*VARARGS1*/
28295Seric syserr(fmt, a, b, c, d, e)
29295Seric 	char *fmt;
30295Seric {
31295Seric 	extern int errno;
32295Seric 	static char errbuf[MAXLINE+1];
33295Seric 	register char *p;
34295Seric 	extern char *sys_errlist[];
35295Seric 	extern int sys_nerr;
362989Seric 	extern char *sprintf();
37295Seric 
38295Seric 	sprintf(errbuf, fmt, a, b, c, d, e);
39295Seric 	if (errno != 0)
40295Seric 	{
41295Seric 		p = &errbuf[strlen(errbuf)];
42295Seric 		if (errno < sys_nerr && errno > 0)
43295Seric 			sprintf(p, ": %s", sys_errlist[errno]);
44295Seric 		else
45295Seric 			sprintf(p, ": error %d", errno);
46295Seric 	}
47*3311Seric 	printf("sendmail: %s\n", errbuf);
482097Seric 	fflush(stdout);
491514Seric 	Errors++;
50295Seric 
51295Seric 	/* determine exit status if not already set */
52295Seric 	if (ExitStat == EX_OK)
53295Seric 	{
54295Seric 		if (errno == 0)
55295Seric 			ExitStat = EX_SOFTWARE;
56295Seric 		else
571598Seric 			ExitStat = EX_OSERR;
58295Seric 	}
59295Seric 
60295Seric # ifdef LOG
612775Seric 	syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, errbuf);
62295Seric # endif LOG
63295Seric 	errno = 0;
64295Seric 	return (-1);
65295Seric }
66295Seric /*
67295Seric **  USRERR -- Signal user error.
68295Seric **
69295Seric **	This is much like syserr except it is for user errors.
70295Seric **
71295Seric **	Parameters:
72295Seric **		fmt, a, b, c, d -- printf strings
73295Seric **
74295Seric **	Returns:
75295Seric **		-1
76295Seric **
77295Seric **	Side Effects:
781514Seric **		increments Errors.
79295Seric */
80295Seric 
81295Seric /*VARARGS1*/
82295Seric usrerr(fmt, a, b, c, d, e)
83295Seric 	char *fmt;
84295Seric {
85295Seric 	extern char SuprErrs;
86295Seric 
87295Seric 	if (SuprErrs)
882989Seric 		return (0);
89295Seric 
901514Seric 	Errors++;
91295Seric 	if (To != NULL)
92295Seric 		printf("%s... ", To);
93295Seric 	printf(fmt, a, b, c, d, e);
94295Seric 	printf("\n");
952097Seric 	fflush(stdout);
96295Seric 	return (-1);
97295Seric }
98