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