1 # include "sendmail.h" 2 # ifdef LOG 3 # include <syslog.h> 4 # endif LOG 5 6 SCCSID(@(#)err.c 3.18 12/06/81); 7 8 /* 9 ** SYSERR -- Print error message. 10 ** 11 ** Prints an error message via printf to the diagnostic 12 ** output. If LOG is defined, it logs it also. 13 ** 14 ** Parameters: 15 ** f -- the format string 16 ** a, b, c, d, e -- parameters 17 ** 18 ** Returns: 19 ** none 20 ** 21 ** Side Effects: 22 ** increments Errors. 23 ** sets ExitStat. 24 */ 25 26 # ifdef lint 27 int sys_nerr; 28 char *sys_errlist[]; 29 # endif lint 30 31 /*VARARGS1*/ 32 syserr(fmt, a, b, c, d, e) 33 char *fmt; 34 { 35 static char errbuf[2*BUFSIZ]; 36 extern char Arpa_Syserr[]; 37 38 /* format the error message */ 39 fmtmsg(errbuf, (char *) NULL, Arpa_Syserr, fmt, a, b, c, d, e); 40 41 /* output error message to transcript */ 42 fprintf(Xscript, "%s\n", errbuf); 43 44 /* output error message to output channel if appropriate */ 45 if (!HoldErrs) 46 { 47 if (ArpaMode) 48 fprintf(OutChannel, "%s\r\n", errbuf); 49 else 50 fprintf(OutChannel, "sendmail: %s\n", &errbuf[4]); 51 (void) fflush(OutChannel); 52 } 53 54 Errors++; 55 56 /* determine exit status if not already set */ 57 if (ExitStat == EX_OK) 58 { 59 if (errno == 0) 60 ExitStat = EX_SOFTWARE; 61 else 62 ExitStat = EX_OSERR; 63 } 64 65 # ifdef LOG 66 syslog(LOG_ERR, "%s->%s: %s", From.q_paddr, To, &errbuf[4]); 67 # endif LOG 68 errno = 0; 69 } 70 /* 71 ** USRERR -- Signal user error. 72 ** 73 ** This is much like syserr except it is for user errors. 74 ** 75 ** Parameters: 76 ** fmt, a, b, c, d -- printf strings 77 ** 78 ** Returns: 79 ** none 80 ** 81 ** Side Effects: 82 ** increments Errors. 83 */ 84 85 /*VARARGS1*/ 86 usrerr(fmt, a, b, c, d, e) 87 char *fmt; 88 { 89 extern char SuprErrs; 90 extern char Arpa_Usrerr[]; 91 92 if (SuprErrs) 93 return; 94 Errors++; 95 96 message(Arpa_Usrerr, fmt, a, b, c, d, e); 97 } 98 /* 99 ** MESSAGE -- print message (not necessarily an error) 100 ** 101 ** Parameters: 102 ** num -- the default ARPANET error number (in ascii) 103 ** msg -- the message (printf fmt) -- if it begins 104 ** with a digit, this number overrides num. 105 ** a, b, c, d, e -- printf arguments 106 ** 107 ** Returns: 108 ** none 109 ** 110 ** Side Effects: 111 ** none. 112 */ 113 114 /*VARARGS2*/ 115 message(num, msg, a, b, c, d, e) 116 register char *num; 117 register char *msg; 118 { 119 char errbuf[2*BUFSIZ]; 120 121 errno = 0; 122 fmtmsg(errbuf, To, num, msg, a, b, c, d, e); 123 124 /* output to transcript */ 125 fprintf(Xscript, "%s\n", errbuf); 126 127 /* output to channel if appropriate */ 128 if (!HoldErrs) 129 { 130 if (ArpaMode) 131 fprintf(OutChannel, "%s\r\n", errbuf); 132 else 133 fprintf(OutChannel, "%s\n", &errbuf[4]); 134 (void) fflush(OutChannel); 135 } 136 } 137 /* 138 ** FMTMSG -- format a message into buffer. 139 ** 140 ** Parameters: 141 ** eb -- error buffer to get result. 142 ** to -- the recipient tag for this message. 143 ** num -- arpanet error number. 144 ** fmt -- format of string. 145 ** a, b, c, d, e -- arguments. 146 ** 147 ** Returns: 148 ** none. 149 ** 150 ** Side Effects: 151 ** none. 152 */ 153 154 /*VARARGS4*/ 155 static 156 fmtmsg(eb, to, num, fmt, a, b, c, d, e) 157 register char *eb; 158 char *to; 159 char *num; 160 char *fmt; 161 { 162 char del; 163 164 /* output the reply code */ 165 if (isdigit(*fmt)) 166 { 167 num = fmt; 168 fmt += 4; 169 } 170 if (num[3] == '-') 171 del = '-'; 172 else 173 del = ' '; 174 (void) sprintf(eb, "%3.3s%c", num, del); 175 eb += 4; 176 177 /* output the "to" person */ 178 if (to != NULL && to[0] != '\0') 179 { 180 (void) sprintf(eb, "%s... ", to); 181 while (*eb != '\0') 182 *eb++ &= 0177; 183 } 184 185 /* output the message */ 186 (void) sprintf(eb, fmt, a, b, c, d, e); 187 while (*eb != '\0') 188 *eb++ &= 0177; 189 190 /* output the error code, if any */ 191 if (errno != 0) 192 { 193 extern int sys_nerr; 194 extern char *sys_errlist[]; 195 if (errno < sys_nerr && errno > 0) 196 (void) sprintf(eb, ": %s", sys_errlist[errno]); 197 else 198 (void) sprintf(eb, ": error %d", errno); 199 eb += strlen(eb); 200 } 201 } 202