Debian Codegraph @

src/common/error.c

raw symbols SCIP
1
2 /*
3 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
4 * All Rights Reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Authors:
21 * Lukas Kuklinek <[email protected]>
22 */
23
24 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
25 #include <config.h>cxx . . $ `<file>/build/config.h`/
26 #endif
27
28 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
29 #include <pthread.h>
30 #endif
31 #include <string.h>
32
33 #include "util.h"cxx . . $ `<file>/src/common/util.h`/
34 #include "_error.h"cxx . . $ `<file>/src/common/_error.h`/
35 #include "err_queue.h"cxx . . $ `<file>/src/common/err_queue.h`/
36 #include "debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
37 #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
38
39 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
40 static pthread_key_tcxx . . $ pthread_key_t# __keycxx . . $ __key.;
41 static pthread_once_tcxx . . $ pthread_once_t# __oncecxx . . $ __once. = PTHREAD_ONCE_INITcxx . . $ `<external>/14712363683955484316/pthread.h:186:9`!;
42 #else
43 struct err_queue *q = NULL;
44 #endif
45
46 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
47 static void oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).(void)
48 {
49 (void)pthread_key_createcxx . . $ pthread_key_create(27e8d8ad44765b90).(&__keycxx . . $ __key., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
50 }
51 #endif
52
53 static struct oscap_err_tcxx . . $ oscap_err_t# *oscap_err_newcxx . . $ oscap_err_new(dfa1a21fe07360dd).(oscap_errfamily_tcxx . . $ oscap_errfamily_t# family, const char *desc,
54 const char *func, uint32_tcxx . . $ uint32_t# line, const char *file)
55 {
56 struct oscap_err_tcxx . . $ oscap_err_t# *err = (struct oscap_err_tcxx . . $ oscap_err_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct oscap_err_tcxx . . $ oscap_err_t#));
57 err->familycxx . . $ oscap_err_t#family. = family;
58 err->desccxx . . $ oscap_err_t#desc. = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s [%s:%d]", desc, file, line);
59 err->funccxx . . $ oscap_err_t#func. = func;
60 err->linecxx . . $ oscap_err_t#line. = line;
61 err->filecxx . . $ oscap_err_t#file. = file;
62
63 return (err);
64 }
65
66 static void oscap_err_freecxx . . $ oscap_err_free(33df0e5de56ab794).(struct oscap_err_tcxx . . $ oscap_err_t# *err)
67 {
68 if (err->desccxx . . $ oscap_err_t#desc. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
69 freecxx . . $ free(5d22bdacc48458e8).(err->desccxx . . $ oscap_err_t#desc.);
70 freecxx . . $ free(5d22bdacc48458e8).(err);
71 }
72
73 static inline void _push_errcxx . . $ _push_err(33df0e5de56ab794).(struct oscap_err_tcxx . . $ oscap_err_t# *err)
74 {
75 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
76 struct err_queuecxx . . $ err_queue# *q = pthread_getspecificcxx . . $ pthread_getspecific(52408c21a1e21ff7).(__keycxx . . $ __key.);
77 #endif
78 if (q == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) {
79 q = err_queue_newcxx . . $ err_queue_new(14ccda84b3465fef).();
80 assertcxx . . $ `/usr/include/assert.h:50:10`!(q != NULL);
81 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
82 (void)pthread_setspecificcxx . . $ pthread_setspecific(d365db6b7b881e77).(__keycxx . . $ __key., q);
83 #endif
84 }
85 (void)err_queue_pushcxx . . $ err_queue_push(130f920746fcff31).(q, err);
86 }
87
88 void __oscap_setxmlerrcxx . . $ __oscap_setxmlerr(232bac446a1df277).(const char *file, uint32_tcxx . . $ uint32_t# line, const char *func, const xmlErrorcxx . . $ xmlError# *error)
89 {
90
91 if (error == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
92 return;
93
94 struct oscap_err_tcxx . . $ oscap_err_t# *err;
95 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
96 (void)pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oncecxx . . $ __once., oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).);
97 #endif
98
99 /* get rid of a newline that was pass by xmlGetLastError() */
100 int len = strlencxx . . $ strlen(751346f8406fd082).(error->messagecxx . . $ _xmlError#message.);
101 if (len != 0 && error->messagecxx . . $ _xmlError#message.[len - 1] == '\n')
102 error->messagecxx . . $ _xmlError#message.[len-1] = 0;
103 if (error->filecxx . . $ _xmlError#file. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) {
104 char *msg = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("%s [%s:%d]", error->messagecxx . . $ _xmlError#message., error->filecxx . . $ _xmlError#file., error->linecxx . . $ _xmlError#line.);
105 if (msg != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) {
106 err = oscap_err_newcxx . . $ oscap_err_new(dfa1a21fe07360dd).(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, msg, func, line, file);
107 freecxx . . $ free(5d22bdacc48458e8).(msg);
108 _push_errcxx . . $ _push_err(33df0e5de56ab794).(err);
109 return;
110 }
111 }
112
113 err = oscap_err_newcxx . . $ oscap_err_new(dfa1a21fe07360dd).(OSCAP_EFAMILY_XMLcxx . . $ `src/common/public/oscap_error.h:59:9`!, error->messagecxx . . $ _xmlError#message., func, line, file);
114 _push_errcxx . . $ _push_err(33df0e5de56ab794).(err);
115 }
116
117 void __oscap_seterrcxx . . $ __oscap_seterr(4e2a17a716e00309).(const char *file, uint32_tcxx . . $ uint32_t# line, const char *func, oscap_errfamily_tcxx . . $ oscap_errfamily_t# family, const char *fmt, ...)
118 {
119 struct oscap_err_tcxx . . $ oscap_err_t# *err;
120 char *msg;
121 va_listcxx . . $ va_list# ap;
122
123 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
124 (void)pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oncecxx . . $ __once., oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).);
125 #endif
126
127 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(ap, fmt);
128 msg = oscap_vsprintfcxx . . $ oscap_vsprintf(db813db1ba4aba5a).(fmt, ap);
129 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(ap);
130
131 err = oscap_err_newcxx . . $ oscap_err_new(dfa1a21fe07360dd).(family, msg, func, line, file);
132
133 freecxx . . $ free(5d22bdacc48458e8).(msg);
134 _push_errcxx . . $ _push_err(33df0e5de56ab794).(err);
135 }
136
137 void oscap_clearerrcxx . . $ oscap_clearerr(49f6e7a06ebc5aa8).(void)
138 {
139 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
140 struct err_queuecxx . . $ err_queue# *q;
141
142 (void)pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oncecxx . . $ __once., oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).);
143
144 q = pthread_getspecificcxx . . $ pthread_getspecific(52408c21a1e21ff7).(__keycxx . . $ __key.);
145 (void)pthread_setspecificcxx . . $ pthread_setspecific(d365db6b7b881e77).(__keycxx . . $ __key., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
146 #endif
147 err_queue_freecxx . . $ err_queue_free(db4c3ce443b7b377).(q, (oscap_destruct_funccxx . . $ oscap_destruct_func#) oscap_err_freecxx . . $ oscap_err_free(33df0e5de56ab794).);
148 }
149
150 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! oscap_errcxx . . $ oscap_err(c9857a73d68e59ba).(void)
151 {
152 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
153 (void)pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oncecxx . . $ __once., oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).);
154 struct err_queuecxx . . $ err_queue# *q = pthread_getspecificcxx . . $ pthread_getspecific(52408c21a1e21ff7).(__keycxx . . $ __key.);
155 #endif
156 return (q != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && !err_queue_is_emptycxx . . $ err_queue_is_empty(ac3ca0b8c1867adc).(q));
157 }
158
159 oscap_errfamily_tcxx . . $ oscap_errfamily_t# oscap_err_familycxx . . $ oscap_err_family(32a7769d58713265).(void)
160 {
161 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
162 struct err_queuecxx . . $ err_queue# *q;
163
164 (void)pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oncecxx . . $ __once., oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).);
165 q = pthread_getspecificcxx . . $ pthread_getspecific(52408c21a1e21ff7).(__keycxx . . $ __key.);
166 #endif
167
168 if (q == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || err_queue_is_emptycxx . . $ err_queue_is_empty(ac3ca0b8c1867adc).(q))
169 return 0;
170 return err_queue_get_lastcxx . . $ err_queue_get_last(e5bbd80691f081f8).(q)->familycxx . . $ oscap_err_t#family.;
171 }
172
173 const char *oscap_err_desccxx . . $ oscap_err_desc(33a1f659e94feb42).(void)
174 {
175 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
176 struct err_queuecxx . . $ err_queue# *q;
177
178 (void)pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oncecxx . . $ __once., oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).);
179 q = pthread_getspecificcxx . . $ pthread_getspecific(52408c21a1e21ff7).(__keycxx . . $ __key.);
180 #endif
181
182 if (q == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || err_queue_is_emptycxx . . $ err_queue_is_empty(ac3ca0b8c1867adc).(q))
183 return 0;
184 return (const char *) err_queue_get_lastcxx . . $ err_queue_get_last(e5bbd80691f081f8).(q)->desccxx . . $ oscap_err_t#desc.;
185 }
186
187 char *oscap_err_get_full_errorcxx . . $ oscap_err_get_full_error(41208ce6ca65dd58).(void)
188 {
189 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
190 struct err_queuecxx . . $ err_queue# *q;
191 (void)pthread_oncecxx . . $ pthread_once(95e4b41df204d8e2).(&__oncecxx . . $ __once., oscap_errkey_initcxx . . $ oscap_errkey_init(49f6e7a06ebc5aa8).);
192 q = pthread_getspecificcxx . . $ pthread_getspecific(52408c21a1e21ff7).(__keycxx . . $ __key.);
193 #endif
194
195 char *res = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
196 if (q == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || err_queue_is_emptycxx . . $ err_queue_is_empty(ac3ca0b8c1867adc).(q))
197 return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
198 if (err_queue_to_stringcxx . . $ err_queue_to_string(11c23276edec036e).(q, &res) != 0)
199 return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
200
201 #ifdef OSCAP_THREAD_SAFEcxx . . $ `build/config.h:13:9`!
202 (void)pthread_setspecificcxx . . $ pthread_setspecific(d365db6b7b881e77).(__keycxx . . $ __key., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!);
203 #endif
204 err_queue_freecxx . . $ err_queue_free(db4c3ce443b7b377).(q, (oscap_destruct_funccxx . . $ oscap_destruct_func#) oscap_err_freecxx . . $ oscap_err_free(33df0e5de56ab794).);
205 return res;
206 }