| 1 | /* |
| 2 | * Copyright 2018 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 | * "Jan Černý" <[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 <stdlib.h> |
| 28 | |
| 29 | #include "_sexp-types.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_sexp-types.h`/ |
| 30 | #include "_seap-types.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap-types.h`/ |
| 31 | #include "sch_queue.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/sch_queue.h`/ |
| 32 | #include "seap-descriptor.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/seap-descriptor.h`/ |
| 33 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 34 | #include "../probe/probe_main.h"cxx . . $ `<file>/src/OVAL/probes/probe/probe_main.h`/ |
| 35 | #include "oval_definitions.h"cxx . . $ `<file>/src/OVAL/public/oval_definitions.h`/ |
| 36 | |
| 37 | |
| 38 | int sch_queue_connectcxx . . $ sch_queue_connect(697248ac26eea891).(SEAP_desc_tcxx . . $ SEAP_desc_t# *desc) |
| 39 | { |
| 40 | sch_queuedata_tcxx . . $ sch_queuedata_t# *data = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(sch_queuedata_tcxx . . $ sch_queuedata_t#)); |
| 41 | |
| 42 | data->from_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_queue. = oscap_queue_newcxx . . $ oscap_queue_new(bdf6ccca4559a142).(); |
| 43 | data->from_probe_cntcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_cnt. = 0; |
| 44 | pthread_cond_initcxx . . $ pthread_cond_init(fc876bc1ec1249fc).(&data->from_probe_condcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_cond., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 45 | pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa).(&data->from_probe_mutexcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_mutex., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 46 | |
| 47 | data->to_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_queue. = oscap_queue_newcxx . . $ oscap_queue_new(bdf6ccca4559a142).(); |
| 48 | data->to_probe_cntcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_cnt. = 0; |
| 49 | pthread_cond_initcxx . . $ pthread_cond_init(fc876bc1ec1249fc).(&data->to_probe_condcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_cond., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 50 | pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa).(&data->to_probe_mutexcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_mutex., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 51 | |
| 52 | data->parent_thread_idcxx . . $ $anonymous_type_e828ea20cd12bff8_0#parent_thread_id. = pthread_selfcxx . . $ pthread_self(f708dce9a8856c70).(); |
| 53 | |
| 54 | struct probe_common_main_argumentcxx . . $ probe_common_main_argument# *arg = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct probe_common_main_argumentcxx . . $ probe_common_main_argument#)); |
| 55 | arg->subtypecxx . . $ probe_common_main_argument#subtype. = desc->subtypecxx . . $ $anonymous_type_5b6d52305350878e_0#subtype.; |
| 56 | arg->queuedatacxx . . $ probe_common_main_argument#queuedata. = data; |
| 57 | desc->argcxx . . $ $anonymous_type_5b6d52305350878e_0#arg. = arg; |
| 58 | |
| 59 | pthread_attr_tcxx . . $ pthread_attr_t# attr; |
| 60 | pthread_attr_initcxx . . $ pthread_attr_init(26f1688c57ac69c9).(&attr); |
| 61 | pthread_attr_setdetachstatecxx . . $ pthread_attr_setdetachstate(1c205214b8a99ab8).(&attr, PTHREAD_CREATE_JOINABLEcxx . . $ `<external>/14712363683955484316/pthread.h:40:9`!); |
| 62 | if (pthread_createcxx . . $ pthread_create(2141a84bcac899e5).(&data->probe_thread_idcxx . . $ $anonymous_type_e828ea20cd12bff8_0#probe_thread_id., &attr, &probe_common_maincxx . . $ probe_common_main(9f162e79bfc6c74)., arg)) { |
| 63 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Cannot create probe thread"); |
| 64 | return -1; |
| 65 | } |
| 66 | pthread_attr_destroycxx . . $ pthread_attr_destroy(26f1688c57ac69c9).(&attr); |
| 67 | |
| 68 | desc->scheme_datacxx . . $ $anonymous_type_5b6d52305350878e_0#scheme_data. = (void *) data; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | SEXP_tcxx . . $ SEXP_t# *sch_queue_recvsexpcxx . . $ sch_queue_recvsexp(5337bf09bc59ad21).(SEAP_desc_tcxx . . $ SEAP_desc_t# *desc) |
| 73 | { |
| 74 | sch_queuedata_tcxx . . $ sch_queuedata_t# *data = (sch_queuedata_tcxx . . $ sch_queuedata_t# *)desc->scheme_datacxx . . $ $anonymous_type_5b6d52305350878e_0#scheme_data.; |
| 75 | struct oscap_queuecxx . . $ oscap_queue# *queue; |
| 76 | pthread_mutex_tcxx . . $ pthread_mutex_t# *mutex; |
| 77 | pthread_cond_tcxx . . $ pthread_cond_t# *cond; |
| 78 | int *cnt; |
| 79 | if (pthread_equalcxx . . $ pthread_equal(8bdd4f646c1f3ab7).(pthread_selfcxx . . $ pthread_self(f708dce9a8856c70).(), data->parent_thread_idcxx . . $ $anonymous_type_e828ea20cd12bff8_0#parent_thread_id.)) { |
| 80 | queue = data->from_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_queue.; |
| 81 | mutex = &data->from_probe_mutexcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_mutex.; |
| 82 | cond = &data->from_probe_condcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_cond.; |
| 83 | cnt = &data->from_probe_cntcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_cnt.; |
| 84 | } else { |
| 85 | queue = data->to_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_queue.; |
| 86 | mutex = &data->to_probe_mutexcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_mutex.; |
| 87 | cond = &data->to_probe_condcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_cond.; |
| 88 | cnt = &data->to_probe_cntcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_cnt.; |
| 89 | } |
| 90 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(mutex); |
| 91 | while (*cnt == 0) { |
| 92 | pthread_cond_waitcxx . . $ pthread_cond_wait(6145be15a5d9db5d).(cond, mutex); |
| 93 | } |
| 94 | SEXP_tcxx . . $ SEXP_t# *sexp = oscap_queue_removecxx . . $ oscap_queue_remove(1607303aa7bc3f96).(queue); |
| 95 | (*cnt)--; |
| 96 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(mutex); |
| 97 | return sexp; |
| 98 | } |
| 99 | |
| 100 | ssize_tcxx . . $ ssize_t# sch_queue_sendsexpcxx . . $ sch_queue_sendsexp(bc098aea6e2d56cd).(SEAP_desc_tcxx . . $ SEAP_desc_t# *desc, SEXP_tcxx . . $ SEXP_t# *sexp, uint32_tcxx . . $ uint32_t# flags) |
| 101 | { |
| 102 | sch_queuedata_tcxx . . $ sch_queuedata_t# *data = (sch_queuedata_tcxx . . $ sch_queuedata_t# *) desc->scheme_datacxx . . $ $anonymous_type_5b6d52305350878e_0#scheme_data.; |
| 103 | struct oscap_queuecxx . . $ oscap_queue# *queue; |
| 104 | pthread_mutex_tcxx . . $ pthread_mutex_t# *mutex; |
| 105 | pthread_cond_tcxx . . $ pthread_cond_t# *cond; |
| 106 | int *cnt; |
| 107 | if (pthread_equalcxx . . $ pthread_equal(8bdd4f646c1f3ab7).(pthread_selfcxx . . $ pthread_self(f708dce9a8856c70).(), data->parent_thread_idcxx . . $ $anonymous_type_e828ea20cd12bff8_0#parent_thread_id.)) { |
| 108 | queue = data->to_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_queue.; |
| 109 | mutex = &data->to_probe_mutexcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_mutex.; |
| 110 | cond = &data->to_probe_condcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_cond.; |
| 111 | cnt = &data->to_probe_cntcxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_cnt.; |
| 112 | } else { |
| 113 | queue = data->from_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_queue.; |
| 114 | mutex = &data->from_probe_mutexcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_mutex.; |
| 115 | cond = &data->from_probe_condcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_cond.; |
| 116 | cnt = &data->from_probe_cntcxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_cnt.; |
| 117 | } |
| 118 | /* We want to send a SEXP, but the receiver expects a list of SEXPs. */ |
| 119 | SEXP_tcxx . . $ SEXP_t# *sexp_list = SEXP_list_newcxx . . $ SEXP_list_new(902e4f76566c8810).(sexp, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 120 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(mutex); |
| 121 | oscap_queue_addcxx . . $ oscap_queue_add(71ccb11e7c91f23b).(queue, (void *) sexp_list); |
| 122 | (*cnt)++; |
| 123 | pthread_cond_broadcastcxx . . $ pthread_cond_broadcast(98095c34a2b0149d).(cond); |
| 124 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(mutex); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | int sch_queue_closecxx . . $ sch_queue_close(912e80c1e1b86eec).(SEAP_desc_tcxx . . $ SEAP_desc_t# *desc, uint32_tcxx . . $ uint32_t# flags) |
| 129 | { |
| 130 | int ret = 0; |
| 131 | sch_queuedata_tcxx . . $ sch_queuedata_t# *data = (sch_queuedata_tcxx . . $ sch_queuedata_t# *) desc->scheme_datacxx . . $ $anonymous_type_5b6d52305350878e_0#scheme_data.; |
| 132 | if (pthread_cancelcxx . . $ pthread_cancel(15f694ef3c96d230).(data->probe_thread_idcxx . . $ $anonymous_type_e828ea20cd12bff8_0#probe_thread_id.) != 0) { |
| 133 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Could not cancel %s_probe main thread.", oval_subtype_get_text(desc->subtype)); |
| 134 | ret = -1; |
| 135 | goto cleanup; |
| 136 | } |
| 137 | void *status; |
| 138 | const char *subtype_str = oval_subtype_get_textcxx . . $ oval_subtype_get_text(ee6b3dcae047e21f).(desc->subtypecxx . . $ $anonymous_type_5b6d52305350878e_0#subtype.); |
| 139 | ret = pthread_joincxx . . $ pthread_join(269902cf949f12c5).(data->probe_thread_idcxx . . $ $anonymous_type_e828ea20cd12bff8_0#probe_thread_id., &status); |
| 140 | if (ret != 0) { |
| 141 | dEcxx . . $ `src/common/debug_priv.h:63:9`!("Return code of %s_probe main thread is %d.", subtype_str, ret); |
| 142 | } |
| 143 | cleanup: |
| 144 | oscap_queue_freecxx . . $ oscap_queue_free(879664d74130d69b).(data->to_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#to_probe_queue., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 145 | oscap_queue_freecxx . . $ oscap_queue_free(879664d74130d69b).(data->from_probe_queuecxx . . $ $anonymous_type_e828ea20cd12bff8_0#from_probe_queue., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 146 | freecxx . . $ free(5d22bdacc48458e8).(data); |
| 147 | freecxx . . $ free(5d22bdacc48458e8).(desc->argcxx . . $ $anonymous_type_5b6d52305350878e_0#arg.); |
| 148 | return ret; |
| 149 | } |