00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef lint
00038 static char sccsid[] = "@(#)error.c 5.1 (Berkeley) 3/7/91";
00039 #endif
00040
00041
00042
00043
00044
00045 #include "shell.h"
00046 #include "main.h"
00047 #include "options.h"
00048 #include "output.h"
00049 #include "error.h"
00050 #include <sys/types.h>
00051 #include <signal.h>
00052 #ifdef __STDC__
00053 #include "stdarg.h"
00054 #else
00055 #include <varargs.h>
00056 #endif
00057 #include <errno.h>
00058
00059
00060
00061
00062
00063
00064 struct jmploc *handler;
00065 int exception;
00066 volatile int suppressint;
00067 volatile int intpending;
00068 char *commandname;
00069
00070
00071
00072
00073
00074
00075
00076
00077 void
00078 exraise(e) {
00079 if (handler == NULL)
00080 abort();
00081 exception = e;
00082 longjmp(handler->loc, 1);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 void
00097 onint() {
00098 if (suppressint) {
00099 intpending++;
00100 return;
00101 }
00102 intpending = 0;
00103 #ifdef BSD
00104 sigsetmask(0);
00105 #endif
00106 if (rootshell && iflag)
00107 exraise(EXINT);
00108 else
00109 _exit(128 + SIGINT);
00110 }
00111
00112
00113
00114 void
00115 error2(a, b)
00116 char *a, *b;
00117 {
00118 error("%s: %s", a, b);
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 #ifdef __STDC__
00129 void
00130 error(char *msg, ...) {
00131 #else
00132 void
00133 error(va_alist)
00134 va_dcl
00135 {
00136 char *msg;
00137 #endif
00138 va_list ap;
00139
00140 CLEAR_PENDING_INT;
00141 INTOFF;
00142 #ifdef __STDC__
00143 va_start(ap, msg);
00144 #else
00145 va_start(ap);
00146 msg = va_arg(ap, char *);
00147 #endif
00148 #if DEBUG
00149 if (msg)
00150 TRACE(("error(\"%s\") pid=%d\n", msg, getpid()));
00151 else
00152 TRACE(("error(NULL) pid=%d\n", getpid()));
00153 #endif
00154 if (msg) {
00155 if (commandname)
00156 outfmt(&errout, "%s: ", commandname);
00157 doformat(&errout, msg, ap);
00158 out2c('\n');
00159 }
00160 va_end(ap);
00161 flushall();
00162 exraise(EXERROR);
00163 }
00164
00165
00166 #ifdef notdef
00167
00168
00169
00170
00171 struct errname {
00172 short errcode;
00173 short action;
00174 char *msg;
00175 };
00176
00177
00178 #define ALL (E_OPEN|E_CREAT|E_EXEC)
00179
00180 STATIC const struct errname errormsg[] = {
00181 EINTR, ALL, "interrupted",
00182 EACCES, ALL, "permission denied",
00183 EIO, ALL, "I/O error",
00184 ENOENT, E_OPEN, "no such file",
00185 ENOENT, E_CREAT, "directory nonexistent",
00186 ENOENT, E_EXEC, "not found",
00187 ENOTDIR, E_OPEN, "no such file",
00188 ENOTDIR, E_CREAT, "directory nonexistent",
00189 ENOTDIR, E_EXEC, "not found",
00190 ENOEXEC, ALL, "not an executable",
00191 EISDIR, ALL, "is a directory",
00192
00193 ENFILE, ALL, "file table overflow",
00194 ENOSPC, ALL, "file system full",
00195 #ifdef EDQUOT
00196 EDQUOT, ALL, "disk quota exceeded",
00197 #endif
00198 #ifdef ENOSR
00199 ENOSR, ALL, "no streams resources",
00200 #endif
00201 ENXIO, ALL, "no such device or address",
00202 EROFS, ALL, "read-only file system",
00203 ETXTBSY, ALL, "text busy",
00204 #ifdef SYSV
00205 EAGAIN, E_EXEC, "not enough memory",
00206 #endif
00207 ENOMEM, ALL, "not enough memory",
00208 #ifdef ENOLINK
00209 ENOLINK, ALL, "remote access failed",
00210 #endif
00211 #ifdef EMULTIHOP
00212 EMULTIHOP, ALL, "remote access failed",
00213 #endif
00214 #ifdef ECOMM
00215 ECOMM, ALL, "remote access failed",
00216 #endif
00217 #ifdef ESTALE
00218 ESTALE, ALL, "remote access failed",
00219 #endif
00220 #ifdef ETIMEDOUT
00221 ETIMEDOUT, ALL, "remote access failed",
00222 #endif
00223 #ifdef ELOOP
00224 ELOOP, ALL, "symbolic link loop",
00225 #endif
00226 E2BIG, E_EXEC, "argument list too long",
00227 #ifdef ELIBACC
00228 ELIBACC, E_EXEC, "shared library missing",
00229 #endif
00230 0, 0, NULL
00231 };
00232
00233
00234
00235
00236
00237
00238
00239
00240 char *
00241 errmsg(e, action) {
00242 const struct errname *ep;
00243 static char buf[12];
00244
00245 for (ep = errormsg ; ep->errcode ; ep++) {
00246 if (ep->errcode == e && (ep->action & action) != 0)
00247 return ep->msg;
00248 }
00249 fmtstr(buf, sizeof buf, "error %d", e);
00250 return buf;
00251 }
00252 #endif