13311Seric # include "sendmail.h" 2295Seric 3*8239Seric SCCSID(@(#)err.c 3.30 09/21/82); 4406Seric 5295Seric /* 61514Seric ** SYSERR -- Print error message. 7295Seric ** 8295Seric ** Prints an error message via printf to the diagnostic 9295Seric ** output. If LOG is defined, it logs it also. 10295Seric ** 11295Seric ** Parameters: 12295Seric ** f -- the format string 13295Seric ** a, b, c, d, e -- parameters 14295Seric ** 15295Seric ** Returns: 164084Seric ** none 177762Seric ** Through TopFrame if QuickAbort is set. 18295Seric ** 19295Seric ** Side Effects: 201514Seric ** increments Errors. 211514Seric ** sets ExitStat. 22295Seric */ 23295Seric 244084Seric # ifdef lint 254084Seric int sys_nerr; 264084Seric char *sys_errlist[]; 274084Seric # endif lint 287525Seric static char MsgBuf[BUFSIZ*2]; /* text of most recent message */ 294084Seric 30295Seric /*VARARGS1*/ 31295Seric syserr(fmt, a, b, c, d, e) 32295Seric char *fmt; 33295Seric { 347957Seric extern char Arpa_PSyserr[]; 357957Seric extern char Arpa_TSyserr[]; 367957Seric register char *p; 37295Seric 387525Seric /* format and output the error message */ 397957Seric if (errno == 0) 407957Seric p = Arpa_PSyserr; 417957Seric else 427957Seric p = Arpa_TSyserr; 437957Seric fmtmsg(MsgBuf, (char *) NULL, p, fmt, a, b, c, d, e); 447613Seric putmsg(MsgBuf); 454063Seric 46295Seric /* determine exit status if not already set */ 47295Seric if (ExitStat == EX_OK) 48295Seric { 49295Seric if (errno == 0) 50295Seric ExitStat = EX_SOFTWARE; 51295Seric else 521598Seric ExitStat = EX_OSERR; 53295Seric } 54295Seric 557810Seric (void) queuename(CurEnv, '\0'); 56295Seric # ifdef LOG 577674Seric if (LogLevel > 0) 587810Seric syslog(LOG_ERR, "%s: %s", CurEnv->e_id, &MsgBuf[4]); 59295Seric # endif LOG 60295Seric errno = 0; 617762Seric if (QuickAbort) 627762Seric longjmp(TopFrame, 2); 63295Seric } 64295Seric /* 65295Seric ** USRERR -- Signal user error. 66295Seric ** 67295Seric ** This is much like syserr except it is for user errors. 68295Seric ** 69295Seric ** Parameters: 70295Seric ** fmt, a, b, c, d -- printf strings 71295Seric ** 72295Seric ** Returns: 734084Seric ** none 747762Seric ** Through TopFrame if QuickAbort is set. 75295Seric ** 76295Seric ** Side Effects: 771514Seric ** increments Errors. 78295Seric */ 79295Seric 80295Seric /*VARARGS1*/ 81295Seric usrerr(fmt, a, b, c, d, e) 82295Seric char *fmt; 83295Seric { 84295Seric extern char SuprErrs; 854167Seric extern char Arpa_Usrerr[]; 86295Seric 87295Seric if (SuprErrs) 884084Seric return; 89295Seric 907613Seric fmtmsg(MsgBuf, CurEnv->e_to, Arpa_Usrerr, fmt, a, b, c, d, e); 917613Seric putmsg(MsgBuf); 92*8239Seric 937762Seric if (QuickAbort) 947762Seric longjmp(TopFrame, 1); 954063Seric } 964063Seric /* 974063Seric ** MESSAGE -- print message (not necessarily an error) 984063Seric ** 994063Seric ** Parameters: 1004063Seric ** num -- the default ARPANET error number (in ascii) 1014063Seric ** msg -- the message (printf fmt) -- if it begins 1024063Seric ** with a digit, this number overrides num. 1034063Seric ** a, b, c, d, e -- printf arguments 1044063Seric ** 1054063Seric ** Returns: 1064063Seric ** none 1074063Seric ** 1084063Seric ** Side Effects: 1094063Seric ** none. 1104063Seric */ 1114063Seric 1124084Seric /*VARARGS2*/ 1134063Seric message(num, msg, a, b, c, d, e) 1144063Seric register char *num; 1154063Seric register char *msg; 1164063Seric { 1174711Seric errno = 0; 1187525Seric fmtmsg(MsgBuf, CurEnv->e_to, num, msg, a, b, c, d, e); 1197613Seric putmsg(MsgBuf); 1207613Seric } 1217613Seric /* 122*8239Seric ** NMESSAGE -- print message (not necessarily an error) 123*8239Seric ** 124*8239Seric ** Just like "message" except it never puts the to... tag on. 125*8239Seric ** 126*8239Seric ** Parameters: 127*8239Seric ** num -- the default ARPANET error number (in ascii) 128*8239Seric ** msg -- the message (printf fmt) -- if it begins 129*8239Seric ** with a digit, this number overrides num. 130*8239Seric ** a, b, c, d, e -- printf arguments 131*8239Seric ** 132*8239Seric ** Returns: 133*8239Seric ** none 134*8239Seric ** 135*8239Seric ** Side Effects: 136*8239Seric ** none. 137*8239Seric */ 138*8239Seric 139*8239Seric /*VARARGS2*/ 140*8239Seric nmessage(num, msg, a, b, c, d, e) 141*8239Seric register char *num; 142*8239Seric register char *msg; 143*8239Seric { 144*8239Seric errno = 0; 145*8239Seric fmtmsg(MsgBuf, NULL, num, msg, a, b, c, d, e); 146*8239Seric putmsg(MsgBuf); 147*8239Seric } 148*8239Seric /* 1497613Seric ** PUTMSG -- output error message to transcript and channel 1507613Seric ** 1517613Seric ** Parameters: 1527613Seric ** msg -- message to output (in SMTP format). 1537613Seric ** 1547613Seric ** Returns: 1557613Seric ** none. 1567613Seric ** 1577613Seric ** Side Effects: 1587613Seric ** Outputs msg to the transcript. 1597613Seric ** If appropriate, outputs it to the channel. 1607613Seric ** Deletes SMTP reply code number as appropriate. 1617613Seric */ 1624711Seric 1637613Seric putmsg(msg) 1647613Seric char *msg; 1657613Seric { 1664711Seric /* output to transcript */ 1677613Seric fprintf(Xscript, "%s\n", Smtp ? msg : &msg[4]); 1684711Seric 1694711Seric /* output to channel if appropriate */ 1707613Seric if (!HoldErrs && (Verbose || msg[0] != '0')) 1714063Seric { 1727275Seric (void) fflush(stdout); 1734711Seric if (ArpaMode) 1747613Seric fprintf(OutChannel, "%s\r\n", msg); 1754711Seric else 1767613Seric fprintf(OutChannel, "%s\n", &msg[4]); 1774711Seric (void) fflush(OutChannel); 1784063Seric } 179*8239Seric 180*8239Seric /* determine error status */ 181*8239Seric switch (msg[0]) 182*8239Seric { 183*8239Seric case '5': 184*8239Seric FatalErrors = TRUE; 185*8239Seric /* fall through.... */ 186*8239Seric 187*8239Seric case '4': 188*8239Seric Errors++; 189*8239Seric break; 190*8239Seric } 1914711Seric } 1924711Seric /* 1934711Seric ** FMTMSG -- format a message into buffer. 1944711Seric ** 1954711Seric ** Parameters: 1964711Seric ** eb -- error buffer to get result. 1974711Seric ** to -- the recipient tag for this message. 1984711Seric ** num -- arpanet error number. 1994711Seric ** fmt -- format of string. 2004711Seric ** a, b, c, d, e -- arguments. 2014711Seric ** 2024711Seric ** Returns: 2034711Seric ** none. 2044711Seric ** 2054711Seric ** Side Effects: 2064711Seric ** none. 2074711Seric */ 2084063Seric 2094834Seric /*VARARGS4*/ 2104711Seric static 2114711Seric fmtmsg(eb, to, num, fmt, a, b, c, d, e) 2124711Seric register char *eb; 2134711Seric char *to; 2144711Seric char *num; 2154711Seric char *fmt; 2164711Seric { 2174711Seric char del; 2184711Seric 2194711Seric /* output the reply code */ 2204711Seric if (isdigit(*fmt)) 2214577Seric { 2224711Seric num = fmt; 2234711Seric fmt += 4; 2244711Seric } 2254711Seric if (num[3] == '-') 2264711Seric del = '-'; 2274711Seric else 2284711Seric del = ' '; 2294711Seric (void) sprintf(eb, "%3.3s%c", num, del); 2304711Seric eb += 4; 2314063Seric 2324711Seric /* output the "to" person */ 2334711Seric if (to != NULL && to[0] != '\0') 2344711Seric { 2354711Seric (void) sprintf(eb, "%s... ", to); 2365201Seric while (*eb != '\0') 2375201Seric *eb++ &= 0177; 2384711Seric } 2394711Seric 2404711Seric /* output the message */ 2414711Seric (void) sprintf(eb, fmt, a, b, c, d, e); 2425201Seric while (*eb != '\0') 2435201Seric *eb++ &= 0177; 2444711Seric 2454711Seric /* output the error code, if any */ 2464711Seric if (errno != 0) 2474711Seric { 2484711Seric extern int sys_nerr; 2494711Seric extern char *sys_errlist[]; 2504711Seric if (errno < sys_nerr && errno > 0) 2514711Seric (void) sprintf(eb, ": %s", sys_errlist[errno]); 2524577Seric else 2534711Seric (void) sprintf(eb, ": error %d", errno); 2544711Seric eb += strlen(eb); 2554577Seric } 256295Seric } 257