13311Seric # include "sendmail.h" 2295Seric # ifdef LOG 32775Seric # include <syslog.h> 4295Seric # endif LOG 5295Seric 6*6048Seric SCCSID(@(#)err.c 3.19 03/06/82); 7406Seric 8295Seric /* 91514Seric ** SYSERR -- Print error message. 10295Seric ** 11295Seric ** Prints an error message via printf to the diagnostic 12295Seric ** output. If LOG is defined, it logs it also. 13295Seric ** 14295Seric ** Parameters: 15295Seric ** f -- the format string 16295Seric ** a, b, c, d, e -- parameters 17295Seric ** 18295Seric ** Returns: 194084Seric ** none 20295Seric ** 21295Seric ** Side Effects: 221514Seric ** increments Errors. 231514Seric ** sets ExitStat. 24295Seric */ 25295Seric 264084Seric # ifdef lint 274084Seric int sys_nerr; 284084Seric char *sys_errlist[]; 294084Seric # endif lint 304084Seric 31295Seric /*VARARGS1*/ 32295Seric syserr(fmt, a, b, c, d, e) 33295Seric char *fmt; 34295Seric { 355201Seric static char errbuf[2*BUFSIZ]; 364167Seric extern char Arpa_Syserr[]; 37295Seric 384711Seric /* format the error message */ 394834Seric fmtmsg(errbuf, (char *) NULL, Arpa_Syserr, fmt, a, b, c, d, e); 404063Seric 414711Seric /* output error message to transcript */ 424711Seric fprintf(Xscript, "%s\n", errbuf); 434711Seric 444711Seric /* output error message to output channel if appropriate */ 454711Seric if (!HoldErrs) 46295Seric { 474711Seric if (ArpaMode) 484711Seric fprintf(OutChannel, "%s\r\n", errbuf); 49295Seric else 504711Seric fprintf(OutChannel, "sendmail: %s\n", &errbuf[4]); 514711Seric (void) fflush(OutChannel); 52295Seric } 534063Seric 541514Seric Errors++; 55*6048Seric FatalErrors = TRUE; 56295Seric 57295Seric /* determine exit status if not already set */ 58295Seric if (ExitStat == EX_OK) 59295Seric { 60295Seric if (errno == 0) 61295Seric ExitStat = EX_SOFTWARE; 62295Seric else 631598Seric ExitStat = EX_OSERR; 64295Seric } 65295Seric 66295Seric # ifdef LOG 674316Seric syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, &errbuf[4]); 68295Seric # endif LOG 69295Seric errno = 0; 70295Seric } 71295Seric /* 72295Seric ** USRERR -- Signal user error. 73295Seric ** 74295Seric ** This is much like syserr except it is for user errors. 75295Seric ** 76295Seric ** Parameters: 77295Seric ** fmt, a, b, c, d -- printf strings 78295Seric ** 79295Seric ** Returns: 804084Seric ** none 81295Seric ** 82295Seric ** Side Effects: 831514Seric ** increments Errors. 84295Seric */ 85295Seric 86295Seric /*VARARGS1*/ 87295Seric usrerr(fmt, a, b, c, d, e) 88295Seric char *fmt; 89295Seric { 90295Seric extern char SuprErrs; 914167Seric extern char Arpa_Usrerr[]; 92295Seric 93295Seric if (SuprErrs) 944084Seric return; 954063Seric Errors++; 96*6048Seric FatalErrors = TRUE; 97295Seric 984167Seric message(Arpa_Usrerr, fmt, a, b, c, d, e); 994063Seric } 1004063Seric /* 1014063Seric ** MESSAGE -- print message (not necessarily an error) 1024063Seric ** 1034063Seric ** Parameters: 1044063Seric ** num -- the default ARPANET error number (in ascii) 1054063Seric ** msg -- the message (printf fmt) -- if it begins 1064063Seric ** with a digit, this number overrides num. 1074063Seric ** a, b, c, d, e -- printf arguments 1084063Seric ** 1094063Seric ** Returns: 1104063Seric ** none 1114063Seric ** 1124063Seric ** Side Effects: 1134063Seric ** none. 1144063Seric */ 1154063Seric 1164084Seric /*VARARGS2*/ 1174063Seric message(num, msg, a, b, c, d, e) 1184063Seric register char *num; 1194063Seric register char *msg; 1204063Seric { 1215201Seric char errbuf[2*BUFSIZ]; 1224711Seric 1234711Seric errno = 0; 1244711Seric fmtmsg(errbuf, To, num, msg, a, b, c, d, e); 1254711Seric 1264711Seric /* output to transcript */ 1274711Seric fprintf(Xscript, "%s\n", errbuf); 1284711Seric 1294711Seric /* output to channel if appropriate */ 1304711Seric if (!HoldErrs) 1314063Seric { 1324711Seric if (ArpaMode) 1334711Seric fprintf(OutChannel, "%s\r\n", errbuf); 1344711Seric else 1354711Seric fprintf(OutChannel, "%s\n", &errbuf[4]); 1364711Seric (void) fflush(OutChannel); 1374063Seric } 1384711Seric } 1394711Seric /* 1404711Seric ** FMTMSG -- format a message into buffer. 1414711Seric ** 1424711Seric ** Parameters: 1434711Seric ** eb -- error buffer to get result. 1444711Seric ** to -- the recipient tag for this message. 1454711Seric ** num -- arpanet error number. 1464711Seric ** fmt -- format of string. 1474711Seric ** a, b, c, d, e -- arguments. 1484711Seric ** 1494711Seric ** Returns: 1504711Seric ** none. 1514711Seric ** 1524711Seric ** Side Effects: 1534711Seric ** none. 1544711Seric */ 1554063Seric 1564834Seric /*VARARGS4*/ 1574711Seric static 1584711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e) 1594711Seric register char *eb; 1604711Seric char *to; 1614711Seric char *num; 1624711Seric char *fmt; 1634711Seric { 1644711Seric char del; 1654711Seric 1664711Seric /* output the reply code */ 1674711Seric if (isdigit(*fmt)) 1684577Seric { 1694711Seric num = fmt; 1704711Seric fmt += 4; 1714711Seric } 1724711Seric if (num[3] == '-') 1734711Seric del = '-'; 1744711Seric else 1754711Seric del = ' '; 1764711Seric (void) sprintf(eb, "%3.3s%c", num, del); 1774711Seric eb += 4; 1784063Seric 1794711Seric /* output the "to" person */ 1804711Seric if (to != NULL && to[0] != '\0') 1814711Seric { 1824711Seric (void) sprintf(eb, "%s... ", to); 1835201Seric while (*eb != '\0') 1845201Seric *eb++ &= 0177; 1854711Seric } 1864711Seric 1874711Seric /* output the message */ 1884711Seric (void) sprintf(eb, fmt, a, b, c, d, e); 1895201Seric while (*eb != '\0') 1905201Seric *eb++ &= 0177; 1914711Seric 1924711Seric /* output the error code, if any */ 1934711Seric if (errno != 0) 1944711Seric { 1954711Seric extern int sys_nerr; 1964711Seric extern char *sys_errlist[]; 1974711Seric if (errno < sys_nerr && errno > 0) 1984711Seric (void) sprintf(eb, ": %s", sys_errlist[errno]); 1994577Seric else 2004711Seric (void) sprintf(eb, ": error %d", errno); 2014711Seric eb += strlen(eb); 2024577Seric } 203295Seric } 204