1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker * $Header$
3*6a54128fSAndroid Build Coastguard Worker * $Source$
4*6a54128fSAndroid Build Coastguard Worker * $Locker$
5*6a54128fSAndroid Build Coastguard Worker *
6*6a54128fSAndroid Build Coastguard Worker * Copyright 1987 by the Student Information Processing Board
7*6a54128fSAndroid Build Coastguard Worker * of the Massachusetts Institute of Technology
8*6a54128fSAndroid Build Coastguard Worker *
9*6a54128fSAndroid Build Coastguard Worker * Permission to use, copy, modify, and distribute this software and
10*6a54128fSAndroid Build Coastguard Worker * its documentation for any purpose is hereby granted, provided that
11*6a54128fSAndroid Build Coastguard Worker * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
12*6a54128fSAndroid Build Coastguard Worker * advertising or publicity pertaining to distribution of the software
13*6a54128fSAndroid Build Coastguard Worker * without specific, written prior permission. M.I.T. and the
14*6a54128fSAndroid Build Coastguard Worker * M.I.T. S.I.P.B. make no representations about the suitability of
15*6a54128fSAndroid Build Coastguard Worker * this software for any purpose. It is provided "as is" without
16*6a54128fSAndroid Build Coastguard Worker * express or implied warranty.
17*6a54128fSAndroid Build Coastguard Worker */
18*6a54128fSAndroid Build Coastguard Worker
19*6a54128fSAndroid Build Coastguard Worker #include "config.h"
20*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
21*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
22*6a54128fSAndroid Build Coastguard Worker #include <string.h>
23*6a54128fSAndroid Build Coastguard Worker #include <errno.h>
24*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SYS_PRCTL_H
25*6a54128fSAndroid Build Coastguard Worker #include <sys/prctl.h>
26*6a54128fSAndroid Build Coastguard Worker #else
27*6a54128fSAndroid Build Coastguard Worker #define PR_GET_DUMPABLE 3
28*6a54128fSAndroid Build Coastguard Worker #endif
29*6a54128fSAndroid Build Coastguard Worker #if (!defined(HAVE_PRCTL) && defined(linux))
30*6a54128fSAndroid Build Coastguard Worker #include <sys/syscall.h>
31*6a54128fSAndroid Build Coastguard Worker #endif
32*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SEMAPHORE_H
33*6a54128fSAndroid Build Coastguard Worker #include <semaphore.h>
34*6a54128fSAndroid Build Coastguard Worker #endif
35*6a54128fSAndroid Build Coastguard Worker #if HAVE_UNISTD_H
36*6a54128fSAndroid Build Coastguard Worker #include <unistd.h>
37*6a54128fSAndroid Build Coastguard Worker #endif
38*6a54128fSAndroid Build Coastguard Worker #if HAVE_FCNTL
39*6a54128fSAndroid Build Coastguard Worker #include <fcntl.h>
40*6a54128fSAndroid Build Coastguard Worker #endif
41*6a54128fSAndroid Build Coastguard Worker #if HAVE_SYS_TYPES_H
42*6a54128fSAndroid Build Coastguard Worker #include <sys/types.h>
43*6a54128fSAndroid Build Coastguard Worker #endif
44*6a54128fSAndroid Build Coastguard Worker #include "com_err.h"
45*6a54128fSAndroid Build Coastguard Worker #include "error_table.h"
46*6a54128fSAndroid Build Coastguard Worker #include "internal.h"
47*6a54128fSAndroid Build Coastguard Worker
48*6a54128fSAndroid Build Coastguard Worker #ifdef TLS
49*6a54128fSAndroid Build Coastguard Worker #define THREAD_LOCAL static TLS
50*6a54128fSAndroid Build Coastguard Worker #else
51*6a54128fSAndroid Build Coastguard Worker #define THREAD_LOCAL static
52*6a54128fSAndroid Build Coastguard Worker #endif
53*6a54128fSAndroid Build Coastguard Worker
54*6a54128fSAndroid Build Coastguard Worker THREAD_LOCAL char buffer[25];
55*6a54128fSAndroid Build Coastguard Worker
56*6a54128fSAndroid Build Coastguard Worker struct et_list * _et_list = (struct et_list *) NULL;
57*6a54128fSAndroid Build Coastguard Worker struct et_list * _et_dynamic_list = (struct et_list *) NULL;
58*6a54128fSAndroid Build Coastguard Worker
59*6a54128fSAndroid Build Coastguard Worker #ifdef __GNUC__
60*6a54128fSAndroid Build Coastguard Worker #define COMERR_ATTR(x) __attribute__(x)
61*6a54128fSAndroid Build Coastguard Worker #else
62*6a54128fSAndroid Build Coastguard Worker #define COMERR_ATTR(x)
63*6a54128fSAndroid Build Coastguard Worker #endif
64*6a54128fSAndroid Build Coastguard Worker
65*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SEM_INIT
66*6a54128fSAndroid Build Coastguard Worker static sem_t _et_lock;
67*6a54128fSAndroid Build Coastguard Worker static int _et_lock_initialized;
68*6a54128fSAndroid Build Coastguard Worker
setup_et_lock(void)69*6a54128fSAndroid Build Coastguard Worker static void COMERR_ATTR((constructor)) setup_et_lock(void)
70*6a54128fSAndroid Build Coastguard Worker {
71*6a54128fSAndroid Build Coastguard Worker sem_init(&_et_lock, 0, 1);
72*6a54128fSAndroid Build Coastguard Worker _et_lock_initialized = 1;
73*6a54128fSAndroid Build Coastguard Worker }
74*6a54128fSAndroid Build Coastguard Worker
fini_et_lock(void)75*6a54128fSAndroid Build Coastguard Worker static void COMERR_ATTR((destructor)) fini_et_lock(void)
76*6a54128fSAndroid Build Coastguard Worker {
77*6a54128fSAndroid Build Coastguard Worker sem_destroy(&_et_lock);
78*6a54128fSAndroid Build Coastguard Worker _et_lock_initialized = 0;
79*6a54128fSAndroid Build Coastguard Worker }
80*6a54128fSAndroid Build Coastguard Worker #endif
81*6a54128fSAndroid Build Coastguard Worker
82*6a54128fSAndroid Build Coastguard Worker
et_list_lock(void)83*6a54128fSAndroid Build Coastguard Worker int et_list_lock(void)
84*6a54128fSAndroid Build Coastguard Worker {
85*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SEM_INIT
86*6a54128fSAndroid Build Coastguard Worker if (!_et_lock_initialized)
87*6a54128fSAndroid Build Coastguard Worker setup_et_lock();
88*6a54128fSAndroid Build Coastguard Worker return sem_wait(&_et_lock);
89*6a54128fSAndroid Build Coastguard Worker #else
90*6a54128fSAndroid Build Coastguard Worker return 0;
91*6a54128fSAndroid Build Coastguard Worker #endif
92*6a54128fSAndroid Build Coastguard Worker }
93*6a54128fSAndroid Build Coastguard Worker
et_list_unlock(void)94*6a54128fSAndroid Build Coastguard Worker int et_list_unlock(void)
95*6a54128fSAndroid Build Coastguard Worker {
96*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_SEM_INIT
97*6a54128fSAndroid Build Coastguard Worker if (_et_lock_initialized)
98*6a54128fSAndroid Build Coastguard Worker return sem_post(&_et_lock);
99*6a54128fSAndroid Build Coastguard Worker #endif
100*6a54128fSAndroid Build Coastguard Worker return 0;
101*6a54128fSAndroid Build Coastguard Worker }
102*6a54128fSAndroid Build Coastguard Worker
103*6a54128fSAndroid Build Coastguard Worker typedef char *(*gettextf) (const char *);
104*6a54128fSAndroid Build Coastguard Worker
105*6a54128fSAndroid Build Coastguard Worker static gettextf com_err_gettext = NULL;
106*6a54128fSAndroid Build Coastguard Worker
set_com_err_gettext(gettextf new_proc)107*6a54128fSAndroid Build Coastguard Worker gettextf set_com_err_gettext(gettextf new_proc)
108*6a54128fSAndroid Build Coastguard Worker {
109*6a54128fSAndroid Build Coastguard Worker gettextf x = com_err_gettext;
110*6a54128fSAndroid Build Coastguard Worker
111*6a54128fSAndroid Build Coastguard Worker com_err_gettext = new_proc;
112*6a54128fSAndroid Build Coastguard Worker
113*6a54128fSAndroid Build Coastguard Worker return x;
114*6a54128fSAndroid Build Coastguard Worker }
115*6a54128fSAndroid Build Coastguard Worker
116*6a54128fSAndroid Build Coastguard Worker #ifdef __GNU__
117*6a54128fSAndroid Build Coastguard Worker #define SYS_ERR_BASE 0x40000000
118*6a54128fSAndroid Build Coastguard Worker #else
119*6a54128fSAndroid Build Coastguard Worker #define SYS_ERR_BASE 0
120*6a54128fSAndroid Build Coastguard Worker #endif
121*6a54128fSAndroid Build Coastguard Worker
error_message(errcode_t code)122*6a54128fSAndroid Build Coastguard Worker const char * error_message (errcode_t code)
123*6a54128fSAndroid Build Coastguard Worker {
124*6a54128fSAndroid Build Coastguard Worker int offset;
125*6a54128fSAndroid Build Coastguard Worker struct et_list *et;
126*6a54128fSAndroid Build Coastguard Worker errcode_t table_num;
127*6a54128fSAndroid Build Coastguard Worker int started = 0;
128*6a54128fSAndroid Build Coastguard Worker char *cp;
129*6a54128fSAndroid Build Coastguard Worker
130*6a54128fSAndroid Build Coastguard Worker offset = (int) (code & ((1<<ERRCODE_RANGE)-1));
131*6a54128fSAndroid Build Coastguard Worker table_num = code - offset;
132*6a54128fSAndroid Build Coastguard Worker if (table_num == SYS_ERR_BASE) {
133*6a54128fSAndroid Build Coastguard Worker #ifdef HAS_SYS_ERRLIST
134*6a54128fSAndroid Build Coastguard Worker if (code < sys_nerr)
135*6a54128fSAndroid Build Coastguard Worker return(sys_errlist[code]);
136*6a54128fSAndroid Build Coastguard Worker else
137*6a54128fSAndroid Build Coastguard Worker goto oops;
138*6a54128fSAndroid Build Coastguard Worker #else
139*6a54128fSAndroid Build Coastguard Worker cp = strerror(code);
140*6a54128fSAndroid Build Coastguard Worker if (cp)
141*6a54128fSAndroid Build Coastguard Worker return(cp);
142*6a54128fSAndroid Build Coastguard Worker else
143*6a54128fSAndroid Build Coastguard Worker goto oops;
144*6a54128fSAndroid Build Coastguard Worker #endif
145*6a54128fSAndroid Build Coastguard Worker }
146*6a54128fSAndroid Build Coastguard Worker et_list_lock();
147*6a54128fSAndroid Build Coastguard Worker for (et = _et_list; et; et = et->next) {
148*6a54128fSAndroid Build Coastguard Worker if ((et->table->base & 0xffffffL) == (table_num & 0xffffffL)) {
149*6a54128fSAndroid Build Coastguard Worker /* This is the right table */
150*6a54128fSAndroid Build Coastguard Worker if (et->table->n_msgs <= offset) {
151*6a54128fSAndroid Build Coastguard Worker break;
152*6a54128fSAndroid Build Coastguard Worker } else {
153*6a54128fSAndroid Build Coastguard Worker const char *msg = et->table->msgs[offset];
154*6a54128fSAndroid Build Coastguard Worker et_list_unlock();
155*6a54128fSAndroid Build Coastguard Worker if (com_err_gettext)
156*6a54128fSAndroid Build Coastguard Worker return (*com_err_gettext)(msg);
157*6a54128fSAndroid Build Coastguard Worker else
158*6a54128fSAndroid Build Coastguard Worker return msg;
159*6a54128fSAndroid Build Coastguard Worker }
160*6a54128fSAndroid Build Coastguard Worker }
161*6a54128fSAndroid Build Coastguard Worker }
162*6a54128fSAndroid Build Coastguard Worker for (et = _et_dynamic_list; et; et = et->next) {
163*6a54128fSAndroid Build Coastguard Worker if ((et->table->base & 0xffffffL) == (table_num & 0xffffffL)) {
164*6a54128fSAndroid Build Coastguard Worker /* This is the right table */
165*6a54128fSAndroid Build Coastguard Worker if (et->table->n_msgs <= offset) {
166*6a54128fSAndroid Build Coastguard Worker break;
167*6a54128fSAndroid Build Coastguard Worker } else {
168*6a54128fSAndroid Build Coastguard Worker const char *msg = et->table->msgs[offset];
169*6a54128fSAndroid Build Coastguard Worker et_list_unlock();
170*6a54128fSAndroid Build Coastguard Worker if (com_err_gettext)
171*6a54128fSAndroid Build Coastguard Worker return (*com_err_gettext)(msg);
172*6a54128fSAndroid Build Coastguard Worker else
173*6a54128fSAndroid Build Coastguard Worker return msg;
174*6a54128fSAndroid Build Coastguard Worker }
175*6a54128fSAndroid Build Coastguard Worker }
176*6a54128fSAndroid Build Coastguard Worker }
177*6a54128fSAndroid Build Coastguard Worker et_list_unlock();
178*6a54128fSAndroid Build Coastguard Worker oops:
179*6a54128fSAndroid Build Coastguard Worker strcpy (buffer, "Unknown code ");
180*6a54128fSAndroid Build Coastguard Worker if (table_num) {
181*6a54128fSAndroid Build Coastguard Worker strcat (buffer, error_table_name (table_num));
182*6a54128fSAndroid Build Coastguard Worker strcat (buffer, " ");
183*6a54128fSAndroid Build Coastguard Worker }
184*6a54128fSAndroid Build Coastguard Worker for (cp = buffer; *cp; cp++)
185*6a54128fSAndroid Build Coastguard Worker ;
186*6a54128fSAndroid Build Coastguard Worker if (offset >= 100) {
187*6a54128fSAndroid Build Coastguard Worker *cp++ = '0' + offset / 100;
188*6a54128fSAndroid Build Coastguard Worker offset %= 100;
189*6a54128fSAndroid Build Coastguard Worker started++;
190*6a54128fSAndroid Build Coastguard Worker }
191*6a54128fSAndroid Build Coastguard Worker if (started || offset >= 10) {
192*6a54128fSAndroid Build Coastguard Worker *cp++ = '0' + offset / 10;
193*6a54128fSAndroid Build Coastguard Worker offset %= 10;
194*6a54128fSAndroid Build Coastguard Worker }
195*6a54128fSAndroid Build Coastguard Worker *cp++ = '0' + offset;
196*6a54128fSAndroid Build Coastguard Worker *cp = '\0';
197*6a54128fSAndroid Build Coastguard Worker return(buffer);
198*6a54128fSAndroid Build Coastguard Worker }
199*6a54128fSAndroid Build Coastguard Worker
200*6a54128fSAndroid Build Coastguard Worker /*
201*6a54128fSAndroid Build Coastguard Worker * This routine will only return a value if the we are not running as
202*6a54128fSAndroid Build Coastguard Worker * a privileged process.
203*6a54128fSAndroid Build Coastguard Worker */
safe_getenv(const char * arg)204*6a54128fSAndroid Build Coastguard Worker static char *safe_getenv(const char *arg)
205*6a54128fSAndroid Build Coastguard Worker {
206*6a54128fSAndroid Build Coastguard Worker #if !defined(_WIN32)
207*6a54128fSAndroid Build Coastguard Worker if ((getuid() != geteuid()) || (getgid() != getegid()))
208*6a54128fSAndroid Build Coastguard Worker return NULL;
209*6a54128fSAndroid Build Coastguard Worker #endif
210*6a54128fSAndroid Build Coastguard Worker #if HAVE_PRCTL
211*6a54128fSAndroid Build Coastguard Worker if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
212*6a54128fSAndroid Build Coastguard Worker return NULL;
213*6a54128fSAndroid Build Coastguard Worker #else
214*6a54128fSAndroid Build Coastguard Worker #if (defined(linux) && defined(SYS_prctl))
215*6a54128fSAndroid Build Coastguard Worker if (syscall(SYS_prctl, PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
216*6a54128fSAndroid Build Coastguard Worker return NULL;
217*6a54128fSAndroid Build Coastguard Worker #endif
218*6a54128fSAndroid Build Coastguard Worker #endif
219*6a54128fSAndroid Build Coastguard Worker
220*6a54128fSAndroid Build Coastguard Worker #if defined(HAVE_SECURE_GETENV)
221*6a54128fSAndroid Build Coastguard Worker return secure_getenv(arg);
222*6a54128fSAndroid Build Coastguard Worker #elif defined(HAVE___SECURE_GETENV)
223*6a54128fSAndroid Build Coastguard Worker return __secure_getenv(arg);
224*6a54128fSAndroid Build Coastguard Worker #else
225*6a54128fSAndroid Build Coastguard Worker return getenv(arg);
226*6a54128fSAndroid Build Coastguard Worker #endif
227*6a54128fSAndroid Build Coastguard Worker }
228*6a54128fSAndroid Build Coastguard Worker
229*6a54128fSAndroid Build Coastguard Worker #define DEBUG_INIT 0x8000
230*6a54128fSAndroid Build Coastguard Worker #define DEBUG_ADDREMOVE 0x0001
231*6a54128fSAndroid Build Coastguard Worker
232*6a54128fSAndroid Build Coastguard Worker static int debug_mask = 0;
233*6a54128fSAndroid Build Coastguard Worker static FILE *debug_f = 0;
234*6a54128fSAndroid Build Coastguard Worker
init_debug(void)235*6a54128fSAndroid Build Coastguard Worker static void init_debug(void)
236*6a54128fSAndroid Build Coastguard Worker {
237*6a54128fSAndroid Build Coastguard Worker char *dstr, *fn, *tmp;
238*6a54128fSAndroid Build Coastguard Worker
239*6a54128fSAndroid Build Coastguard Worker if (debug_mask & DEBUG_INIT)
240*6a54128fSAndroid Build Coastguard Worker return;
241*6a54128fSAndroid Build Coastguard Worker
242*6a54128fSAndroid Build Coastguard Worker dstr = getenv("COMERR_DEBUG");
243*6a54128fSAndroid Build Coastguard Worker if (dstr) {
244*6a54128fSAndroid Build Coastguard Worker debug_mask = strtoul(dstr, &tmp, 0);
245*6a54128fSAndroid Build Coastguard Worker if (*tmp || errno)
246*6a54128fSAndroid Build Coastguard Worker debug_mask = 0;
247*6a54128fSAndroid Build Coastguard Worker }
248*6a54128fSAndroid Build Coastguard Worker
249*6a54128fSAndroid Build Coastguard Worker debug_mask |= DEBUG_INIT;
250*6a54128fSAndroid Build Coastguard Worker if (debug_mask == DEBUG_INIT)
251*6a54128fSAndroid Build Coastguard Worker return;
252*6a54128fSAndroid Build Coastguard Worker
253*6a54128fSAndroid Build Coastguard Worker fn = safe_getenv("COMERR_DEBUG_FILE");
254*6a54128fSAndroid Build Coastguard Worker if (fn)
255*6a54128fSAndroid Build Coastguard Worker debug_f = fopen(fn, "a");
256*6a54128fSAndroid Build Coastguard Worker if (!debug_f)
257*6a54128fSAndroid Build Coastguard Worker debug_f = fopen("/dev/tty", "a");
258*6a54128fSAndroid Build Coastguard Worker if (debug_f) {
259*6a54128fSAndroid Build Coastguard Worker #ifdef HAVE_FCNTL
260*6a54128fSAndroid Build Coastguard Worker int fd = fileno(debug_f);
261*6a54128fSAndroid Build Coastguard Worker
262*6a54128fSAndroid Build Coastguard Worker if (fd >= 0) {
263*6a54128fSAndroid Build Coastguard Worker int flags = fcntl(fd, F_GETFD);
264*6a54128fSAndroid Build Coastguard Worker
265*6a54128fSAndroid Build Coastguard Worker if (flags >= 0)
266*6a54128fSAndroid Build Coastguard Worker flags = fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
267*6a54128fSAndroid Build Coastguard Worker if (flags < 0) {
268*6a54128fSAndroid Build Coastguard Worker fprintf(debug_f, "Couldn't set FD_CLOEXEC "
269*6a54128fSAndroid Build Coastguard Worker "on debug FILE: %s\n", strerror(errno));
270*6a54128fSAndroid Build Coastguard Worker fclose(debug_f);
271*6a54128fSAndroid Build Coastguard Worker debug_f = NULL;
272*6a54128fSAndroid Build Coastguard Worker debug_mask = DEBUG_INIT;
273*6a54128fSAndroid Build Coastguard Worker }
274*6a54128fSAndroid Build Coastguard Worker }
275*6a54128fSAndroid Build Coastguard Worker #endif
276*6a54128fSAndroid Build Coastguard Worker } else
277*6a54128fSAndroid Build Coastguard Worker debug_mask = DEBUG_INIT;
278*6a54128fSAndroid Build Coastguard Worker }
279*6a54128fSAndroid Build Coastguard Worker
280*6a54128fSAndroid Build Coastguard Worker /*
281*6a54128fSAndroid Build Coastguard Worker * New interface provided by krb5's com_err library
282*6a54128fSAndroid Build Coastguard Worker */
add_error_table(const struct error_table * et)283*6a54128fSAndroid Build Coastguard Worker errcode_t add_error_table(const struct error_table * et)
284*6a54128fSAndroid Build Coastguard Worker {
285*6a54128fSAndroid Build Coastguard Worker struct et_list *el;
286*6a54128fSAndroid Build Coastguard Worker
287*6a54128fSAndroid Build Coastguard Worker if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
288*6a54128fSAndroid Build Coastguard Worker return ENOMEM;
289*6a54128fSAndroid Build Coastguard Worker
290*6a54128fSAndroid Build Coastguard Worker if (et_list_lock() != 0) {
291*6a54128fSAndroid Build Coastguard Worker free(el);
292*6a54128fSAndroid Build Coastguard Worker return errno;
293*6a54128fSAndroid Build Coastguard Worker }
294*6a54128fSAndroid Build Coastguard Worker
295*6a54128fSAndroid Build Coastguard Worker el->table = et;
296*6a54128fSAndroid Build Coastguard Worker el->next = _et_dynamic_list;
297*6a54128fSAndroid Build Coastguard Worker _et_dynamic_list = el;
298*6a54128fSAndroid Build Coastguard Worker
299*6a54128fSAndroid Build Coastguard Worker init_debug();
300*6a54128fSAndroid Build Coastguard Worker if (debug_mask & DEBUG_ADDREMOVE)
301*6a54128fSAndroid Build Coastguard Worker fprintf(debug_f, "add_error_table: %s (0x%p)\n",
302*6a54128fSAndroid Build Coastguard Worker error_table_name(et->base),
303*6a54128fSAndroid Build Coastguard Worker (const void *) et);
304*6a54128fSAndroid Build Coastguard Worker
305*6a54128fSAndroid Build Coastguard Worker et_list_unlock();
306*6a54128fSAndroid Build Coastguard Worker return 0;
307*6a54128fSAndroid Build Coastguard Worker }
308*6a54128fSAndroid Build Coastguard Worker
309*6a54128fSAndroid Build Coastguard Worker /*
310*6a54128fSAndroid Build Coastguard Worker * New interface provided by krb5's com_err library
311*6a54128fSAndroid Build Coastguard Worker */
remove_error_table(const struct error_table * et)312*6a54128fSAndroid Build Coastguard Worker errcode_t remove_error_table(const struct error_table * et)
313*6a54128fSAndroid Build Coastguard Worker {
314*6a54128fSAndroid Build Coastguard Worker struct et_list *el;
315*6a54128fSAndroid Build Coastguard Worker struct et_list *el2 = 0;
316*6a54128fSAndroid Build Coastguard Worker
317*6a54128fSAndroid Build Coastguard Worker if (et_list_lock() != 0)
318*6a54128fSAndroid Build Coastguard Worker return ENOENT;
319*6a54128fSAndroid Build Coastguard Worker
320*6a54128fSAndroid Build Coastguard Worker el = _et_dynamic_list;
321*6a54128fSAndroid Build Coastguard Worker init_debug();
322*6a54128fSAndroid Build Coastguard Worker while (el) {
323*6a54128fSAndroid Build Coastguard Worker if (el->table->base == et->base) {
324*6a54128fSAndroid Build Coastguard Worker if (el2) /* Not the beginning of the list */
325*6a54128fSAndroid Build Coastguard Worker el2->next = el->next;
326*6a54128fSAndroid Build Coastguard Worker else
327*6a54128fSAndroid Build Coastguard Worker _et_dynamic_list = el->next;
328*6a54128fSAndroid Build Coastguard Worker (void) free(el);
329*6a54128fSAndroid Build Coastguard Worker if (debug_mask & DEBUG_ADDREMOVE)
330*6a54128fSAndroid Build Coastguard Worker fprintf(debug_f,
331*6a54128fSAndroid Build Coastguard Worker "remove_error_table: %s (0x%p)\n",
332*6a54128fSAndroid Build Coastguard Worker error_table_name(et->base),
333*6a54128fSAndroid Build Coastguard Worker (const void *) et);
334*6a54128fSAndroid Build Coastguard Worker et_list_unlock();
335*6a54128fSAndroid Build Coastguard Worker return 0;
336*6a54128fSAndroid Build Coastguard Worker }
337*6a54128fSAndroid Build Coastguard Worker el2 = el;
338*6a54128fSAndroid Build Coastguard Worker el = el->next;
339*6a54128fSAndroid Build Coastguard Worker }
340*6a54128fSAndroid Build Coastguard Worker if (debug_mask & DEBUG_ADDREMOVE)
341*6a54128fSAndroid Build Coastguard Worker fprintf(debug_f, "remove_error_table FAILED: %s (0x%p)\n",
342*6a54128fSAndroid Build Coastguard Worker error_table_name(et->base),
343*6a54128fSAndroid Build Coastguard Worker (const void *) et);
344*6a54128fSAndroid Build Coastguard Worker et_list_unlock();
345*6a54128fSAndroid Build Coastguard Worker return ENOENT;
346*6a54128fSAndroid Build Coastguard Worker }
347*6a54128fSAndroid Build Coastguard Worker
348*6a54128fSAndroid Build Coastguard Worker /*
349*6a54128fSAndroid Build Coastguard Worker * Variant of the interface provided by Heimdal's com_err library
350*6a54128fSAndroid Build Coastguard Worker */
351*6a54128fSAndroid Build Coastguard Worker void
add_to_error_table(struct et_list * new_table)352*6a54128fSAndroid Build Coastguard Worker add_to_error_table(struct et_list *new_table)
353*6a54128fSAndroid Build Coastguard Worker {
354*6a54128fSAndroid Build Coastguard Worker add_error_table(new_table->table);
355*6a54128fSAndroid Build Coastguard Worker }
356