13311Seric # include "sendmail.h" 2295Seric # ifdef LOG 32775Seric # include <syslog.h> 4295Seric # endif LOG 5295Seric 6*7275Seric SCCSID(@(#)err.c 3.23 06/25/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 */ 426992Seric fprintf(Xscript, "%s\n", &errbuf[4]); 434711Seric 444711Seric /* output error message to output channel if appropriate */ 454711Seric if (!HoldErrs) 46295Seric { 47*7275Seric (void) fflush(stdout); 484711Seric if (ArpaMode) 494711Seric fprintf(OutChannel, "%s\r\n", errbuf); 50295Seric else 514711Seric fprintf(OutChannel, "sendmail: %s\n", &errbuf[4]); 524711Seric (void) fflush(OutChannel); 53295Seric } 544063Seric 551514Seric Errors++; 566048Seric FatalErrors = TRUE; 57295Seric 58295Seric /* determine exit status if not already set */ 59295Seric if (ExitStat == EX_OK) 60295Seric { 61295Seric if (errno == 0) 62295Seric ExitStat = EX_SOFTWARE; 63295Seric else 641598Seric ExitStat = EX_OSERR; 65295Seric } 66295Seric 67295Seric # ifdef LOG 686902Seric syslog(LOG_ERR, "%s->%s: %s", CurEnv->e_from.q_paddr, CurEnv->e_to, &errbuf[4]); 69295Seric # endif LOG 70295Seric errno = 0; 71295Seric } 72295Seric /* 73295Seric ** USRERR -- Signal user error. 74295Seric ** 75295Seric ** This is much like syserr except it is for user errors. 76295Seric ** 77295Seric ** Parameters: 78295Seric ** fmt, a, b, c, d -- printf strings 79295Seric ** 80295Seric ** Returns: 814084Seric ** none 82295Seric ** 83295Seric ** Side Effects: 841514Seric ** increments Errors. 85295Seric */ 86295Seric 87295Seric /*VARARGS1*/ 88295Seric usrerr(fmt, a, b, c, d, e) 89295Seric char *fmt; 90295Seric { 91295Seric extern char SuprErrs; 924167Seric extern char Arpa_Usrerr[]; 93295Seric 94295Seric if (SuprErrs) 954084Seric return; 964063Seric Errors++; 976048Seric FatalErrors = TRUE; 98295Seric 994167Seric message(Arpa_Usrerr, fmt, a, b, c, d, e); 1004063Seric } 1014063Seric /* 1024063Seric ** MESSAGE -- print message (not necessarily an error) 1034063Seric ** 1044063Seric ** Parameters: 1054063Seric ** num -- the default ARPANET error number (in ascii) 1064063Seric ** msg -- the message (printf fmt) -- if it begins 1074063Seric ** with a digit, this number overrides num. 1084063Seric ** a, b, c, d, e -- printf arguments 1094063Seric ** 1104063Seric ** Returns: 1114063Seric ** none 1124063Seric ** 1134063Seric ** Side Effects: 1144063Seric ** none. 1154063Seric */ 1164063Seric 1174084Seric /*VARARGS2*/ 1184063Seric message(num, msg, a, b, c, d, e) 1194063Seric register char *num; 1204063Seric register char *msg; 1214063Seric { 1225201Seric char errbuf[2*BUFSIZ]; 1234711Seric 1244711Seric errno = 0; 1256902Seric fmtmsg(errbuf, CurEnv->e_to, num, msg, a, b, c, d, e); 1264711Seric 1274711Seric /* output to transcript */ 1286992Seric fprintf(Xscript, "%s\n", &errbuf[4]); 1294711Seric 1304711Seric /* output to channel if appropriate */ 1317053Seric if (!HoldErrs && (Verbose || errbuf[0] != '0')) 1324063Seric { 133*7275Seric (void) fflush(stdout); 1344711Seric if (ArpaMode) 1354711Seric fprintf(OutChannel, "%s\r\n", errbuf); 1364711Seric else 1374711Seric fprintf(OutChannel, "%s\n", &errbuf[4]); 1384711Seric (void) fflush(OutChannel); 1394063Seric } 1404711Seric } 1414711Seric /* 1424711Seric ** FMTMSG -- format a message into buffer. 1434711Seric ** 1444711Seric ** Parameters: 1454711Seric ** eb -- error buffer to get result. 1464711Seric ** to -- the recipient tag for this message. 1474711Seric ** num -- arpanet error number. 1484711Seric ** fmt -- format of string. 1494711Seric ** a, b, c, d, e -- arguments. 1504711Seric ** 1514711Seric ** Returns: 1524711Seric ** none. 1534711Seric ** 1544711Seric ** Side Effects: 1554711Seric ** none. 1564711Seric */ 1574063Seric 1584834Seric /*VARARGS4*/ 1594711Seric static 1604711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e) 1614711Seric register char *eb; 1624711Seric char *to; 1634711Seric char *num; 1644711Seric char *fmt; 1654711Seric { 1664711Seric char del; 1674711Seric 1684711Seric /* output the reply code */ 1694711Seric if (isdigit(*fmt)) 1704577Seric { 1714711Seric num = fmt; 1724711Seric fmt += 4; 1734711Seric } 1744711Seric if (num[3] == '-') 1754711Seric del = '-'; 1764711Seric else 1774711Seric del = ' '; 1784711Seric (void) sprintf(eb, "%3.3s%c", num, del); 1794711Seric eb += 4; 1804063Seric 1814711Seric /* output the "to" person */ 1824711Seric if (to != NULL && to[0] != '\0') 1834711Seric { 1844711Seric (void) sprintf(eb, "%s... ", to); 1855201Seric while (*eb != '\0') 1865201Seric *eb++ &= 0177; 1874711Seric } 1884711Seric 1894711Seric /* output the message */ 1904711Seric (void) sprintf(eb, fmt, a, b, c, d, e); 1915201Seric while (*eb != '\0') 1925201Seric *eb++ &= 0177; 1934711Seric 1944711Seric /* output the error code, if any */ 1954711Seric if (errno != 0) 1964711Seric { 1974711Seric extern int sys_nerr; 1984711Seric extern char *sys_errlist[]; 1994711Seric if (errno < sys_nerr && errno > 0) 2004711Seric (void) sprintf(eb, ": %s", sys_errlist[errno]); 2014577Seric else 2024711Seric (void) sprintf(eb, ": error %d", errno); 2034711Seric eb += strlen(eb); 2044577Seric } 205295Seric } 206