Debian Codegraph @

src/OVAL/probes/probe/input_handler.c

raw symbols SCIP
1 /*
2 * Copyright 2011 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * Daniel Kopecek <[email protected]>
21 */
22
23 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
24 #include <config.h>cxx . . $ `<file>/build/config.h`/
25 #endif
26
27 #include <errno.h>
28 #include <pthread.h>
29 #include <string.h>
30 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
31 #include <probe-api.h>cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
32
33 #if defined(OS_FREEBSD)
34 #include <pthread_np.h>
35 #endif
36
37 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
38 #include "../SEAP/generic/rbt/rbt.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/generic/rbt/rbt.h`/
39 #include "probe.h"cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
40 #include "worker.h"cxx . . $ `<file>/src/OVAL/probes/probe/worker.h`/
41 #include "rcache.h"cxx . . $ `<file>/src/OVAL/probes/probe/rcache.h`/
42 #include "input_handler.h"cxx . . $ `<file>/src/OVAL/probes/probe/input_handler.h`/
43 #include "common/compat_pthread_barrier.h"cxx . . $ `<file>/src/common/compat_pthread_barrier.h`/
44
45 static void pthread_attr_cleanup_handlercxx . . $ pthread_attr_cleanup_handler(5d22bdacc48458e8).(void *arg)
46 {
47 pthread_attr_destroycxx . . $ pthread_attr_destroy(26f1688c57ac69c9).(arg);
48 }
49
50 /*
51 * The input handler waits for incomming eval requests and either returns
52 * a result immediately if it is found in the result cache or spawns a new
53 * worker thread which takes care of evaluating the request, caching the
54 * result and sending it to the requestee.
55 */
56 void *probe_input_handlercxx . . $ probe_input_handler(9f162e79bfc6c74).(void *arg)
57 {
58 pthread_attr_tcxx . . $ pthread_attr_t# pth_attr;
59 probe_tcxx . . $ probe_t# *probe = (probe_tcxx . . $ probe_t# *)arg;
60
61 int probe_ret, cstate; /* XXX */
62 SEAP_msg_tcxx . . $ SEAP_msg_t# *seap_request, *seap_reply;
63 SEXP_tcxx . . $ SEXP_t# *probe_in, *probe_out, *oid;
64
65 #if defined(HAVE_PTHREAD_SETNAME_NPcxx . . $ `build/config.h:53:9`!)
66 # if defined(OS_APPLE)
67 pthread_setname_np("input_handler");
68 # else
69 pthread_setname_npcxx . . $ pthread_setname_np(bee54c13bee684da).(pthread_selfcxx . . $ pthread_self(f708dce9a8856c70).(), "input_handler");
70 # endif
71 #endif
72
73 #define TH_CANCEL_ONcxx . . $ `src/OVAL/probes/probe/input_handler.c:73:9`! pthread_setcancelstate(PTHREAD_CANCEL_ENABLEcxx . . $ `<external>/14712363683955484316/pthread.h:171:9`!, &cstate)
74 #define TH_CANCEL_OFFcxx . . $ `src/OVAL/probes/probe/input_handler.c:74:9`! pthread_setcancelstate(PTHREAD_CANCEL_DISABLEcxx . . $ `<external>/14712363683955484316/pthread.h:173:9`!, &cstate)
75
76 TH_CANCEL_OFFcxx . . $ `src/OVAL/probes/probe/input_handler.c:74:9`!;
77
78 if (pthread_attr_initcxx . . $ pthread_attr_init(26f1688c57ac69c9).(&pth_attr))
79 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
80
81 if (pthread_attr_setdetachstatecxx . . $ pthread_attr_setdetachstate(1c205214b8a99ab8).(&pth_attr, PTHREAD_CREATE_JOINABLEcxx . . $ `<external>/14712363683955484316/pthread.h:40:9`!)) {
82 pthread_attr_destroycxx . . $ pthread_attr_destroy(26f1688c57ac69c9).(&pth_attr);
83 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
84 }
85
86 pthread_cleanup_pushcxx . . $ `<external>/14712363683955484316/pthread.h:681:10`!(pthread_attr_cleanup_handler, (void *)&pth_attr);
87
88 switch (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = pthread_barrier_waitcxx . . $ pthread_barrier_wait(6183b0e2072457c0).(probe->th_barriercxx . . $ $anonymous_type_3aeea60fe9979420_0#th_barrier.))
89 {
90 case 0:
91 case PTHREAD_BARRIER_SERIAL_THREADcxx . . $ `<external>/14712363683955484316/pthread.h:193:10`!:
92 break;
93 default:
94 dEcxx . . $ `src/common/debug_priv.h:63:9`!("pthread_barrier_wait: %d, %s.",
95 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
96 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
97 }
98
99 while(1) {
100 TH_CANCEL_ONcxx . . $ `src/OVAL/probes/probe/input_handler.c:73:9`!;
101
102 if (SEAP_recvmsgcxx . . $ SEAP_recvmsg(548af285d41333c4).(probe->SEAP_ctxcxx . . $ $anonymous_type_3aeea60fe9979420_0#SEAP_ctx., probe->sdcxx . . $ $anonymous_type_3aeea60fe9979420_0#sd., &seap_request) == -1) {
103 dEcxx . . $ `src/common/debug_priv.h:63:9`!("An error ocured while receiving SEAP message. errno=%u, %s.", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
104
105 /*
106 * TODO: check for abort request
107 */
108 break;
109 }
110
111 TH_CANCEL_OFFcxx . . $ `src/OVAL/probes/probe/input_handler.c:74:9`!;
112
113 probe_in = SEAP_msg_getcxx . . $ SEAP_msg_get(265ef69b98da50a9).(seap_request);
114
115 if (probe_in == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
116 abortcxx . . $ abort(8df32a62017fbbf6).();
117
118 SEXP_VALIDATEcxx . . $ `src/OVAL/probes/SEAP/public/sexp-manip.h:576:10`!(probe_in);
119
120 /*
121 * Get a reference to the `id' attribute of the input object. The value
122 * of this attribute is the OVAL object ID and serves as a key in the
123 * result cache.
124 */
125 oid = probe_obj_getattrvalcxx . . $ probe_obj_getattrval(42b37380d22a3312).(probe_in, "id");
126
127 if (oid != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
128 SEXP_VALIDATEcxx . . $ `src/OVAL/probes/SEAP/public/sexp-manip.h:576:10`!(oid);
129 probe_out = probe_rcache_sexp_getcxx . . $ probe_rcache_sexp_get(ce64d4c7f6269eda).(probe->rcachecxx . . $ $anonymous_type_3aeea60fe9979420_0#rcache., oid);
130
131 if (probe_out == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { /* cache miss */
132 SEXP_tcxx . . $ SEXP_t# *skip_flag, *obj_mask;
133
134 skip_flag = probe_obj_getattrvalcxx . . $ probe_obj_getattrval(42b37380d22a3312).(probe_in, "skip_eval");
135 obj_mask = probe_obj_getmaskcxx . . $ probe_obj_getmask(478b347fcbbad3c5).(probe_in);
136 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(probe_in);
137 probe_in = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
138
139 if (skip_flag != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
140 oval_syschar_collection_flag_tcxx . . $ oval_syschar_collection_flag_t# cobj_flag;
141
142 cobj_flag = SEXP_number_geti_32cxx . . $ SEXP_number_geti_32(e77439d026b7e3ce).(skip_flag);
143 probe_out = probe_cobj_newcxx . . $ probe_cobj_new(4e082355872fd045).(cobj_flag, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, obj_mask);
144
145 if (probe_rcache_sexp_addcxx . . $ probe_rcache_sexp_add(2a038249cafd8515).(probe->rcachecxx . . $ $anonymous_type_3aeea60fe9979420_0#rcache., oid, probe_out) != 0) {
146 /* TODO */
147 abortcxx . . $ abort(8df32a62017fbbf6).();
148 }
149
150 probe_ret = 0;
151 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(oid);
152 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(skip_flag);
153 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(obj_mask);
154 } else {
155
156 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(oid);
157 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(skip_flag);
158 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(obj_mask);
159
160 probe_pwpair_tcxx . . $ probe_pwpair_t# *pair = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(probe_pwpair_tcxx . . $ probe_pwpair_t#));
161 pair->probecxx . . $ $anonymous_type_f5d5f76501d695aa_1#probe. = probe;
162 pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth. = probe_worker_newcxx . . $ probe_worker_new(9faedb07d76d304d).();
163 pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.->sidcxx . . $ $anonymous_type_f5d5f76501d695aa_0#sid. = SEAP_msg_idcxx . . $ SEAP_msg_id(18c00517003ebe74).(seap_request);
164 pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.->msgcxx . . $ $anonymous_type_f5d5f76501d695aa_0#msg. = seap_request;
165 pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.->msg_handlercxx . . $ $anonymous_type_f5d5f76501d695aa_0#msg_handler. = &probe_workercxx . . $ probe_worker(9568d6155da1d3b6).;
166
167 if (rbt_i32_addcxx . . $ rbt_i32_add(3215e2e734e57b31).(probe->workerscxx . . $ $anonymous_type_3aeea60fe9979420_0#workers., pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.->sidcxx . . $ $anonymous_type_f5d5f76501d695aa_0#sid., pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) != 0) {
168 /*
169 * Getting here means that there is already a
170 * thread handling the message with the given
171 * ID.
172 */
173 dWcxx . . $ `src/common/debug_priv.h:62:9`!("Attempt to evaluate an object "
174 "(ID=%u) " // TODO: 64b IDs
175 "which is already being evaluated by another thread.", pair->pth->sid);
176
177 freecxx . . $ free(5d22bdacc48458e8).(pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.);
178 freecxx . . $ free(5d22bdacc48458e8).(pair);
179 SEAP_msg_freecxx . . $ SEAP_msg_free(4995d55015d41e57).(seap_request);
180 } else {
181 /* OK */
182
183 if (pthread_createcxx . . $ pthread_create(2141a84bcac899e5).(&pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.->tidcxx . . $ $anonymous_type_f5d5f76501d695aa_0#tid., &pth_attr, &probe_worker_runfncxx . . $ probe_worker_runfn(9f162e79bfc6c74)., pair))
184 {
185 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Cannot start a new worker thread: %d, %s.", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
186
187 if (rbt_i32_delcxx . . $ rbt_i32_del(fbdfcf5a3c6c46ec).(probe->workerscxx . . $ $anonymous_type_3aeea60fe9979420_0#workers., pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.->sidcxx . . $ $anonymous_type_f5d5f76501d695aa_0#sid., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) != 0)
188 dEcxx . . $ `src/common/debug_priv.h:63:9`!("rbt_i32_del: failed to remove worker thread (ID=%u)", pair->pth->sid);
189
190 SEAP_msg_freecxx . . $ SEAP_msg_free(4995d55015d41e57).(pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.->msgcxx . . $ $anonymous_type_f5d5f76501d695aa_0#msg.);
191 freecxx . . $ free(5d22bdacc48458e8).(pair->pthcxx . . $ $anonymous_type_f5d5f76501d695aa_1#pth.);
192 freecxx . . $ free(5d22bdacc48458e8).(pair);
193
194 probe_ret = PROBE_EUNKNOWNcxx . . $ `src/OVAL/probes/public/probe-common.h:24:9`!;
195 probe_out = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
196
197 goto __error_reply;
198 }
199 }
200
201 seap_request = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
202 continue;
203 }
204 } else {
205 /* cache hit */
206 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(oid);
207 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(probe_in);
208 probe_ret = 0;
209 }
210 } else {
211 /* the `id' was not found in the input object */
212 dEcxx . . $ `src/common/debug_priv.h:63:9`!("No `id' attribute");
213 probe_ret = PROBE_ENOATTRcxx . . $ `src/OVAL/probes/public/probe-common.h:11:9`!;
214 probe_out = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
215 }
216
217 if (probe_out == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || probe_ret != 0) {
218 __error_reply:
219 if (SEAP_replyerrcxx . . $ SEAP_replyerr(9c3156c1fad5b304).(probe->SEAP_ctxcxx . . $ $anonymous_type_3aeea60fe9979420_0#SEAP_ctx., probe->sdcxx . . $ $anonymous_type_3aeea60fe9979420_0#sd., seap_request, probe_ret) == -1)
220 {
221 dEcxx . . $ `src/common/debug_priv.h:63:9`!("An error ocured while sending error status. errno=%u, %s.",
222 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
223
224 SEAP_msg_freecxx . . $ SEAP_msg_free(4995d55015d41e57).(seap_request);
225 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(probe_in);
226
227 break;
228 }
229 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(probe_in);
230 } else {
231 SEXP_VALIDATEcxx . . $ `src/OVAL/probes/SEAP/public/sexp-manip.h:576:10`!(probe_out);
232
233 seap_reply = SEAP_msg_newcxx . . $ SEAP_msg_new(b76a66c6f733d68f).();
234 SEAP_msg_setcxx . . $ SEAP_msg_set(780f103242f3120a).(seap_reply, probe_out);
235 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(probe_out);
236
237 if (SEAP_replycxx . . $ SEAP_reply(86996c4f120c23bc).(probe->SEAP_ctxcxx . . $ $anonymous_type_3aeea60fe9979420_0#SEAP_ctx., probe->sdcxx . . $ $anonymous_type_3aeea60fe9979420_0#sd., seap_reply, seap_request) == -1) {
238 dEcxx . . $ `src/common/debug_priv.h:63:9`!("An error ocured while sending SEAP message. errno=%u, %s.",
239 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
240
241 /* TODO: check for abort request */
242 SEAP_msg_freecxx . . $ SEAP_msg_free(4995d55015d41e57).(seap_reply);
243 SEAP_msg_freecxx . . $ SEAP_msg_free(4995d55015d41e57).(seap_request);
244
245 break;
246 }
247
248 SEAP_msg_freecxx . . $ SEAP_msg_free(4995d55015d41e57).(seap_reply);
249 }
250
251 SEAP_msg_freecxx . . $ SEAP_msg_free(4995d55015d41e57).(seap_request);
252 } /* main loop */
253
254 pthread_cleanup_popcxx . . $ `<external>/14712363683955484316/pthread.h:702:10`!(1);
255 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
256 }