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