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