1295Seric # include <stdio.h> 24063Seric # include <ctype.h> 33311Seric # include "sendmail.h" 4295Seric # ifdef LOG 52775Seric # include <syslog.h> 6295Seric # endif LOG 7295Seric 8*4077Seric static char SccsId[] = "@(#)err.c 3.5 08/09/81"; 9406Seric 10295Seric /* 111514Seric ** SYSERR -- Print error message. 12295Seric ** 13295Seric ** Prints an error message via printf to the diagnostic 14295Seric ** output. If LOG is defined, it logs it also. 15295Seric ** 16295Seric ** Parameters: 17295Seric ** f -- the format string 18295Seric ** a, b, c, d, e -- parameters 19295Seric ** 20295Seric ** Returns: 21295Seric ** -1 always 22295Seric ** 23295Seric ** Side Effects: 241514Seric ** increments Errors. 251514Seric ** sets ExitStat. 26295Seric */ 27295Seric 28295Seric /*VARARGS1*/ 29295Seric syserr(fmt, a, b, c, d, e) 30295Seric char *fmt; 31295Seric { 32295Seric extern int errno; 33295Seric static char errbuf[MAXLINE+1]; 34295Seric register char *p; 35295Seric extern char *sys_errlist[]; 36295Seric extern int sys_nerr; 372989Seric extern char *sprintf(); 384063Seric register char *eb = errbuf; 39295Seric 404063Seric /* add arpanet error number if not present */ 414063Seric if (!isdigit(*fmt)) 424063Seric { 434063Seric strcpy(eb, "455 "); 444063Seric eb += 4; 454063Seric } 464063Seric 474063Seric /* put error message into buffer */ 484063Seric sprintf(eb, fmt, a, b, c, d, e); 49295Seric if (errno != 0) 50295Seric { 514063Seric eb += strlen(eb); 52295Seric if (errno < sys_nerr && errno > 0) 534063Seric sprintf(eb, ": %s", sys_errlist[errno]); 54295Seric else 554063Seric sprintf(eb, ": error %d", errno); 56295Seric } 574063Seric 584063Seric if (ArpaFmt) 59*4077Seric printf("%s\r\n", errbuf); 604063Seric else 614063Seric printf("sendmail: %s\n", &errbuf[4]); 622097Seric fflush(stdout); 631514Seric Errors++; 64295Seric 65295Seric /* determine exit status if not already set */ 66295Seric if (ExitStat == EX_OK) 67295Seric { 68295Seric if (errno == 0) 69295Seric ExitStat = EX_SOFTWARE; 70295Seric else 711598Seric ExitStat = EX_OSERR; 72295Seric } 73295Seric 74295Seric # ifdef LOG 752775Seric syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, errbuf); 76295Seric # endif LOG 77295Seric errno = 0; 78295Seric return (-1); 79295Seric } 80295Seric /* 81295Seric ** USRERR -- Signal user error. 82295Seric ** 83295Seric ** This is much like syserr except it is for user errors. 84295Seric ** 85295Seric ** Parameters: 86295Seric ** fmt, a, b, c, d -- printf strings 87295Seric ** 88295Seric ** Returns: 89295Seric ** -1 90295Seric ** 91295Seric ** Side Effects: 921514Seric ** increments Errors. 93295Seric */ 94295Seric 95295Seric /*VARARGS1*/ 96295Seric usrerr(fmt, a, b, c, d, e) 97295Seric char *fmt; 98295Seric { 99295Seric extern char SuprErrs; 100295Seric 101295Seric if (SuprErrs) 1022989Seric return (0); 1034063Seric Errors++; 104295Seric 1054063Seric message("450", fmt, a, b, c, d, e); 1064063Seric return (-1); 1074063Seric } 1084063Seric /* 1094063Seric ** MESSAGE -- print message (not necessarily an error) 1104063Seric ** 1114063Seric ** Parameters: 1124063Seric ** num -- the default ARPANET error number (in ascii) 1134063Seric ** msg -- the message (printf fmt) -- if it begins 1144063Seric ** with a digit, this number overrides num. 1154063Seric ** a, b, c, d, e -- printf arguments 1164063Seric ** 1174063Seric ** Returns: 1184063Seric ** none 1194063Seric ** 1204063Seric ** Side Effects: 1214063Seric ** none. 1224063Seric */ 1234063Seric 1244063Seric message(num, msg, a, b, c, d, e) 1254063Seric register char *num; 1264063Seric register char *msg; 1274063Seric { 1284063Seric /* compute error number */ 1294063Seric if (isdigit(*msg)) 1304063Seric { 1314063Seric num = msg; 1324063Seric msg += 4; 1334063Seric } 1344063Seric 1354063Seric /* print arpa format header if needed */ 1364063Seric if (ArpaFmt) 1374063Seric printf("%.3s ", num); 1384063Seric 1394063Seric if (To != NULL && To[0] != '\0') 140295Seric printf("%s... ", To); 1414063Seric printf(msg, a, b, c, d, e); 142*4077Seric if (ArpaFmt) 143*4077Seric printf("\r"); 144295Seric printf("\n"); 1452097Seric fflush(stdout); 146295Seric } 147