From 1c855ea16a28f0bfec04dd9b6f6cfc415d7008dd Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 3 Jan 2022 22:23:29 -0600 Subject: [PATCH] Progress: Continue working on the controller program's control functionality. The f_socket_listen() seems to need its own process or thread. Give it one. Make this one as isolated as possible so that it can be forcible exited. (Because listen() doesn't respect signal handlers.) --- level_3/controller/c/common/private-cache.c | 4 +- level_3/controller/c/common/private-cache.h | 4 +- level_3/controller/c/common/private-control.c | 17 ++ level_3/controller/c/common/private-control.h | 69 +++++ level_3/controller/c/common/private-entry.c | 12 +- level_3/controller/c/common/private-entry.h | 12 +- level_3/controller/c/common/private-lock.c | 2 +- level_3/controller/c/common/private-lock.h | 2 +- level_3/controller/c/common/private-process.c | 12 +- level_3/controller/c/common/private-process.h | 12 +- level_3/controller/c/common/private-rule.c | 24 +- level_3/controller/c/common/private-rule.h | 26 +- level_3/controller/c/common/private-setting.c | 2 +- level_3/controller/c/common/private-setting.h | 2 +- level_3/controller/c/common/private-task.c | 12 +- level_3/controller/c/common/private-task.h | 12 +- level_3/controller/c/common/private-thread.c | 2 +- level_3/controller/c/common/private-thread.h | 3 + level_3/controller/c/private-common.h | 1 + level_3/controller/c/private-control.c | 91 ++++++ level_3/controller/c/private-control.h | 61 ++++ level_3/controller/c/private-controller.c | 278 +++++++++--------- level_3/controller/c/private-controller.h | 20 +- level_3/controller/c/private-controller_print.c | 5 +- level_3/controller/c/private-controller_print.h | 16 +- level_3/controller/c/private-entry.c | 358 ++++++++++++------------ level_3/controller/c/private-entry.h | 6 +- level_3/controller/c/private-rule.c | 266 +++++++++--------- level_3/controller/c/private-rule.h | 12 +- level_3/controller/c/private-rule_print.c | 4 +- level_3/controller/c/private-rule_print.h | 12 +- level_3/controller/c/private-thread.c | 36 +-- level_3/controller/c/private-thread.h | 12 +- level_3/controller/c/private-thread_control.c | 43 ++- level_3/controller/c/private-thread_control.h | 19 +- level_3/controller/c/private-thread_entry.c | 12 +- level_3/controller/c/private-thread_entry.h | 4 +- level_3/controller/c/private-thread_process.c | 9 +- level_3/controller/c/private-thread_process.h | 6 +- level_3/controller/c/private-thread_rule.c | 4 +- level_3/controller/c/private-thread_rule.h | 2 +- level_3/controller/c/private-thread_signal.c | 14 +- level_3/controller/c/private-thread_signal.h | 14 +- level_3/controller/data/build/settings | 2 +- 44 files changed, 936 insertions(+), 600 deletions(-) create mode 100644 level_3/controller/c/common/private-control.c create mode 100644 level_3/controller/c/common/private-control.h diff --git a/level_3/controller/c/common/private-cache.c b/level_3/controller/c/common/private-cache.c index f3e90f3..883f43b 100644 --- a/level_3/controller/c/common/private-cache.c +++ b/level_3/controller/c/common/private-cache.c @@ -6,7 +6,7 @@ extern "C" { #endif #ifndef _di_controller_cache_action_delete_simple_ - void controller_cache_action_delete_simple(controller_cache_action_t *cache) { + void controller_cache_action_delete_simple(controller_cache_action_t * const cache) { f_string_dynamic_resize(0, &cache->name_action); f_string_dynamic_resize(0, &cache->name_file); @@ -16,7 +16,7 @@ extern "C" { #endif // _di_controller_cache_action_delete_simple_ #ifndef _di_controller_cache_delete_simple_ - void controller_cache_delete_simple(controller_cache_t *cache) { + void controller_cache_delete_simple(controller_cache_t * const cache) { macro_f_array_lengths_t_delete_simple(cache->ats) macro_f_array_lengths_t_delete_simple(cache->stack) diff --git a/level_3/controller/c/common/private-cache.h b/level_3/controller/c/common/private-cache.h index c637f92..caf86a5 100644 --- a/level_3/controller/c/common/private-cache.h +++ b/level_3/controller/c/common/private-cache.h @@ -124,7 +124,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_controller_cache_action_delete_simple_ - extern void controller_cache_action_delete_simple(controller_cache_action_t *cache) F_attribute_visibility_internal_d; + extern void controller_cache_action_delete_simple(controller_cache_action_t * const cache) F_attribute_visibility_internal_d; #endif // _di_controller_cache_action_delete_simple_ /** @@ -142,7 +142,7 @@ extern "C" { * @see f_string_rangess_resize() */ #ifndef _di_controller_cache_delete_simple_ - extern void controller_cache_delete_simple(controller_cache_t *cache) F_attribute_visibility_internal_d; + extern void controller_cache_delete_simple(controller_cache_t * const cache) F_attribute_visibility_internal_d; #endif // _di_controller_cache_delete_simple_ #ifdef __cplusplus diff --git a/level_3/controller/c/common/private-control.c b/level_3/controller/c/common/private-control.c new file mode 100644 index 0000000..5c6f562 --- /dev/null +++ b/level_3/controller/c/common/private-control.c @@ -0,0 +1,17 @@ +#include "../controller.h" +#include "../private-common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_packet_delete_simple_ + void controller_packet_delete_simple(controller_packet_t * const packet) { + + f_string_dynamic_resize(0, &packet->payload); + } +#endif // _di_controller_packet_delete_simple_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/controller/c/common/private-control.h b/level_3/controller/c/common/private-control.h new file mode 100644 index 0000000..3f5da51 --- /dev/null +++ b/level_3/controller/c/common/private-control.h @@ -0,0 +1,69 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + */ +#ifndef _PRIVATE_common_control_h +#define _PRIVATE_common_control_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Provide default control settings. + * + * controller_control_default: + * - socket_backlog: The amount of waiting client connections to support while handling a socket connection. + * - socket_buffer: The size of the buffer in bytes when processing packets (must not be set smaller the packet headers). + * - socket_header: The minimum size of the packet header to read to be able to process the size information. + * - socket_linger: The number of seconds to linger the connection before closing. + * - socket_timeout: The number of microseconds to wait. + */ +#ifndef _di_controller_control_defaults_ + #define controller_control_default_socket_backlog_d 64 + #define controller_control_default_socket_buffer_d 16384 + #define controller_control_default_socket_header_d 33 + #define controller_control_default_socket_linger_d 1 + #define controller_control_default_socket_timeout_d 10000 // 0.01 seconds. +#endif // _di_controller_defaults_ + +/** + * A structure representing the packet payload. + * + * Payload structure: [uint32_t][char X]. + * + * bytes: The header repesenting the number of bytes in the character payload. + * payload: The character payload whose size is represented by the header bytes. + */ +#ifndef _di_controller_packet_t_ + typedef struct { + uint32_t bytes; + f_string_dynamic_t payload; + } controller_packet_t; + + #define controller_packet_t_initialize { 0, f_string_dynamic_t_initialize } + + #define macro_controller_packet_t_initialize(bytes, payload) { \ + bytes, \ + payload, \ + } +#endif // _di_controller_main_t_ + +/** + * Fully deallocate all memory for the given packet without caring about return status. + * + * @param packet + * The packet to deallocate. + */ +#ifndef _di_controller_packet_delete_simple_ + extern void controller_packet_delete_simple(controller_packet_t * const packet) F_attribute_visibility_internal_d; +#endif // _di_controller_packet_delete_simple_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_common_control_h diff --git a/level_3/controller/c/common/private-entry.c b/level_3/controller/c/common/private-entry.c index 424c297..9d79605 100644 --- a/level_3/controller/c/common/private-entry.c +++ b/level_3/controller/c/common/private-entry.c @@ -6,14 +6,14 @@ extern "C" { #endif #ifndef _di_controller_entry_action_delete_simple_ - void controller_entry_action_delete_simple(controller_entry_action_t *action) { + void controller_entry_action_delete_simple(controller_entry_action_t * const action) { f_string_dynamics_resize(0, &action->parameters); } #endif // _di_controller_entry_action_delete_simple_ #ifndef _di_controller_entry_actions_delete_simple_ - void controller_entry_actions_delete_simple(controller_entry_actions_t *actions) { + void controller_entry_actions_delete_simple(controller_entry_actions_t * const actions) { actions->used = actions->size; @@ -27,7 +27,7 @@ extern "C" { #endif // _di_controller_entry_actions_delete_simple_ #ifndef _di_controller_entry_actions_increase_by_ - f_status_t controller_entry_actions_increase_by(const f_array_length_t amount, controller_entry_actions_t *actions) { + f_status_t controller_entry_actions_increase_by(const f_array_length_t amount, controller_entry_actions_t * const actions) { if (actions->used + amount > actions->size) { if (actions->used + amount > F_array_length_t_size_d) { @@ -48,7 +48,7 @@ extern "C" { #endif // _di_controller_entry_actions_increase_by_ #ifndef _di_controller_entry_item_delete_simple_ - void controller_entry_item_delete_simple(controller_entry_item_t *item) { + void controller_entry_item_delete_simple(controller_entry_item_t * const item) { f_string_dynamic_resize(0, &item->name); @@ -57,7 +57,7 @@ extern "C" { #endif // _di_controller_entry_item_delete_simple_ #ifndef _di_controller_entry_items_delete_simple_ - void controller_entry_items_delete_simple(controller_entry_items_t *items) { + void controller_entry_items_delete_simple(controller_entry_items_t * const items) { items->used = items->size; @@ -71,7 +71,7 @@ extern "C" { #endif // _di_controller_entry_items_delete_simple_ #ifndef _di_controller_entry_items_increase_by_ - f_status_t controller_entry_items_increase_by(const f_array_length_t amount, controller_entry_items_t *items) { + f_status_t controller_entry_items_increase_by(const f_array_length_t amount, controller_entry_items_t * const items) { if (items->used + amount > items->size) { if (items->used + amount > F_array_length_t_size_d) { diff --git a/level_3/controller/c/common/private-entry.h b/level_3/controller/c/common/private-entry.h index be9ac69..3061213 100644 --- a/level_3/controller/c/common/private-entry.h +++ b/level_3/controller/c/common/private-entry.h @@ -247,7 +247,7 @@ extern "C" { * @see f_string_dynamics_resize() */ #ifndef _di_controller_entry_action_delete_simple_ - extern void controller_entry_action_delete_simple(controller_entry_action_t *action) F_attribute_visibility_internal_d; + extern void controller_entry_action_delete_simple(controller_entry_action_t * const action) F_attribute_visibility_internal_d; #endif // _di_controller_entry_action_delete_simple_ /** @@ -260,7 +260,7 @@ extern "C" { * @see f_memory_delete() */ #ifndef _di_controller_entry_actions_delete_simple_ - extern void controller_entry_actions_delete_simple(controller_entry_actions_t *actions) F_attribute_visibility_internal_d; + extern void controller_entry_actions_delete_simple(controller_entry_actions_t * const actions) F_attribute_visibility_internal_d; #endif // _di_controller_entry_actions_delete_simple_ /** @@ -282,7 +282,7 @@ extern "C" { * @see f_memory_resize() */ #ifndef _di_controller_entry_actions_increase_by_ - extern f_status_t controller_entry_actions_increase_by(const f_array_length_t amount, controller_entry_actions_t *actions) F_attribute_visibility_internal_d; + extern f_status_t controller_entry_actions_increase_by(const f_array_length_t amount, controller_entry_actions_t * const actions) F_attribute_visibility_internal_d; #endif // _di_controller_entry_actions_increase_by_ /** @@ -294,7 +294,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_controller_entry_item_delete_simple_ - extern void controller_entry_item_delete_simple(controller_entry_item_t *item) F_attribute_visibility_internal_d; + extern void controller_entry_item_delete_simple(controller_entry_item_t * const item) F_attribute_visibility_internal_d; #endif // _di_controller_entry_item_delete_simple_ /** @@ -307,7 +307,7 @@ extern "C" { * @see f_memory_delete() */ #ifndef _di_controller_entry_items_delete_simple_ - extern void controller_entry_items_delete_simple(controller_entry_items_t *items) F_attribute_visibility_internal_d; + extern void controller_entry_items_delete_simple(controller_entry_items_t * const items) F_attribute_visibility_internal_d; #endif // _di_controller_entry_items_delete_simple_ /** @@ -329,7 +329,7 @@ extern "C" { * @see f_memory_resize() */ #ifndef _di_controller_entry_items_increase_by_ - extern f_status_t controller_entry_items_increase_by(const f_array_length_t amount, controller_entry_items_t *items) F_attribute_visibility_internal_d; + extern f_status_t controller_entry_items_increase_by(const f_array_length_t amount, controller_entry_items_t * const items) F_attribute_visibility_internal_d; #endif // _di_controller_entry_items_increase_by_ #ifdef __cplusplus diff --git a/level_3/controller/c/common/private-lock.c b/level_3/controller/c/common/private-lock.c index 185379d..9917891 100644 --- a/level_3/controller/c/common/private-lock.c +++ b/level_3/controller/c/common/private-lock.c @@ -42,7 +42,7 @@ extern "C" { #endif // _di_controller_lock_delete_rw_ #ifndef _di_controller_lock_delete_simple_ - void controller_lock_delete_simple(controller_lock_t *lock) { + void controller_lock_delete_simple(controller_lock_t * const lock) { controller_lock_delete_mutex(&lock->print); controller_lock_delete_mutex(&lock->alert); diff --git a/level_3/controller/c/common/private-lock.h b/level_3/controller/c/common/private-lock.h index 260bc58..d5b9dbb 100644 --- a/level_3/controller/c/common/private-lock.h +++ b/level_3/controller/c/common/private-lock.h @@ -78,7 +78,7 @@ extern "C" { * @see f_thread_mutex_delete() */ #ifndef _di_controller_lock_delete_simple_ - extern void controller_lock_delete_simple(controller_lock_t *lock) F_attribute_visibility_internal_d; + extern void controller_lock_delete_simple(controller_lock_t * const lock) F_attribute_visibility_internal_d; #endif // _di_controller_lock_delete_simple_ #ifdef __cplusplus diff --git a/level_3/controller/c/common/private-process.c b/level_3/controller/c/common/private-process.c index 26de3f5..d01207f 100644 --- a/level_3/controller/c/common/private-process.c +++ b/level_3/controller/c/common/private-process.c @@ -6,7 +6,7 @@ extern "C" { #endif #ifndef _di_controller_pids_increase_ - f_status_t controller_pids_increase(controller_pids_t *pids) { + f_status_t controller_pids_increase(controller_pids_t * const pids) { if (pids->used + 1 > pids->size) { f_array_length_t size = pids->used + controller_common_allocation_small_d; @@ -27,7 +27,7 @@ extern "C" { #endif // _di_controller_pids_increase_ #ifndef _di_controller_pids_resize_ - f_status_t controller_pids_resize(const f_array_length_t length, controller_pids_t *pids) { + f_status_t controller_pids_resize(const f_array_length_t length, controller_pids_t * const pids) { f_status_t status = F_none; @@ -46,7 +46,7 @@ extern "C" { #endif // _di_controller_pids_resize_ #ifndef _di_controller_process_delete_simple_ - void controller_process_delete_simple(controller_process_t *process) { + void controller_process_delete_simple(controller_process_t * const process) { if (process->id_thread) { f_thread_signal(process->id_thread, F_signal_kill); @@ -72,14 +72,14 @@ extern "C" { #endif // _di_controller_process_delete_simple_ #ifndef _di_controller_processs_delete_simple_ - void controller_processs_delete_simple(controller_processs_t *processs) { + void controller_processs_delete_simple(controller_processs_t * const processs) { controller_processs_resize(0, processs); } #endif // _di_controller_processs_delete_simple_ #ifndef _di_controller_processs_increase_ - f_status_t controller_processs_increase(controller_processs_t *processs) { + f_status_t controller_processs_increase(controller_processs_t * const processs) { if (processs->used + 1 > processs->size) { f_array_length_t size = processs->used + controller_common_allocation_small_d; @@ -100,7 +100,7 @@ extern "C" { #endif // _di_controller_processs_increase_ #ifndef _di_controller_processs_resize_ - f_status_t controller_processs_resize(const f_array_length_t length, controller_processs_t *processs) { + f_status_t controller_processs_resize(const f_array_length_t length, controller_processs_t * const processs) { f_status_t status = F_none; diff --git a/level_3/controller/c/common/private-process.h b/level_3/controller/c/common/private-process.h index 191e62d..92dca1f 100644 --- a/level_3/controller/c/common/private-process.h +++ b/level_3/controller/c/common/private-process.h @@ -187,7 +187,7 @@ extern "C" { * @see controller_pids_resize() */ #ifndef _di_controller_pids_increase_ - extern f_status_t controller_pids_increase(controller_pids_t *pids) F_attribute_visibility_internal_d; + extern f_status_t controller_pids_increase(controller_pids_t * const pids) F_attribute_visibility_internal_d; #endif // _di_controller_rule_increase_ /** @@ -207,7 +207,7 @@ extern "C" { * @see f_memory_resize() */ #ifndef _di_controller_pids_resize_ - extern f_status_t controller_pids_resize(const f_array_length_t length, controller_pids_t *pids) F_attribute_visibility_internal_d; + extern f_status_t controller_pids_resize(const f_array_length_t length, controller_pids_t * const pids) F_attribute_visibility_internal_d; #endif // _di_controller_pids_resize_ /** @@ -221,7 +221,7 @@ extern "C" { * @see f_thread_mutex_delete() */ #ifndef _di_controller_process_delete_simple_ - extern void controller_process_delete_simple(controller_process_t *process) F_attribute_visibility_internal_d; + extern void controller_process_delete_simple(controller_process_t * const process) F_attribute_visibility_internal_d; #endif // _di_controller_process_delete_simple_ /** @@ -233,7 +233,7 @@ extern "C" { * @see controller_processs_resize() */ #ifndef _di_controller_processs_delete_simple_ - extern void controller_processs_delete_simple(controller_processs_t *processs) F_attribute_visibility_internal_d; + extern void controller_processs_delete_simple(controller_processs_t * const processs) F_attribute_visibility_internal_d; #endif // _di_controller_processs_delete_simple_ /** @@ -256,7 +256,7 @@ extern "C" { * @see controller_processs_resize() */ #ifndef _di_controller_processs_increase_ - extern f_status_t controller_processs_increase(controller_processs_t *processs) F_attribute_visibility_internal_d; + extern f_status_t controller_processs_increase(controller_processs_t * const processs) F_attribute_visibility_internal_d; #endif // _di_controller_rule_increase_ /** @@ -281,7 +281,7 @@ extern "C" { * @see f_thread_lock_create() */ #ifndef _di_controller_processs_resize_ - extern f_status_t controller_processs_resize(const f_array_length_t length, controller_processs_t *processs) F_attribute_visibility_internal_d; + extern f_status_t controller_processs_resize(const f_array_length_t length, controller_processs_t * const processs) F_attribute_visibility_internal_d; #endif // _di_controller_processs_resize_ #ifdef __cplusplus diff --git a/level_3/controller/c/common/private-rule.c b/level_3/controller/c/common/private-rule.c index 3193855..6199fb5 100644 --- a/level_3/controller/c/common/private-rule.c +++ b/level_3/controller/c/common/private-rule.c @@ -6,14 +6,14 @@ extern "C" { #endif #ifndef _di_controller_rule_action_delete_simple_ - void controller_rule_action_delete_simple(controller_rule_action_t *action) { + void controller_rule_action_delete_simple(controller_rule_action_t * const action) { f_string_dynamics_resize(0, &action->parameters); } #endif // _di_controller_rule_action_delete_simple_ #ifndef _di_controller_rule_actions_delete_simple_ - void controller_rule_actions_delete_simple(controller_rule_actions_t *actions) { + void controller_rule_actions_delete_simple(controller_rule_actions_t * const actions) { actions->used = actions->size; @@ -27,7 +27,7 @@ extern "C" { #endif // _di_controller_rule_actions_delete_simple_ #ifndef _di_controller_rule_actions_increase_by_ - f_status_t controller_rule_actions_increase_by(const f_array_length_t amount, controller_rule_actions_t *actions) { + f_status_t controller_rule_actions_increase_by(const f_array_length_t amount, controller_rule_actions_t * const actions) { if (actions->used + amount > actions->size) { if (actions->used + amount > F_array_length_t_size_d) { @@ -75,7 +75,7 @@ extern "C" { #endif // _di_controller_rule_delete_simple_ #ifndef _di_controller_rule_item_delete_simple_ - void controller_rule_item_delete_simple(controller_rule_item_t *item) { + void controller_rule_item_delete_simple(controller_rule_item_t * const item) { f_string_dynamic_resize(0, &item->pid_file); @@ -84,7 +84,7 @@ extern "C" { #endif // _di_controller_rule_item_delete_simple_ #ifndef _di_controller_rule_items_delete_simple_ - void controller_rule_items_delete_simple(controller_rule_items_t *items) { + void controller_rule_items_delete_simple(controller_rule_items_t * const items) { items->used = items->size; @@ -98,7 +98,7 @@ extern "C" { #endif // _di_controller_rule_items_delete_simple_ #ifndef _di_controller_rule_on_delete_simple_ - void controller_rule_on_delete_simple(controller_rule_on_t *on) { + void controller_rule_on_delete_simple(controller_rule_on_t * const on) { f_string_dynamics_resize(0, &on->need); f_string_dynamics_resize(0, &on->want); @@ -107,7 +107,7 @@ extern "C" { #endif // _di_controller_rule_on_delete_simple_ #ifndef _di_controller_rule_ons_delete_simple_ - void controller_rule_ons_delete_simple(controller_rule_ons_t *ons) { + void controller_rule_ons_delete_simple(controller_rule_ons_t * const ons) { ons->used = ons->size; @@ -121,7 +121,7 @@ extern "C" { #endif // _di_controller_rule_ons_delete_simple_ #ifndef _di_controller_rule_ons_increase_ - f_status_t controller_rule_ons_increase(controller_rule_ons_t *ons) { + f_status_t controller_rule_ons_increase(controller_rule_ons_t * const ons) { if (ons->used + 1 > ons->size) { f_array_length_t size = ons->used + controller_common_allocation_small_d; @@ -142,7 +142,7 @@ extern "C" { #endif // _di_controller_rule_ons_increase_ #ifndef _di_controller_rule_ons_resize_ - f_status_t controller_rule_ons_resize(const f_array_length_t length, controller_rule_ons_t *ons) { + f_status_t controller_rule_ons_resize(const f_array_length_t length, controller_rule_ons_t * const ons) { for (f_array_length_t i = length; i < ons->size; ++i) { controller_rule_on_delete_simple(&ons->array[i]); @@ -163,14 +163,14 @@ extern "C" { #endif // _di_controller_rule_ons_resize_ #ifndef _di_controller_rules_delete_simple_ - void controller_rules_delete_simple(controller_rules_t *rules) { + void controller_rules_delete_simple(controller_rules_t * const rules) { controller_rules_resize(0, rules); } #endif // _di_controller_rules_delete_simple_ #ifndef _di_controller_rules_increase_ - f_status_t controller_rules_increase(controller_rules_t *rules) { + f_status_t controller_rules_increase(controller_rules_t * const rules) { if (rules->used + 1 > rules->size) { f_array_length_t size = rules->used + controller_common_allocation_small_d; @@ -191,7 +191,7 @@ extern "C" { #endif // _di_controller_rules_increase_ #ifndef _di_controller_rules_resize_ - f_status_t controller_rules_resize(const f_array_length_t length, controller_rules_t *rules) { + f_status_t controller_rules_resize(const f_array_length_t length, controller_rules_t * const rules) { for (f_array_length_t i = length; i < rules->size; ++i) { controller_rule_delete_simple(&rules->array[i]); diff --git a/level_3/controller/c/common/private-rule.h b/level_3/controller/c/common/private-rule.h index eed2625..78d49aa 100644 --- a/level_3/controller/c/common/private-rule.h +++ b/level_3/controller/c/common/private-rule.h @@ -507,7 +507,7 @@ extern "C" { * @see f_string_dynamics_resize() */ #ifndef _di_controller_rule_action_delete_simple_ - extern void controller_rule_action_delete_simple(controller_rule_action_t *action) F_attribute_visibility_internal_d; + extern void controller_rule_action_delete_simple(controller_rule_action_t * const action) F_attribute_visibility_internal_d; #endif // _di_controller_rule_action_delete_simple_ /** @@ -520,7 +520,7 @@ extern "C" { * @see f_memory_delete() */ #ifndef _di_controller_rule_actions_delete_simple_ - extern void controller_rule_actions_delete_simple(controller_rule_actions_t *actions) F_attribute_visibility_internal_d; + extern void controller_rule_actions_delete_simple(controller_rule_actions_t * const actions) F_attribute_visibility_internal_d; #endif // _di_controller_rule_actions_delete_simple_ /** @@ -540,7 +540,7 @@ extern "C" { * Errors (with error bit) from: f_memory_resize(). */ #ifndef _di_controller_rule_actions_increase_by_ - extern f_status_t controller_rule_actions_increase_by(const f_array_length_t amount, controller_rule_actions_t *actions) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_actions_increase_by(const f_array_length_t amount, controller_rule_actions_t * const actions) F_attribute_visibility_internal_d; #endif // _di_controller_rule_actions_increase_by_ /** @@ -562,7 +562,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_controller_rule_delete_simple_ - extern void controller_rule_delete_simple(controller_rule_t *rule) F_attribute_visibility_internal_d; + extern void controller_rule_delete_simple(controller_rule_t * const rule) F_attribute_visibility_internal_d; #endif // _di_controller_rule_delete_simple_ /** @@ -574,7 +574,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_controller_rule_item_delete_simple_ - extern void controller_rule_item_delete_simple(controller_rule_item_t *item) F_attribute_visibility_internal_d; + extern void controller_rule_item_delete_simple(controller_rule_item_t * const item) F_attribute_visibility_internal_d; #endif // _di_controller_rule_item_delete_simple_ /** @@ -587,7 +587,7 @@ extern "C" { * @see f_memory_delete() */ #ifndef _di_controller_rule_items_delete_simple_ - extern void controller_rule_items_delete_simple(controller_rule_items_t *items) F_attribute_visibility_internal_d; + extern void controller_rule_items_delete_simple(controller_rule_items_t * const items) F_attribute_visibility_internal_d; #endif // _di_controller_rule_items_delete_simple_ /** @@ -599,7 +599,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_controller_rule_on_delete_simple_ - extern void controller_rule_on_delete_simple(controller_rule_on_t *on) F_attribute_visibility_internal_d; + extern void controller_rule_on_delete_simple(controller_rule_on_t * const on) F_attribute_visibility_internal_d; #endif // _di_controller_rule_on_delete_simple_ /** @@ -612,7 +612,7 @@ extern "C" { * @see f_memory_delete() */ #ifndef _di_controller_rule_ons_delete_simple_ - extern void controller_rule_ons_delete_simple(controller_rule_ons_t *ons) F_attribute_visibility_internal_d; + extern void controller_rule_ons_delete_simple(controller_rule_ons_t * const ons) F_attribute_visibility_internal_d; #endif // _di_controller_rule_ons_delete_simple_ /** @@ -635,7 +635,7 @@ extern "C" { * @see controller_rule_ons_resize() */ #ifndef _di_controller_rule_ons_increase_ - extern f_status_t controller_rule_ons_increase(controller_rule_ons_t *ons) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_ons_increase(controller_rule_ons_t * const ons) F_attribute_visibility_internal_d; #endif // _di_controller_rule_increase_ /** @@ -655,7 +655,7 @@ extern "C" { * @see f_memory_resize() */ #ifndef _di_controller_rule_ons_resize_ - extern f_status_t controller_rule_ons_resize(const f_array_length_t length, controller_rule_ons_t *ons) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_ons_resize(const f_array_length_t length, controller_rule_ons_t * const ons) F_attribute_visibility_internal_d; #endif // _di_controller_rule_ons_resize_ /** @@ -667,7 +667,7 @@ extern "C" { * @see controller_rules_resize() */ #ifndef _di_controller_rules_delete_simple_ - extern void controller_rules_delete_simple(controller_rules_t *rules) F_attribute_visibility_internal_d; + extern void controller_rules_delete_simple(controller_rules_t * const rules) F_attribute_visibility_internal_d; #endif // _di_controller_rules_delete_simple_ /** @@ -690,7 +690,7 @@ extern "C" { * @see controller_rules_resize() */ #ifndef _di_controller_rules_increase_ - extern f_status_t controller_rules_increase(controller_rules_t *rules) F_attribute_visibility_internal_d; + extern f_status_t controller_rules_increase(controller_rules_t * const rules) F_attribute_visibility_internal_d; #endif // _di_controller_rule_increase_ /** @@ -710,7 +710,7 @@ extern "C" { * @see f_memory_resize() */ #ifndef _di_controller_rules_resize_ - extern f_status_t controller_rules_resize(const f_array_length_t length, controller_rules_t *rules) F_attribute_visibility_internal_d; + extern f_status_t controller_rules_resize(const f_array_length_t length, controller_rules_t * const rules) F_attribute_visibility_internal_d; #endif // _di_controller_rules_resize_ #ifdef __cplusplus diff --git a/level_3/controller/c/common/private-setting.c b/level_3/controller/c/common/private-setting.c index 87bd64a..19f25e8 100644 --- a/level_3/controller/c/common/private-setting.c +++ b/level_3/controller/c/common/private-setting.c @@ -6,7 +6,7 @@ extern "C" { #endif #ifndef _di_controller_setting_delete_simple_ - void controller_setting_delete_simple(controller_setting_t *setting) { + void controller_setting_delete_simple(controller_setting_t * const setting) { f_string_dynamic_resize(0, &setting->path_control); f_string_dynamic_resize(0, &setting->path_cgroup); diff --git a/level_3/controller/c/common/private-setting.h b/level_3/controller/c/common/private-setting.h index ff1108e..527d3e3 100644 --- a/level_3/controller/c/common/private-setting.h +++ b/level_3/controller/c/common/private-setting.h @@ -121,7 +121,7 @@ extern "C" { * @see f_string_dynamic_resize() */ #ifndef _di_controller_setting_delete_simple_ - extern void controller_setting_delete_simple(controller_setting_t *setting) F_attribute_visibility_internal_d; + extern void controller_setting_delete_simple(controller_setting_t * const setting) F_attribute_visibility_internal_d; #endif // _di_controller_setting_delete_simple_ #ifdef __cplusplus diff --git a/level_3/controller/c/common/private-task.c b/level_3/controller/c/common/private-task.c index b4b1b7d..0c4aea2 100644 --- a/level_3/controller/c/common/private-task.c +++ b/level_3/controller/c/common/private-task.c @@ -6,7 +6,7 @@ extern "C" { #endif #ifndef _di_controller_task_action_delete_simple_ - void controller_task_action_delete_simple(controller_task_action_t *action) { + void controller_task_action_delete_simple(controller_task_action_t * const action) { f_string_dynamic_resize(0, &action->help); f_string_dynamics_resize(0, &action->parameters); @@ -14,7 +14,7 @@ extern "C" { #endif // _di_controller_task_action_delete_simple_ #ifndef _di_controller_task_actions_delete_simple_ - void controller_task_actions_delete_simple(controller_task_actions_t *actions) { + void controller_task_actions_delete_simple(controller_task_actions_t * const actions) { actions->used = actions->size; @@ -28,7 +28,7 @@ extern "C" { #endif // _di_controller_task_actions_delete_simple_ #ifndef _di_controller_task_actions_increase_by_ - f_status_t controller_task_actions_increase_by(const f_array_length_t amount, controller_task_actions_t *actions) { + f_status_t controller_task_actions_increase_by(const f_array_length_t amount, controller_task_actions_t * const actions) { if (actions->used + amount > actions->size) { if (actions->used + amount > F_array_length_t_size_d) { @@ -77,14 +77,14 @@ extern "C" { #endif // _di_controller_task_delete_simple_ #ifndef _di_controller_tasks_delete_simple_ - void controller_tasks_delete_simple(controller_tasks_t *tasks) { + void controller_tasks_delete_simple(controller_tasks_t * const tasks) { controller_tasks_resize(0, tasks); } #endif // _di_controller_tasks_delete_simple_ #ifndef _di_controller_tasks_increase_ - f_status_t controller_tasks_increase(controller_tasks_t *tasks) { + f_status_t controller_tasks_increase(controller_tasks_t * const tasks) { if (tasks->used + 1 > tasks->size) { f_array_length_t size = tasks->used + controller_common_allocation_small_d; @@ -105,7 +105,7 @@ extern "C" { #endif // _di_controller_tasks_increase_ #ifndef _di_controller_tasks_resize_ - f_status_t controller_tasks_resize(const f_array_length_t length, controller_tasks_t *tasks) { + f_status_t controller_tasks_resize(const f_array_length_t length, controller_tasks_t * const tasks) { for (f_array_length_t i = length; i < tasks->size; ++i) { controller_task_delete_simple(&tasks->array[i]); diff --git a/level_3/controller/c/common/private-task.h b/level_3/controller/c/common/private-task.h index 01e4666..4d16fef 100644 --- a/level_3/controller/c/common/private-task.h +++ b/level_3/controller/c/common/private-task.h @@ -242,7 +242,7 @@ extern "C" { * @see f_string_dynamics_resize() */ #ifndef _di_controller_task_action_delete_simple_ - extern void controller_task_action_delete_simple(controller_task_action_t *action) F_attribute_visibility_internal_d; + extern void controller_task_action_delete_simple(controller_task_action_t * const action) F_attribute_visibility_internal_d; #endif // _di_controller_task_action_delete_simple_ /** @@ -276,7 +276,7 @@ extern "C" { * Errors (with error bit) from: f_memory_resize(). */ #ifndef _di_controller_task_actions_increase_by_ - extern f_status_t controller_task_actions_increase_by(const f_array_length_t amount, controller_task_actions_t *actions) F_attribute_visibility_internal_d; + extern f_status_t controller_task_actions_increase_by(const f_array_length_t amount, controller_task_actions_t * const actions) F_attribute_visibility_internal_d; #endif // _di_controller_task_actions_increase_by_ /** @@ -299,7 +299,7 @@ extern "C" { * @see controller_task_items_delete_simple() */ #ifndef _di_controller_task_delete_simple_ - extern void controller_task_delete_simple(controller_task_t *task) F_attribute_visibility_internal_d; + extern void controller_task_delete_simple(controller_task_t * const task) F_attribute_visibility_internal_d; #endif // _di_controller_task_delete_simple_ /** @@ -311,7 +311,7 @@ extern "C" { * @see controller_tasks_resize() */ #ifndef _di_controller_tasks_delete_simple_ - extern void controller_tasks_delete_simple(controller_tasks_t *tasks) F_attribute_visibility_internal_d; + extern void controller_tasks_delete_simple(controller_tasks_t * const tasks) F_attribute_visibility_internal_d; #endif // _di_controller_tasks_delete_simple_ /** @@ -334,7 +334,7 @@ extern "C" { * @see controller_tasks_resize() */ #ifndef _di_controller_tasks_increase_ - extern f_status_t controller_tasks_increase(controller_tasks_t *tasks) F_attribute_visibility_internal_d; + extern f_status_t controller_tasks_increase(controller_tasks_t * const tasks) F_attribute_visibility_internal_d; #endif // _di_controller_task_increase_ /** @@ -354,7 +354,7 @@ extern "C" { * @see f_memory_resize() */ #ifndef _di_controller_tasks_resize_ - extern f_status_t controller_tasks_resize(const f_array_length_t length, controller_tasks_t *tasks) F_attribute_visibility_internal_d; + extern f_status_t controller_tasks_resize(const f_array_length_t length, controller_tasks_t * const tasks) F_attribute_visibility_internal_d; #endif // _di_controller_tasks_resize_ #ifdef __cplusplus diff --git a/level_3/controller/c/common/private-thread.c b/level_3/controller/c/common/private-thread.c index d77c8af..62613b1 100644 --- a/level_3/controller/c/common/private-thread.c +++ b/level_3/controller/c/common/private-thread.c @@ -6,7 +6,7 @@ extern "C" { #endif #ifndef _di_controller_thread_delete_simple_ - void controller_thread_delete_simple(controller_thread_t *thread) { + void controller_thread_delete_simple(controller_thread_t * const thread) { controller_lock_delete_simple(&thread->lock); controller_processs_resize(0, &thread->processs); diff --git a/level_3/controller/c/common/private-thread.h b/level_3/controller/c/common/private-thread.h index 01af260..68da869 100644 --- a/level_3/controller/c/common/private-thread.h +++ b/level_3/controller/c/common/private-thread.h @@ -25,6 +25,7 @@ extern "C" { * id_cleanup: The thread ID representing the Cleanup Process. * id_control: The thread ID representing the Control Process. * id_entry: The thread ID representing the Entry or Exit Process. + * id_listen: The thread ID representing the Control Process Listener. * id_rule: The thread ID representing the Rule Process. * id_signal: The thread ID representing the Signal Process. * lock: A r/w lock for operating on this structure. @@ -105,6 +106,7 @@ extern "C" { f_thread_id_t id_cleanup; f_thread_id_t id_control; f_thread_id_t id_entry; + f_thread_id_t id_listen; f_thread_id_t id_rule; f_thread_id_t id_signal; @@ -122,6 +124,7 @@ extern "C" { f_thread_id_t_initialize, \ f_thread_id_t_initialize, \ f_thread_id_t_initialize, \ + f_thread_id_t_initialize, \ controller_lock_t_initialize, \ controller_processs_t_initialize, \ controller_cache_t_initialize, \ diff --git a/level_3/controller/c/private-common.h b/level_3/controller/c/private-common.h index 64f96d0..586ffd0 100644 --- a/level_3/controller/c/private-common.h +++ b/level_3/controller/c/private-common.h @@ -23,6 +23,7 @@ extern "C" { #include "common/private-setting.h" #include "common/private-thread.h" #include "common/private-state.h" +#include "common/private-control.h" /** * All special strings used within this program. diff --git a/level_3/controller/c/private-control.c b/level_3/controller/c/private-control.c index 8008106..5749886 100644 --- a/level_3/controller/c/private-control.c +++ b/level_3/controller/c/private-control.c @@ -1,11 +1,102 @@ #include "controller.h" #include "private-common.h" #include "private-control.h" +#include "private-controller_print.h" #ifdef __cplusplus extern "C" { #endif +#ifndef _di_controller_control_configure_client_ + f_status_t controller_control_configure_client(const controller_global_t *global, f_socket_t * const client) { + + struct timeval time_out; + time_out.tv_sec = 0; + time_out.tv_usec = controller_control_default_socket_timeout_d; + + f_status_t status = f_socket_option_set(client, 1, f_socket_option_time_out_receive_d, (void *) &time_out, sizeof(struct timeval)); + + if (F_status_is_error_not(status)) { + status = f_socket_option_set(client, 1, f_socket_option_time_out_send_d, (void *) &time_out, sizeof(struct timeval)); + } + + if (F_status_is_error(status)) { + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_socket_option_set", F_true); + } + + return status; + } +#endif // _di_controller_control_configure_client_ + +#ifndef _di_controller_control_configure_server_ + f_status_t controller_control_configure_server(const controller_global_t *global, f_socket_t * const server) { + + struct linger value = { 1, 1 }; + + f_status_t status = f_socket_option_set(server, controller_control_default_socket_linger_d, f_socket_option_linger_d, (void *) &value, sizeof(struct linger)); + + if (F_status_is_error(status)) { + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_socket_option_set", F_true); + } + + return status; + } +#endif // _di_controller_control_configure_server_ + +#ifndef _di_controller_control_accept_ + f_status_t controller_control_accept(const controller_global_t *global, f_socket_t * const server, controller_packet_t * const packet) { + + f_socket_t client = f_socket_t_initialize; + + f_status_t status = f_socket_accept(&client, server->id); + + if (F_status_is_error(status)) { + f_socket_disconnect(&client, f_socket_close_read_write_e); + + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_socket_accept", F_true); + + return status; + } + + controller_control_configure_client(global, &client); + + char buffer[controller_control_default_socket_buffer_d + 1]; + size_t length = 0; + + memset(buffer, 0, controller_control_default_socket_buffer_d + 1); + packet->payload.used = 0; + + // Pre-process the packet header. + client.size_read = controller_control_default_socket_header_d; + status = f_socket_read(&client, f_socket_flag_peek_d, buffer, &length); + + if (F_status_is_error(status)) { + f_socket_disconnect(&client, f_socket_close_read_write_e); + + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_socket_read", F_true); + + return status; + } + + client.size_read = controller_control_default_socket_buffer_d; + + // Get all remaining data. + //while (???) { // until done, based on expected length that should be described in the packet header. + //message_length = recv(&client, buffer, input_size, receive_flags); + + //} // while + + // process the data. + + // send any responses. + // sent = send(&client, packet, output_size, send_flags); + + f_socket_disconnect(&client, f_socket_close_read_write_e); + + return F_none; + } +#endif // _di_controller_control_accept_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/controller/c/private-control.h b/level_3/controller/c/private-control.h index e8501e2..46987b6 100644 --- a/level_3/controller/c/private-control.h +++ b/level_3/controller/c/private-control.h @@ -12,6 +12,67 @@ extern "C" { #endif +/** + * Configure client socket settings. + * + * @param global + * The global data. + * @param client + * The client socket structure. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_socket_option_set(). + * + * @see f_socket_option_set() + */ +#ifndef _di_controller_control_configure_client_ + extern f_status_t controller_control_configure_client(const controller_global_t *global, f_socket_t * const client) F_attribute_visibility_internal_d; +#endif // _di_controller_control_configure_client_ + +/** + * Configure server socket settings. + * + * @param global + * The global data. + * @param server + * The server socket structure. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_socket_option_set(). + * + * @see f_socket_option_set() + */ +#ifndef _di_controller_control_configure_server_ + extern f_status_t controller_control_configure_server(const controller_global_t *global, f_socket_t * const server) F_attribute_visibility_internal_d; +#endif // _di_controller_control_configure_server_ + +/** + * Accept connections from a control socket server. + * + * Connectons are processed and actions are performed. + * + * @param global + * The global data. + * @param socket + * The socket structure. + * @param packet + * The control packet data structure. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_socket_accept(). + * + * @see f_socket_accept() + */ +#ifndef _di_controller_control_accept_ + extern f_status_t controller_control_accept(const controller_global_t *global, f_socket_t * const server, controller_packet_t * const packet) F_attribute_visibility_internal_d; +#endif // _di_controller_control_accept_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/controller/c/private-controller.c b/level_3/controller/c/private-controller.c index fcc3d42..34d8588 100644 --- a/level_3/controller/c/private-controller.c +++ b/level_3/controller/c/private-controller.c @@ -4,6 +4,7 @@ #include "private-controller_print.h" #include "private-entry_print.h" #include "private-lock_print.h" +#include "private-thread_control.h" #ifdef __cplusplus extern "C" { @@ -90,7 +91,7 @@ extern "C" { if (F_status_is_error(status)) { if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_append", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_append", F_true); } return status; @@ -100,7 +101,7 @@ extern "C" { if (F_status_is_error(status)) { if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); } return status; @@ -128,7 +129,7 @@ extern "C" { } if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error_file(global.main->error, F_status_set_fine(status), "f_file_stream_open", F_true, path, "open", fll_error_file_type_file_e, global.thread); + controller_print_error_file(global.thread, global.main->error, F_status_set_fine(status), "f_file_stream_open", F_true, path, "open", fll_error_file_type_file_e); } } else { @@ -136,7 +137,7 @@ extern "C" { if (F_status_is_error(status)) { if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error_file(global.main->error, F_status_set_fine(status), "f_file_stream_read", F_true, path, "read", fll_error_file_type_file_e, global.thread); + controller_print_error_file(global.thread, global.main->error, F_status_set_fine(status), "f_file_stream_read", F_true, path, "read", fll_error_file_type_file_e); } } } @@ -150,7 +151,7 @@ extern "C" { if (F_status_is_error(status)) { if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error_file(global.main->error, F_status_set_fine(status), "f_file_stat", F_true, path, "stat", fll_error_file_type_file_e, global.thread); + controller_print_error_file(global.thread, global.main->error, F_status_set_fine(status), "f_file_stat", F_true, path, "stat", fll_error_file_type_file_e); } } else { @@ -262,7 +263,7 @@ extern "C" { #endif // _di_controller_file_pid_delete_ #ifndef _di_controller_file_pid_read_ - f_status_t controller_file_pid_read(const f_string_static_t path, pid_t *pid) { + f_status_t controller_file_pid_read(const f_string_static_t path, pid_t * const pid) { *pid = 0; @@ -312,22 +313,17 @@ extern "C" { #endif // _di_controller_file_pid_read_ #ifndef _di_controller_get_id_user_ - f_status_t controller_get_id_user(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, uid_t *id) { + f_status_t controller_get_id_user(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, uid_t * const id) { f_number_unsigned_t number = 0; f_status_t status = fl_conversion_string_to_number_unsigned(buffer.string, range, &number); if (F_status_is_error(status)) { - status = F_status_set_fine(status); - - if (status == F_number) { + if (F_status_set_fine(status) == F_number) { cache->action.generic.used = 0; - status = f_string_dynamic_partial_append_nulless(buffer, range, &cache->action.generic); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_terminate(&cache->action.generic); + status = controller_dynamic_rip_nulless_terminated(buffer, range, &cache->action.generic); if (F_status_is_error(status)) return status; status = f_account_id_user_by_name(cache->action.generic.string, id); @@ -340,35 +336,28 @@ extern "C" { return F_none; } - return F_status_set_error(status); + return status; } else if (number > F_type_size_32_unsigned_d) { return F_status_set_error(F_number_too_large); } - *id = (uid_t) number; - return status; } #endif // _di_controller_get_id_user_ #ifndef _di_controller_get_id_group_ - f_status_t controller_get_id_group(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, gid_t *id) { + f_status_t controller_get_id_group(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, gid_t * const id) { f_number_unsigned_t number = 0; f_status_t status = fl_conversion_string_to_number_unsigned(buffer.string, range, &number); if (F_status_is_error(status)) { - status = F_status_set_fine(status); - - if (status == F_number) { + if (F_status_set_fine(status) == F_number) { cache->action.generic.used = 0; - status = f_string_dynamic_partial_append_nulless(buffer, range, &cache->action.generic); - if (F_status_is_error(status)) return status; - - status = f_string_dynamic_terminate(&cache->action.generic); + status = controller_dynamic_rip_nulless_terminated(buffer, range, &cache->action.generic); if (F_status_is_error(status)) return status; status = f_account_id_group_by_name(cache->action.generic.string, id); @@ -381,20 +370,18 @@ extern "C" { return F_none; } - return F_status_set_error(status); + return status; } else if (number > F_type_size_32_unsigned_d) { return F_status_set_error(F_number_too_large); } - *id = (gid_t) number; - return status; } #endif // _di_controller_get_id_group_ #ifndef _di_controller_perform_ready_ - f_status_t controller_perform_ready(const controller_global_t global, const bool is_entry, controller_cache_t * const cache) { + f_status_t controller_perform_ready(const controller_global_t *global, controller_cache_t * const cache, const bool is_entry) { if (!is_entry) { return F_none; @@ -402,9 +389,9 @@ extern "C" { f_status_t status = F_none; - if (global.setting->entry.pid != controller_entry_pid_disable_e && !global.setting->path_pid.used) { - if (global.main->parameters[controller_parameter_validate_e].result == f_console_result_additional_e) { - status = controller_file_pid_create(global.main->pid, global.setting->path_pid); + if (global->setting->entry.pid != controller_entry_pid_disable_e && !global->setting->path_pid.used) { + if (global->main->parameters[controller_parameter_validate_e].result == f_console_result_additional_e) { + status = controller_file_pid_create(global->main->pid, global->setting->path_pid); } // Report pid file error but because this could be an "init" program, consider the pid file as optional and continue on. @@ -412,200 +399,227 @@ extern "C" { // Always return immediately on memory errors. if (F_status_set_fine(status) == F_memory_not) { - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->error.to, global.thread); + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->error.to, global->thread); - controller_print_error_file(global.main->error, F_status_set_fine(status), "controller_file_pid_create", F_true, global.setting->path_pid.string, "create", fll_error_file_type_file_e, 0); + controller_print_error_file(0, global->main->error, F_status_set_fine(status), "controller_file_pid_create", F_true, global->setting->path_pid.string, "create", fll_error_file_type_file_e); - flockfile(global.main->error.to.stream); + flockfile(global->main->error.to.stream); - controller_entry_print_error_cache(is_entry, global.main->error, cache->action); + controller_entry_print_error_cache(is_entry, global->main->error, cache->action); - controller_unlock_print_flush(global.main->error.to, global.thread); + controller_unlock_print_flush(global->main->error.to, global->thread); } return status; } - if (global.main->warning.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->warning.to, global.thread); + if (global->main->warning.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->warning.to, global->thread); if (F_status_set_fine(status) == F_read_only) { - fl_print_format("%c%[%SThe pid file '%]", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix, global.main->warning.context); - fl_print_format("%[%Q%]", global.main->warning.to.stream, global.main->warning.notable, global.setting->path_pid, global.main->warning.notable); - fl_print_format("%[' could not be written because the destination is read only.%]%c", global.main->warning.to.stream, global.main->warning.context, global.main->warning.context, f_string_eol_s[0]); + fl_print_format("%c%[%SThe pid file '%]", global->main->warning.to.stream, f_string_eol_s[0], global->main->warning.context, global->main->warning.prefix, global->main->warning.context); + fl_print_format("%[%Q%]", global->main->warning.to.stream, global->main->warning.notable, global->setting->path_pid, global->main->warning.notable); + fl_print_format("%[' could not be written because the destination is read only.%]%c", global->main->warning.to.stream, global->main->warning.context, global->main->warning.context, f_string_eol_s[0]); } else { - controller_print_error_file(global.main->warning, F_status_set_fine(status), "controller_file_pid_create", F_true, global.setting->path_pid.string, "create", fll_error_file_type_file_e, 0); + controller_print_error_file(0, global->main->warning, F_status_set_fine(status), "controller_file_pid_create", F_true, global->setting->path_pid.string, "create", fll_error_file_type_file_e); } - controller_entry_print_error_cache(is_entry, global.main->warning, cache->action); + controller_entry_print_error_cache(is_entry, global->main->warning, cache->action); - controller_unlock_print_flush(global.main->warning.to, global.thread); + controller_unlock_print_flush(global->main->warning.to, global->thread); } status = F_none; } else { - global.setting->pid_created = F_true; + global->setting->pid_created = F_true; - if (global.main->output.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->output.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cPID file '", global.main->output.to.stream, f_string_eol_s[0]); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.notable, global.setting->path_pid, global.main->context.set.notable); + fl_print_format("%cPID file '", global->main->output.to.stream, f_string_eol_s[0]); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.notable, global->setting->path_pid, global->main->context.set.notable); - if (global.main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { - fl_print_format("' created.%c", global.main->output.to.stream, f_string_eol_s[0]); + if (global->main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { + fl_print_format("' created.%c", global->main->output.to.stream, f_string_eol_s[0]); } else { - fl_print_format("'.%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format("'.%c", global->main->output.to.stream, f_string_eol_s[0]); } - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } } - if (global.setting->path_control.used) { - if (global.setting->control_readonly) { - if (f_file_exists(global.setting->path_control.string) != F_true) { - if (global.main->output.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->setting->path_control.used) { + if (global->setting->control_readonly) { + if (f_file_exists(global->setting->path_control.string) != F_true) { + if (global->main->output.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%c%[%SControl socket '%]", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix, global.main->warning.context); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.notable, global.setting->path_control, global.main->context.set.notable); - fl_print_format("' .%c", global.main->output.to.stream, f_string_eol_s[0]); - fl_print_format("%[' cannot be found while read only mode is enabled and so the Control socket is unavailable.%]%c", global.main->output.to.stream, global.main->warning.context, global.main->warning.context, f_string_eol_s[0]); + fl_print_format("%c%[%SControl socket '%]", global->main->warning.to.stream, f_string_eol_s[0], global->main->warning.context, global->main->warning.prefix, global->main->warning.context); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.notable, global->setting->path_control, global->main->context.set.notable); + fl_print_format("' .%c", global->main->output.to.stream, f_string_eol_s[0]); + fl_print_format("%[' cannot be found while read only mode is enabled and so the Control socket is unavailable.%]%c", global->main->output.to.stream, global->main->warning.context, global->main->warning.context, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } return status; } } else { - status = f_socket_create(&global.setting->control_socket); + status = f_socket_create(&global->setting->control_socket); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_memory_not) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_socket_create", F_true, global.thread); + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_socket_create", F_true); return status; } - if (global.main->output.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->output.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%c%[%SControl socket '%]", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix, global.main->warning.context); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.notable, global.setting->path_control, global.main->context.set.notable); - fl_print_format("%[' could not be created, code %]", global.main->output.to.stream, global.main->warning.context, global.main->warning.context); - fl_print_format("%[%ui%]", global.main->output.to.stream, global.main->context.set.notable, F_status_set_fine(status), global.main->context.set.notable); - fl_print_format("%[.%]%c", global.main->output.to.stream, global.main->warning.context, global.main->warning.context, f_string_eol_s[0]); + fl_print_format("%c%[%SControl socket '%]", global->main->warning.to.stream, f_string_eol_s[0], global->main->warning.context, global->main->warning.prefix, global->main->warning.context); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.notable, global->setting->path_control, global->main->context.set.notable); + fl_print_format("%[' could not be created, code %]", global->main->output.to.stream, global->main->warning.context, global->main->warning.context); + fl_print_format("%[%ui%]", global->main->output.to.stream, global->main->context.set.notable, F_status_set_fine(status), global->main->context.set.notable); + fl_print_format("%[.%]%c", global->main->output.to.stream, global->main->warning.context, global->main->warning.context, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } else { - status = f_file_remove(global.setting->path_control.string); + status = f_file_remove(global->setting->path_control.string); if (F_status_set_fine(status) == F_memory_not) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_file_remove", F_true, global.thread); + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_file_remove", F_true); return status; } - global.setting->control_socket.name = global.setting->path_control.string; + global->setting->control_socket.name = global->setting->path_control.string; - status = f_socket_bind_file(global.setting->control_socket); + status = f_socket_bind_file(global->setting->control_socket); if (F_status_is_error(status)) { - f_socket_disconnect(&global.setting->control_socket, f_socket_close_fast_e); + f_socket_disconnect(&global->setting->control_socket, f_socket_close_fast_e); if (F_status_set_fine(status) == F_memory_not) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_socket_bind_file", F_true, global.thread); + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_socket_bind_file", F_true); return status; } - if (global.main->output.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->output.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%c%[%SControl socket '%]", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix, global.main->warning.context); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.notable, global.setting->path_control, global.main->context.set.notable); - fl_print_format("%[' could not be bound, code %]", global.main->output.to.stream, global.main->warning.context, global.main->warning.context); - fl_print_format("%[%ui%]", global.main->output.to.stream, global.main->context.set.notable, F_status_set_fine(status), global.main->context.set.notable); - fl_print_format("%[.%]%c", global.main->output.to.stream, global.main->warning.context, global.main->warning.context, f_string_eol_s[0]); + fl_print_format("%c%[%SControl socket '%]", global->main->warning.to.stream, f_string_eol_s[0], global->main->warning.context, global->main->warning.prefix, global->main->warning.context); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.notable, global->setting->path_control, global->main->context.set.notable); + fl_print_format("%[' could not be bound, code %]", global->main->output.to.stream, global->main->warning.context, global->main->warning.context); + fl_print_format("%[%ui%]", global->main->output.to.stream, global->main->context.set.notable, F_status_set_fine(status), global->main->context.set.notable); + fl_print_format("%[.%]%c", global->main->output.to.stream, global->main->warning.context, global->main->warning.context, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } else { - status = f_file_role_change(global.setting->path_control.string, global.setting->control_user, global.setting->control_group, F_true); + status = f_file_role_change(global->setting->path_control.string, global->setting->control_user, global->setting->control_group, F_true); if (F_status_is_error(status)) { - f_socket_disconnect(&global.setting->control_socket, f_socket_close_fast_e); + f_socket_disconnect(&global->setting->control_socket, f_socket_close_fast_e); if (F_status_set_fine(status) == F_memory_not) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_file_role_change", F_true, global.thread); + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_file_role_change", F_true); return status; } - if (global.main->output.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->output.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%c%[%SControl socket '%]", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix, global.main->warning.context); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.notable, global.setting->path_control, global.main->context.set.notable); - fl_print_format("%[' failed to set file roles, code %]", global.main->output.to.stream, global.main->warning.context, global.main->warning.context); - fl_print_format("%[%ui%]", global.main->output.to.stream, global.main->context.set.notable, F_status_set_fine(status), global.main->context.set.notable); - fl_print_format("%[.%]%c", global.main->output.to.stream, global.main->warning.context, global.main->warning.context, f_string_eol_s[0]); + fl_print_format("%c%[%SControl socket '%]", global->main->warning.to.stream, f_string_eol_s[0], global->main->warning.context, global->main->warning.prefix, global->main->warning.context); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.notable, global->setting->path_control, global->main->context.set.notable); + fl_print_format("%[' failed to set file roles, code %]", global->main->output.to.stream, global->main->warning.context, global->main->warning.context); + fl_print_format("%[%ui%]", global->main->output.to.stream, global->main->context.set.notable, F_status_set_fine(status), global->main->context.set.notable); + fl_print_format("%[.%]%c", global->main->output.to.stream, global->main->warning.context, global->main->warning.context, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } else { - status = f_file_mode_set(global.setting->path_control.string, global.setting->control_mode); + status = f_file_mode_set(global->setting->path_control.string, global->setting->control_mode); if (F_status_is_error(status)) { - f_socket_disconnect(&global.setting->control_socket, f_socket_close_fast_e); + f_socket_disconnect(&global->setting->control_socket, f_socket_close_fast_e); if (F_status_set_fine(status) == F_memory_not) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_file_role_change", F_true, global.thread); + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_file_role_change", F_true); return status; } - if (global.main->output.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->output.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%c%[%SControl socket '%]", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix, global.main->warning.context); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.notable, global.setting->path_control, global.main->context.set.notable); - fl_print_format("%[' failed to set file mode, code %]", global.main->output.to.stream, global.main->warning.context, global.main->warning.context); - fl_print_format("%[%ui%]", global.main->output.to.stream, global.main->context.set.notable, F_status_set_fine(status), global.main->context.set.notable); - fl_print_format("%[.%]%c", global.main->output.to.stream, global.main->warning.context, global.main->warning.context, f_string_eol_s[0]); + fl_print_format("%c%[%SControl socket '%]", global->main->warning.to.stream, f_string_eol_s[0], global->main->warning.context, global->main->warning.prefix, global->main->warning.context); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.notable, global->setting->path_control, global->main->context.set.notable); + fl_print_format("%[' failed to set file mode, code %]", global->main->output.to.stream, global->main->warning.context, global->main->warning.context); + fl_print_format("%[%ui%]", global->main->output.to.stream, global->main->context.set.notable, F_status_set_fine(status), global->main->context.set.notable); + fl_print_format("%[.%]%c", global->main->output.to.stream, global->main->warning.context, global->main->warning.context, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } else { - if (global.main->output.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->output.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cControl socket '", global.main->output.to.stream, f_string_eol_s[0]); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.notable, global.setting->path_control, global.main->context.set.notable); + fl_print_format("%cControl socket '", global->main->output.to.stream, f_string_eol_s[0]); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.notable, global->setting->path_control, global->main->context.set.notable); - if (global.main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { - fl_print_format("' created.%c", global.main->output.to.stream, f_string_eol_s[0]); + if (global->main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { + fl_print_format("' created.%c", global->main->output.to.stream, f_string_eol_s[0]); } else { - fl_print_format("'.%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format("'.%c", global->main->output.to.stream, f_string_eol_s[0]); } - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); + } + + status = f_thread_create(0, &global->thread->id_listen, &controller_thread_control_listen, (void *) global); + + if (status == F_child) { + return status; } - // @todo start the control thread. + if (F_status_is_error_not(status)) { + status = f_thread_create(0, &global->thread->id_control, &controller_thread_control, (void *) global); + + if (status == F_child) { + return status; + } + } + + if (F_status_is_error(status)) { + if (global->thread->id_listen) { + f_thread_cancel(global->thread->id_listen); + f_thread_join(global->thread->id_listen, 0); + + global->thread->id_listen = 0; + } + + global->thread->id_control = 0; + + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_thread_create", F_true); + } + } } } } @@ -699,17 +713,27 @@ extern "C" { #ifndef _di_controller_time_sleep_nanoseconds_ int controller_time_sleep_nanoseconds(controller_main_t * const main, controller_setting_t * const setting, struct timespec time) { - if (setting->interruptible) { - f_signal_mask(SIG_UNBLOCK, &main->signal.set, 0); - } + // When sleep is a second or more, instead wait for terminating signals if interruptible. + if (setting->interruptible && time.tv_sec) { + siginfo_t information; + f_signal_t signal = f_signal_t_initialize; + + memset(&information, 0, sizeof(siginfo_t)); - const int result = nanosleep(&time, 0); + f_signal_set_empty(&signal.set); + f_signal_set_add(F_signal_abort, &signal.set); + f_signal_set_add(F_signal_interrupt, &signal.set); + f_signal_set_add(F_signal_quit, &signal.set); + f_signal_set_add(F_signal_termination, &signal.set); - if (setting->interruptible) { - f_signal_mask(SIG_BLOCK, &main->signal.set, 0); + if (F_status_is_error(f_signal_wait_until(&signal.set, &time, &information))) { + return -1; + } + + return 0; } - return result; + return nanosleep(&time, 0); } #endif // _di_controller_time_sleep_nanoseconds_ diff --git a/level_3/controller/c/private-controller.h b/level_3/controller/c/private-controller.h index 872db43..a0fd07b 100644 --- a/level_3/controller/c/private-controller.h +++ b/level_3/controller/c/private-controller.h @@ -207,7 +207,7 @@ extern "C" { * Errors (with error bit) from: fl_conversion_string_to_decimal_unsigned() */ #ifndef _di_controller_file_pid_read_ - f_status_t controller_file_pid_read(const f_string_static_t path, pid_t *pid) F_attribute_visibility_internal_d; + f_status_t controller_file_pid_read(const f_string_static_t path, pid_t * const pid) F_attribute_visibility_internal_d; #endif // _di_controller_file_pid_read_ /** @@ -234,7 +234,7 @@ extern "C" { * @see fl_conversion_string_to_number_unsigned() */ #ifndef _di_controller_get_id_user_ - f_status_t controller_get_id_user(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, uid_t *id) F_attribute_visibility_internal_d; + f_status_t controller_get_id_user(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, uid_t * const id) F_attribute_visibility_internal_d; #endif // _di_controller_get_id_user_ /** @@ -261,7 +261,7 @@ extern "C" { * @see fl_conversion_string_to_number_unsigned() */ #ifndef _di_controller_get_id_group_ - f_status_t controller_get_id_group(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, gid_t *id) F_attribute_visibility_internal_d; + f_status_t controller_get_id_group(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t * const cache, gid_t * const id) F_attribute_visibility_internal_d; #endif // _di_controller_get_id_group_ /** @@ -273,11 +273,11 @@ extern "C" { * * @param global * The global data. + * @param cache + * The cache. * @param is_entry * If TRUE, then this operate as an entry. * If FALSE, then this operate as an exit. - * @param cache - * The cache. * * @return * F_none on success. @@ -287,7 +287,7 @@ extern "C" { * @see controller_file_pid_create() */ #ifndef _di_controller_perform_ready_ - extern f_status_t controller_perform_ready(const controller_global_t global, const bool is_entry, controller_cache_t * const cache) F_attribute_visibility_internal_d; + extern f_status_t controller_perform_ready(const controller_global_t *global, controller_cache_t * const cache, const bool is_entry) F_attribute_visibility_internal_d; #endif // _di_controller_perform_ready_ /** @@ -353,11 +353,6 @@ extern "C" { /** * Sleep for a given number of nanoseconds. * - * The nanosleep() function handles signals within itself. - * Temporarily unblock signals so that the nanosleep can receive the signal and then restore the signals once done. - * - * The signals will not be unblocked when in uninterruptible mode. - * * @param main * The main program data. * @param setting @@ -366,10 +361,9 @@ extern "C" { * The number of nanoseconds to sleep. * * @return - * The results of nanosleep(). + * The result of nanosleep(). * * @see nanosleep() - * @see controller_time_milliseconds() */ #ifndef _di_controller_time_sleep_nanoseconds_ extern int controller_time_sleep_nanoseconds(controller_main_t * const main, controller_setting_t * const setting, struct timespec time) F_attribute_visibility_internal_d; diff --git a/level_3/controller/c/private-controller_print.c b/level_3/controller/c/private-controller_print.c index 761145f..f4191bb 100644 --- a/level_3/controller/c/private-controller_print.c +++ b/level_3/controller/c/private-controller_print.c @@ -8,7 +8,7 @@ extern "C" { #endif #ifndef _di_controller_print_error_ - void controller_print_error(const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback, controller_thread_t *thread) { + void controller_print_error(controller_thread_t * const thread, const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback) { if (print.verbosity == f_console_verbosity_quiet_e) return; if (status == F_interrupt) return; @@ -27,9 +27,10 @@ extern "C" { #endif // _di_controller_print_error_ #ifndef _di_controller_print_error_file_ - void controller_print_error_file(const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type, controller_thread_t *thread) { + void controller_print_error_file(controller_thread_t * const thread, const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type) { if (print.verbosity == f_console_verbosity_quiet_e) return; + if (status == F_interrupt) return; // fll_error_print() automatically locks, so manually handle only the mutex locking and flushing rather than calling controller_lock_print(). if (thread) { diff --git a/level_3/controller/c/private-controller_print.h b/level_3/controller/c/private-controller_print.h index f23d60f..bbfd80e 100644 --- a/level_3/controller/c/private-controller_print.h +++ b/level_3/controller/c/private-controller_print.h @@ -15,6 +15,9 @@ extern "C" { /** * Print the error, locking the print mutex during the print. * + * @param thread + * (optional) The thread data. + * Set to NULL to disable locking on the thread (this should be done only if the lock is already in place). * @param print * Designates how printing is to be performed. * @param status @@ -25,19 +28,19 @@ extern "C" { * Set to 0 to disable. * @param fallback * Set to F_true to print the fallback error message for unknown errors. - * @param thread - * (optional) The thread data. - * Set to NULL to disable locking on the thread (this should be done only if the lock is already in place). * * @see fll_error_print() */ #ifndef _di_controller_print_error_ - extern void controller_print_error(const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback, controller_thread_t *thread) F_attribute_visibility_internal_d; + extern void controller_print_error(controller_thread_t * const thread, const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback) F_attribute_visibility_internal_d; #endif // _di_controller_print_error_ /** * Print the file error, locking the print mutex during the print. * + * @param thread + * (optional) The thread data. + * Set to NULL to disable locking on the thread (this should be done only if the lock is already in place). * @param print * Designates how printing is to be performed. * @param status @@ -54,14 +57,11 @@ extern "C" { * The operation that fails, such as 'create' or 'access'. * @param type * A valid file type code from the fll_error_file_type enum. - * @param thread - * (optional) The thread data. - * Set to NULL to disable locking on the thread (this should be done only if the lock is already in place). * * @see fll_error_file_print() */ #ifndef _di_controller_print_error_file_ - extern void controller_print_error_file(const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type, controller_thread_t *thread) F_attribute_visibility_internal_d; + extern void controller_print_error_file(controller_thread_t * const thread, const fl_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type) F_attribute_visibility_internal_d; #endif // _di_controller_print_error_file_ /** diff --git a/level_3/controller/c/private-entry.c b/level_3/controller/c/private-entry.c index 7fe41dd..b7ce5c3 100644 --- a/level_3/controller/c/private-entry.c +++ b/level_3/controller/c/private-entry.c @@ -919,8 +919,6 @@ extern "C" { // If ready was never found in the entry, then default to always ready. if (global.setting->ready == controller_setting_ready_no_e) { global.setting->ready = controller_setting_ready_yes_e; - - // @todo set socket file if applicable. } return status; @@ -928,7 +926,7 @@ extern "C" { #endif // _di_controller_entry_preprocess_ #ifndef _di_controller_entry_process_ - f_status_t controller_entry_process(const controller_global_t global, const bool failsafe, const bool is_entry, controller_cache_t * const cache) { + f_status_t controller_entry_process(const controller_global_t *global, controller_cache_t * const cache, const bool failsafe, const bool is_entry) { f_status_t status = F_none; f_status_t status_lock = F_none; @@ -942,7 +940,7 @@ extern "C" { uint8_t options_force = 0; uint8_t options_process = 0; - controller_entry_t *entry = is_entry ? &global.setting->entry : &global.setting->exit; + controller_entry_t *entry = is_entry ? &global->setting->entry : &global->setting->exit; controller_entry_action_t *entry_action = 0; controller_entry_actions_t *entry_actions = 0; controller_process_t *process = 0; @@ -961,13 +959,13 @@ extern "C" { macro_f_array_lengths_t_increase_by(status, cache->ats, controller_common_allocation_small_d) if (F_status_is_error(status)) { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "macro_f_array_lengths_t_increase_by", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "macro_f_array_lengths_t_increase_by", F_true, global->thread); return status; } // utilize the ats cache as an item execution stack (at_i is for item index, and at_j (at_i + 1) is for action index). - cache->ats.array[0] = failsafe ? global.setting->failsafe_item_id : 0; + cache->ats.array[0] = failsafe ? global->setting->failsafe_item_id : 0; cache->ats.array[1] = 0; cache->ats.used = 2; @@ -977,27 +975,33 @@ extern "C" { status = controller_dynamic_append_terminated(entry->items.array[cache->ats.array[0]].name, &cache->action.name_item); if (F_status_is_error(status)) { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global->thread); return status; } - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global.main->error.verbosity == f_console_verbosity_verbose_e || global.main->error.verbosity == f_console_verbosity_debug_e) { - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global->main->error.verbosity == f_console_verbosity_verbose_e || global->main->error.verbosity == f_console_verbosity_debug_e) { + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cProcessing %s%s item '", global.main->output.to.stream, f_string_eol_s[0], failsafe ? "failsafe " : "", is_entry ? controller_entry_s : controller_exit_s); - fl_print_format("%[%Q%]'.%c", global.main->output.to.stream, global.main->context.set.notable, cache->action.name_item, global.main->context.set.notable, f_string_eol_s[0]); + fl_print_format("%cProcessing %s%s item '", global->main->output.to.stream, f_string_eol_s[0], failsafe ? "failsafe " : "", is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("%[%Q%]'.%c", global->main->output.to.stream, global->main->context.set.notable, cache->action.name_item, global->main->context.set.notable, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } - while (controller_thread_is_enabled(is_entry, global.thread)) { + // The pre-process determines if ready is explicitly specified within the entry file and if it is not start as ready. + if (global->setting->ready == controller_setting_ready_yes_e) { + status = controller_perform_ready(global, cache, is_entry); + if (F_status_is_error(status)) return status; + } + + while (controller_thread_is_enabled(is_entry, global->thread)) { entry_actions = &entry->items.array[cache->ats.array[at_i]].actions; - for (; cache->ats.array[at_j] < entry_actions->used && controller_thread_is_enabled(is_entry, global.thread); ++cache->ats.array[at_j]) { + for (; cache->ats.array[at_j] < entry_actions->used && controller_thread_is_enabled(is_entry, global->thread); ++cache->ats.array[at_j]) { entry_action = &entry_actions->array[cache->ats.array[at_j]]; @@ -1007,57 +1011,57 @@ extern "C" { status = controller_dynamic_append_terminated(controller_entry_action_type_name(entry_action->type), &cache->action.name_action); if (F_status_is_error(status)) { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global->thread); return status; } if (F_status_is_error(entry_action->status)) { - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e) { - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e) { + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cThe %s item action '", global.main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.title, cache->action.name_action, global.main->context.set.title); + fl_print_format("%cThe %s item action '", global->main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.title, cache->action.name_action, global->main->context.set.title); if (entry_action->parameters.used) { - fl_print_format(" %[", global.main->output.to.stream, global.main->context.set.notable); + fl_print_format(" %[", global->main->output.to.stream, global->main->context.set.notable); - controller_entry_action_parameters_print(global.main->output.to.stream, *entry_action); + controller_entry_action_parameters_print(global->main->output.to.stream, *entry_action); - fl_print_format("%]", global.main->output.to.stream, global.main->context.set.notable); + fl_print_format("%]", global->main->output.to.stream, global->main->context.set.notable); } - fl_print_format("' is %[%s%] and is in a ", global.main->output.to.stream, global.main->context.set.notable, entry_action->code & controller_entry_rule_code_require_d ? "required" : "optional", global.main->context.set.notable); + fl_print_format("' is %[%s%] and is in a ", global->main->output.to.stream, global->main->context.set.notable, entry_action->code & controller_entry_rule_code_require_d ? "required" : "optional", global->main->context.set.notable); - fl_print_format("%[failed%] state, skipping.%c", global.main->output.to.stream, global.main->context.set.notable, global.main->context.set.notable, global.main->context.set.notable, f_string_eol_s[0]); + fl_print_format("%[failed%] state, skipping.%c", global->main->output.to.stream, global->main->context.set.notable, global->main->context.set.notable, global->main->context.set.notable, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } else { - if ((entry_action->code & controller_entry_rule_code_require_d) && global.main->error.verbosity != f_console_verbosity_quiet_e || !(entry_action->code & controller_entry_rule_code_require_d) && (global.main->warning.verbosity == f_console_verbosity_verbose_e || global.main->warning.verbosity == f_console_verbosity_debug_e)) { + if ((entry_action->code & controller_entry_rule_code_require_d) && global->main->error.verbosity != f_console_verbosity_quiet_e || !(entry_action->code & controller_entry_rule_code_require_d) && (global->main->warning.verbosity == f_console_verbosity_verbose_e || global->main->warning.verbosity == f_console_verbosity_debug_e)) { fl_print_t *output = 0; if (entry_action->code & controller_entry_rule_code_require_d) { - output = &global.main->error; + output = &global->main->error; } else { - output = &global.main->warning; + output = &global->main->warning; } - controller_lock_print(output->to, global.thread); + controller_lock_print(output->to, global->thread); fl_print_format("%c%[%SThe %s item action '%]", output->to.stream, f_string_eol_s[0], output->context, output->prefix ? output->prefix : f_string_empty_s, is_entry ? controller_entry_s : controller_exit_s, output->context); fl_print_format("%[%Q%]", output->to.stream, output->notable, cache->action.name_action, output->notable); if (entry_action->parameters.used) { - fl_print_format(" %[", output->to.stream, global.main->context.set.notable); + fl_print_format(" %[", output->to.stream, global->main->context.set.notable); controller_entry_action_parameters_print(output->to.stream, *entry_action); - fl_print_format("%]", output->to.stream, global.main->context.set.notable); + fl_print_format("%]", output->to.stream, global->main->context.set.notable); } if (entry_action->code & controller_entry_rule_code_require_d) { @@ -1078,7 +1082,7 @@ extern "C" { controller_entry_print_error_cache(is_entry, *output, cache->action); - controller_unlock_print_flush(output->to, global.thread); + controller_unlock_print_flush(output->to, global->thread); } if (controller_entry_action_type_is_rule(entry_action->type) && entry_action->code & controller_entry_rule_code_require_d) { @@ -1090,61 +1094,61 @@ extern "C" { } if (entry_action->type == controller_entry_action_type_ready_e) { - if ((entry_action->code & controller_entry_rule_code_wait_d) || global.setting->ready == controller_setting_ready_wait_e) { - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global.main->error.verbosity == f_console_verbosity_verbose_e || global.main->error.verbosity == f_console_verbosity_debug_e || entry->show == controller_entry_show_init_e) { - if (global.main->output.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->output.to, global.thread); + if ((entry_action->code & controller_entry_rule_code_wait_d) || global->setting->ready == controller_setting_ready_wait_e) { + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global->main->error.verbosity == f_console_verbosity_verbose_e || global->main->error.verbosity == f_console_verbosity_debug_e || entry->show == controller_entry_show_init_e) { + if (global->main->output.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cWaiting before processing %s item action '", global.main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); - fl_print_format("%[%s%]", global.main->output.to.stream, global.main->context.set.title, controller_ready_s, global.main->context.set.title); - fl_print_format("'.%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format("%cWaiting before processing %s item action '", global->main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("%[%s%]", global->main->output.to.stream, global->main->context.set.title, controller_ready_s, global->main->context.set.title); + fl_print_format("'.%c", global->main->output.to.stream, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } - if (global.main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { - status = controller_rule_wait_all(global, is_entry, F_false, process); + if (global->main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { + status = controller_rule_wait_all(*global, is_entry, F_false, process); if (F_status_is_error(status)) return status; } } - if (global.setting->ready == controller_setting_ready_yes_e) { - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global.main->error.verbosity == f_console_verbosity_verbose_e || global.main->error.verbosity == f_console_verbosity_debug_e) { - if (global.main->output.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->setting->ready == controller_setting_ready_yes_e) { + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global->main->error.verbosity == f_console_verbosity_verbose_e || global->main->error.verbosity == f_console_verbosity_debug_e) { + if (global->main->output.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cIgnoring %s item action '", global.main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); - fl_print_format("%[%s%]", global.main->output.to.stream, global.main->context.set.title, controller_ready_s, global.main->context.set.title); - fl_print_format("', state already is ready.%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format("%cIgnoring %s item action '", global->main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("%[%s%]", global->main->output.to.stream, global->main->context.set.title, controller_ready_s, global->main->context.set.title); + fl_print_format("', state already is ready.%c", global->main->output.to.stream, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } } else { - if (!failsafe && (global.main->error.verbosity == f_console_verbosity_verbose_e || entry->show == controller_entry_show_init_e) && global.main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e) { - fl_print_format("%cState is now '%[%s%]'.%c", global.main->output.to.stream, f_string_eol_s[0], global.main->context.set.notable, controller_ready_s, global.main->context.set.notable, f_string_eol_s[0]); + if (!failsafe && (global->main->error.verbosity == f_console_verbosity_verbose_e || entry->show == controller_entry_show_init_e) && global->main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e) { + fl_print_format("%cState is now '%[%s%]'.%c", global->main->output.to.stream, f_string_eol_s[0], global->main->context.set.notable, controller_ready_s, global->main->context.set.notable, f_string_eol_s[0]); } - status = controller_perform_ready(global, is_entry, cache); + status = controller_perform_ready(global, cache, is_entry); if (F_status_is_error(status)) return status; } } else if (entry_action->type == controller_entry_action_type_item_e) { - if (entry_action->number == 0 || entry_action->number >= entry->items.used || failsafe && entry_action->number == global.setting->failsafe_item_id) { + if (entry_action->number == 0 || entry_action->number >= entry->items.used || failsafe && entry_action->number == global->setting->failsafe_item_id) { // This should not happen if the pre-process is working as intended, but in case it doesn't, return a critical error to prevent infinite recursion and similar errors. - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->error.to, global.thread); + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->error.to, global->thread); - fl_print_format("%c%[Invalid %s item index '%]", global.main->error.to.stream, f_string_eol_s[0], global.main->error.context, is_entry ? controller_entry_s : controller_exit_s, global.main->error.context); - fl_print_format("%[%un%]", global.main->error.to.stream, global.main->error.notable, entry_action->number, global.main->error.notable); - fl_print_format("%[' detected.%]%c", global.main->error.to.stream, global.main->error.context, global.main->error.context, f_string_eol_s[0]); + fl_print_format("%c%[Invalid %s item index '%]", global->main->error.to.stream, f_string_eol_s[0], global->main->error.context, is_entry ? controller_entry_s : controller_exit_s, global->main->error.context); + fl_print_format("%[%un%]", global->main->error.to.stream, global->main->error.notable, entry_action->number, global->main->error.notable); + fl_print_format("%[' detected.%]%c", global->main->error.to.stream, global->main->error.context, global->main->error.context, f_string_eol_s[0]); - controller_entry_print_error_cache(is_entry, global.main->error, cache->action); + controller_entry_print_error_cache(is_entry, global->main->error, cache->action); - controller_unlock_print_flush(global.main->error.to, global.thread); + controller_unlock_print_flush(global->main->error.to, global->thread); } return F_status_is_error(F_critical); @@ -1153,7 +1157,7 @@ extern "C" { macro_f_array_lengths_t_increase_by(status, cache->ats, controller_common_allocation_small_d) if (F_status_is_error(status)) { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "macro_f_array_lengths_t_increase_by", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "macro_f_array_lengths_t_increase_by", F_true, global->thread); return status; } @@ -1176,40 +1180,41 @@ extern "C" { status = controller_dynamic_append_terminated(entry->items.array[cache->ats.array[at_i]].name, &cache->action.name_item); if (F_status_is_error(status)) { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global->thread); return status; } - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global.main->error.verbosity == f_console_verbosity_verbose_e || global.main->error.verbosity == f_console_verbosity_debug_e) { - if (global.main->output.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global->main->error.verbosity == f_console_verbosity_verbose_e || global->main->error.verbosity == f_console_verbosity_debug_e) { + if (global->main->output.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cProcessing %s item '", global.main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.title, cache->action.name_item, global.main->context.set.title); - fl_print_format("'.%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format("%cProcessing %s item '", global->main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.title, cache->action.name_item, global->main->context.set.title); + fl_print_format("'.%c", global->main->output.to.stream, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } - // exit inner loop to force restarting and start processing the requested item. + // Exit inner loop to force restarting and start processing the requested item. break; } else if (entry_action->type == controller_entry_action_type_consider_e || controller_entry_action_type_is_rule(entry_action->type)) { - status_lock = controller_lock_write(is_entry, global.thread, &global.thread->lock.rule); + status_lock = controller_lock_write(is_entry, global->thread, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { - controller_lock_print_error_critical(global.main->error, F_status_set_fine(status_lock), F_false, global.thread); + controller_lock_print_error_critical(global->main->error, F_status_set_fine(status_lock), F_false, global->thread); + break; } - status = controller_rules_increase(&global.setting->rules); + status = controller_rules_increase(&global->setting->rules); - f_thread_unlock(&global.thread->lock.rule); + f_thread_unlock(&global->thread->lock.rule); if (F_status_is_error(status)) { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "controller_rules_increase", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "controller_rules_increase", F_true, global->thread); return status; } @@ -1224,48 +1229,49 @@ extern "C" { id_rule_name[entry_action->parameters.array[0].used] = f_path_separator_s[0]; id_rule_name[id_rule_length] = 0; - status_lock = controller_lock_read(is_entry, global.thread, &global.thread->lock.rule); + status_lock = controller_lock_read(is_entry, global->thread, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { - controller_lock_print_error_critical(global.main->error, F_status_set_fine(status_lock), F_true, global.thread); + controller_lock_print_error_critical(global->main->error, F_status_set_fine(status_lock), F_true, global->thread); + break; } - status = controller_rule_find(alias_rule, global.setting->rules, 0); + status = controller_rule_find(alias_rule, global->setting->rules, 0); - f_thread_unlock(&global.thread->lock.rule); + f_thread_unlock(&global->thread->lock.rule); - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global.main->error.verbosity == f_console_verbosity_verbose_e || global.main->error.verbosity == f_console_verbosity_debug_e || (entry->show == controller_entry_show_init_e && entry_action->type != controller_entry_action_type_consider_e)) { - if (global.main->output.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global->main->error.verbosity == f_console_verbosity_verbose_e || global->main->error.verbosity == f_console_verbosity_debug_e || (entry->show == controller_entry_show_init_e && entry_action->type != controller_entry_action_type_consider_e)) { + if (global->main->output.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%c%s %s item rule ", global.main->output.to.stream, f_string_eol_s[0], entry_action->type == controller_entry_action_type_consider_e ? "Considering" : "Processing", is_entry ? controller_entry_s : controller_exit_s); - fl_print_format("'%[%Q%]'", global.main->output.to.stream, global.main->context.set.title, alias_rule, global.main->context.set.title); + fl_print_format("%c%s %s item rule ", global->main->output.to.stream, f_string_eol_s[0], entry_action->type == controller_entry_action_type_consider_e ? "Considering" : "Processing", is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("'%[%Q%]'", global->main->output.to.stream, global->main->context.set.title, alias_rule, global->main->context.set.title); - if (entry->show == controller_entry_show_init_e && global.main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e) { - fl_print_format(" [%[%s%]]", global.main->output.to.stream, global.main->context.set.notable, entry_action->code == controller_entry_rule_code_asynchronous_d ? controller_asynchronous_s : controller_synchronous_s, global.main->context.set.notable); + if (entry->show == controller_entry_show_init_e && global->main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e) { + fl_print_format(" [%[%s%]]", global->main->output.to.stream, global->main->context.set.notable, entry_action->code == controller_entry_rule_code_asynchronous_d ? controller_asynchronous_s : controller_synchronous_s, global->main->context.set.notable); if (entry_action->code == controller_entry_rule_code_wait_d) { - fl_print_format(" [%[%s%]]", global.main->output.to.stream, global.main->context.set.notable, controller_wait_s, global.main->context.set.notable); + fl_print_format(" [%[%s%]]", global->main->output.to.stream, global->main->context.set.notable, controller_wait_s, global->main->context.set.notable); } if (entry_action->code == controller_entry_rule_code_require_d) { - fl_print_format(" [%[%s%]]", global.main->output.to.stream, global.main->context.set.notable, controller_required_s, global.main->context.set.notable); + fl_print_format(" [%[%s%]]", global->main->output.to.stream, global->main->context.set.notable, controller_required_s, global->main->context.set.notable); } } - fl_print_format(".%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format(".%c", global->main->output.to.stream, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } - if (!controller_thread_is_enabled(is_entry, global.thread)) break; + if (!controller_thread_is_enabled(is_entry, global->thread)) break; - // the rule is not yet loaded, ensure that it is loaded. + // The rule is not yet loaded, ensure that it is loaded. if (status != F_true) { - // rule execution will re-use the existing cache, so save the current cache. + // Rule execution will re-use the existing cache, so save the current cache. const f_array_length_t cache_line_action = cache->action.line_action; const f_array_length_t cache_line_item = cache->action.line_item; @@ -1281,13 +1287,13 @@ extern "C" { memcpy(cache_name_item, cache->action.name_item.string, cache->action.name_item.used); memcpy(cache_name_file, cache->action.name_file.string, cache->action.name_file.used); - status_lock = controller_lock_write(is_entry, global.thread, &global.thread->lock.rule); + status_lock = controller_lock_write(is_entry, global->thread, &global->thread->lock.rule); if (F_status_is_fine(status_lock)) { - status = controller_rule_read(global, is_entry, alias_rule, cache, entry, &global.setting->rules.array[global.setting->rules.used]); + status = controller_rule_read(*global, is_entry, alias_rule, cache, entry, &global->setting->rules.array[global->setting->rules.used]); } - // restore cache. + // Restore cache. memcpy(cache->action.name_action.string, cache_name_action, cache_name_action_used); memcpy(cache->action.name_item.string, cache_name_item, cache_name_item_used); memcpy(cache->action.name_file.string, cache_name_file, cache_name_file_used); @@ -1304,30 +1310,30 @@ extern "C" { cache->action.line_item = cache_line_item; if (F_status_is_error(status_lock)) { - controller_lock_print_error_critical(global.main->error, F_status_set_fine(status_lock), F_false, global.thread); + controller_lock_print_error_critical(global->main->error, F_status_set_fine(status_lock), F_false, global->thread); break; } - if (F_status_set_fine(status) == F_interrupt || !controller_thread_is_enabled(is_entry, global.thread)) { - f_thread_unlock(&global.thread->lock.rule); + if (F_status_set_fine(status) == F_interrupt || !controller_thread_is_enabled(is_entry, global->thread)) { + f_thread_unlock(&global->thread->lock.rule); break; } if (F_status_is_error(status)) { - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->error.to, global.thread); + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->error.to, global->thread); - controller_entry_print_error_cache(is_entry, global.main->error, cache->action); + controller_entry_print_error_cache(is_entry, global->main->error, cache->action); - controller_unlock_print_flush(global.main->error.to, global.thread); + controller_unlock_print_flush(global->main->error.to, global->thread); } // Designate the action as failed. entry_action->status = F_status_set_error(F_failure); - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e) { - f_thread_unlock(&global.thread->lock.rule); + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e) { + f_thread_unlock(&global->thread->lock.rule); if (entry_action->code & controller_entry_rule_code_require_d) { return F_status_set_error(F_require); @@ -1338,17 +1344,17 @@ extern "C" { } } else { - ++global.setting->rules.used; + ++global->setting->rules.used; } - f_thread_unlock(&global.thread->lock.rule); + f_thread_unlock(&global->thread->lock.rule); } if (F_status_is_error_not(status)) { options_force = 0; options_process = 0; - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e) { + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e) { options_process |= controller_process_option_simulate_d; } @@ -1360,56 +1366,56 @@ extern "C" { options_process |= controller_process_option_wait_d; } - if (global.main->parameters[controller_parameter_validate_e].result == f_console_result_found_e) { + if (global->main->parameters[controller_parameter_validate_e].result == f_console_result_found_e) { options_process |= controller_process_option_validate_d; } if (entry_action->code & controller_entry_rule_code_asynchronous_d) { - if (global.main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { + if (global->main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { options_force |= controller_process_option_asynchronous_d; } options_process |= controller_process_option_asynchronous_d; } - status = controller_rule_process_begin(global, options_force, alias_rule, controller_entry_action_type_to_rule_action_type(entry_action->type), options_process, is_entry ? controller_process_type_entry_e : controller_process_type_exit_e, stack, *cache); + status = controller_rule_process_begin(*global, options_force, alias_rule, controller_entry_action_type_to_rule_action_type(entry_action->type), options_process, is_entry ? controller_process_type_entry_e : controller_process_type_exit_e, stack, *cache); if (F_status_set_fine(status) == F_memory_not || status == F_child || F_status_set_fine(status) == F_interrupt) { break; } - if (F_status_is_error(status) && global.main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e && (entry_action->code & controller_entry_rule_code_require_d)) { + if (F_status_is_error(status) && global->main->parameters[controller_parameter_simulate_e].result == f_console_result_none_e && (entry_action->code & controller_entry_rule_code_require_d)) { return F_status_set_error(F_require); } } } else if (entry_action->type == controller_entry_action_type_execute_e) { - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global.main->error.verbosity == f_console_verbosity_verbose_e || global.main->error.verbosity == f_console_verbosity_debug_e || entry->show == controller_entry_show_init_e) { - if (global.main->output.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->output.to, global.thread); + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e || global->main->error.verbosity == f_console_verbosity_verbose_e || global->main->error.verbosity == f_console_verbosity_debug_e || entry->show == controller_entry_show_init_e) { + if (global->main->output.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%c%s is executing '", global.main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("%c%s is executing '", global->main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); for (f_array_length_t k = 0; k < entry_action->parameters.used; ++k) { - fl_print_format("%[%Q%]", global.main->output.to.stream, global.main->context.set.title, entry_action->parameters.array[k], global.main->context.set.title); + fl_print_format("%[%Q%]", global->main->output.to.stream, global->main->context.set.title, entry_action->parameters.array[k], global->main->context.set.title); if (k + 1 < entry_action->parameters.used) { - f_print_character(f_string_space_s[0], global.main->output.to.stream); + f_print_character(f_string_space_s[0], global->main->output.to.stream); } } // for - fl_print_format("'.%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format("'.%c", global->main->output.to.stream, f_string_eol_s[0]); - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } } - if (global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e) { + if (global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e) { return F_execute; } - controller_thread_process_cancel(global, is_entry, is_entry ? controller_thread_cancel_execute_e : controller_thread_cancel_exit_execute_e, process); + controller_thread_process_cancel(*global, is_entry, is_entry ? controller_thread_cancel_execute_e : controller_thread_cancel_exit_execute_e, process); int result = 0; int option = FL_execute_parameter_option_path_d; @@ -1422,35 +1428,35 @@ extern "C" { if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_file_found_not) { - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->error.to, global.thread); + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->error.to, global->thread); - fl_print_format("%c%[%SExecution failed, unable to find program or script '%]", global.main->error.to.stream, f_string_eol_s[0], global.main->error.context, global.main->error.prefix ? global.main->error.prefix : f_string_empty_s, global.main->error.context); - fl_print_format("%[%Q%]", global.main->error.to.stream, global.main->error.notable, entry_action->parameters.array[0], global.main->error.notable); - fl_print_format("%['.%]%c", global.main->error.to.stream, global.main->error.context, global.main->error.context, f_string_eol_s[0]); + fl_print_format("%c%[%SExecution failed, unable to find program or script '%]", global->main->error.to.stream, f_string_eol_s[0], global->main->error.context, global->main->error.prefix ? global->main->error.prefix : f_string_empty_s, global->main->error.context); + fl_print_format("%[%Q%]", global->main->error.to.stream, global->main->error.notable, entry_action->parameters.array[0], global->main->error.notable); + fl_print_format("%['.%]%c", global->main->error.to.stream, global->main->error.context, global->main->error.context, f_string_eol_s[0]); - controller_entry_print_error_cache(is_entry, global.main->error, cache->action); + controller_entry_print_error_cache(is_entry, global->main->error, cache->action); - controller_unlock_print_flush(global.main->error.to, global.thread); + controller_unlock_print_flush(global->main->error.to, global->thread); } } else { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "fll_execute_into", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "fll_execute_into", F_true, global->thread); } return F_status_set_error(F_execute); } else if (result != 0) { - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->error.to, global.thread); + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->error.to, global->thread); - fl_print_format("%c%[%SExecution failed with return value of '%]", global.main->error.to.stream, f_string_eol_s[0], global.main->error.context, global.main->error.prefix ? global.main->error.prefix : f_string_empty_s, global.main->error.context); - fl_print_format("%[%i%]", global.main->error.to.stream, global.main->error.notable, result, global.main->error.notable); - fl_print_format("$['.%]%c", global.main->error.to.stream, global.main->error.context, global.main->error.context, f_string_eol_s[0]); + fl_print_format("%c%[%SExecution failed with return value of '%]", global->main->error.to.stream, f_string_eol_s[0], global->main->error.context, global->main->error.prefix ? global->main->error.prefix : f_string_empty_s, global->main->error.context); + fl_print_format("%[%i%]", global->main->error.to.stream, global->main->error.notable, result, global->main->error.notable); + fl_print_format("$['.%]%c", global->main->error.to.stream, global->main->error.context, global->main->error.context, f_string_eol_s[0]); - controller_entry_print_error_cache(is_entry, global.main->error, cache->action); + controller_entry_print_error_cache(is_entry, global->main->error, cache->action); - controller_unlock_print_flush(global.main->error.to, global.thread); + controller_unlock_print_flush(global->main->error.to, global->thread); } return F_status_set_error(F_execute); @@ -1464,55 +1470,55 @@ extern "C" { if (entry_action->code == controller_entry_timeout_code_kill_d) { entry->timeout_kill = entry_action->number; - controller_entry_preprocess_print_simulate_setting_value(global, is_entry, controller_timeout_s, controller_kill_s, entry->items.array[global.setting->failsafe_item_id].name, suffix); + controller_entry_preprocess_print_simulate_setting_value(*global, is_entry, controller_timeout_s, controller_kill_s, entry->items.array[global->setting->failsafe_item_id].name, suffix); } else if (entry_action->code == controller_entry_timeout_code_start_d) { entry->timeout_start = entry_action->number; - controller_entry_preprocess_print_simulate_setting_value(global, is_entry, controller_timeout_s, controller_start_s, entry->items.array[global.setting->failsafe_item_id].name, suffix); + controller_entry_preprocess_print_simulate_setting_value(*global, is_entry, controller_timeout_s, controller_start_s, entry->items.array[global->setting->failsafe_item_id].name, suffix); } else if (entry_action->code == controller_entry_timeout_code_stop_d) { entry->timeout_stop = entry_action->number; - controller_entry_preprocess_print_simulate_setting_value(global, is_entry, controller_timeout_s, controller_stop_s, entry->items.array[global.setting->failsafe_item_id].name, suffix); + controller_entry_preprocess_print_simulate_setting_value(*global, is_entry, controller_timeout_s, controller_stop_s, entry->items.array[global->setting->failsafe_item_id].name, suffix); } } else if (entry_action->type == controller_entry_action_type_failsafe_e) { if (failsafe) { - if (global.main->warning.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(global.main->warning.to, global.thread); + if (global->main->warning.verbosity == f_console_verbosity_debug_e) { + controller_lock_print(global->main->warning.to, global->thread); - fl_print_format("%c%[%SFailsafe may not be specified when running in failsafe, ignoring.%]%c", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix, global.main->warning.context, f_string_eol_s[0]); + fl_print_format("%c%[%SFailsafe may not be specified when running in failsafe, ignoring.%]%c", global->main->warning.to.stream, f_string_eol_s[0], global->main->warning.context, global->main->warning.prefix, global->main->warning.context, f_string_eol_s[0]); - controller_entry_print_error_cache(is_entry, global.main->warning, cache->action); + controller_entry_print_error_cache(is_entry, global->main->warning, cache->action); - controller_unlock_print_flush(global.main->warning.to, global.thread); + controller_unlock_print_flush(global->main->warning.to, global->thread); } } else { if (entry_action->number == 0 || entry_action->number >= entry->items.used) { // This should not happen if the pre-process is working as designed, but in case it doesn't, return a critical error to prevent infinite recursion and similar errors. - if (global.main->error.verbosity != f_console_verbosity_quiet_e) { - controller_lock_print(global.main->error.to, global.thread); + if (global->main->error.verbosity != f_console_verbosity_quiet_e) { + controller_lock_print(global->main->error.to, global->thread); - fl_print_format("%c%[%SInvalid %s item index '%]", global.main->error.to.stream, f_string_eol_s[0], global.main->error.context, global.main->error.prefix ? global.main->error.prefix : f_string_empty_s, is_entry ? controller_entry_s : controller_exit_s, global.main->error.context); - fl_print_format("%[%un%]", global.main->error.to.stream, global.main->error.notable, entry_action->number, global.main->error.notable); - fl_print_format("%[' detected.%]%c", global.main->error.to.stream, global.main->error.context, global.main->error.context, f_string_eol_s[0]); + fl_print_format("%c%[%SInvalid %s item index '%]", global->main->error.to.stream, f_string_eol_s[0], global->main->error.context, global->main->error.prefix ? global->main->error.prefix : f_string_empty_s, is_entry ? controller_entry_s : controller_exit_s, global->main->error.context); + fl_print_format("%[%un%]", global->main->error.to.stream, global->main->error.notable, entry_action->number, global->main->error.notable); + fl_print_format("%[' detected.%]%c", global->main->error.to.stream, global->main->error.context, global->main->error.context, f_string_eol_s[0]); - controller_entry_print_error_cache(is_entry, global.main->error, cache->action); + controller_entry_print_error_cache(is_entry, global->main->error, cache->action); - controller_unlock_print_flush(global.main->error.to, global.thread); + controller_unlock_print_flush(global->main->error.to, global->thread); } return F_status_is_error(F_critical); } else { - global.setting->failsafe_enabled = F_true; - global.setting->failsafe_item_id = entry_action->number; + global->setting->failsafe_enabled = F_true; + global->setting->failsafe_item_id = entry_action->number; - controller_entry_preprocess_print_simulate_setting_value(global, is_entry, controller_failsafe_s, 0, entry->items.array[global.setting->failsafe_item_id].name, 0); + controller_entry_preprocess_print_simulate_setting_value(*global, is_entry, controller_failsafe_s, 0, entry->items.array[global->setting->failsafe_item_id].name, 0); } } } @@ -1529,10 +1535,10 @@ extern "C" { } } - // end of actions found, so drop to previous loop in stack. + // End of actions found, so drop to previous loop in stack. if (cache->ats.array[at_j] == entry_actions->used) { - // all actions for "main" are processed so there is nothing left to do. + // All actions for "main" are processed so there is nothing left to do. if (at_i == 0) break; at_i -= 2; @@ -1547,14 +1553,14 @@ extern "C" { status = controller_dynamic_append_terminated(entry->items.array[cache->ats.array[at_i]].name, &cache->action.name_item); if (F_status_is_error(status)) { - controller_entry_print_error(is_entry, global.main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global.thread); + controller_entry_print_error(is_entry, global->main->error, cache->action, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global->thread); break; } } } // while - if (!controller_thread_is_enabled(is_entry, global.thread)) { + if (!controller_thread_is_enabled(is_entry, global->thread)) { return F_status_set_error(F_interrupt); } @@ -1566,9 +1572,9 @@ extern "C" { return status_lock; } - // check to see if any required processes failed, but do not do this if already operating in failsafe. - if (F_status_is_error_not(status) && !failsafe && global.main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { - const f_status_t status_wait = controller_rule_wait_all(global, is_entry, F_true, 0); + // Check to see if any required processes failed, but do not do this if already operating in failsafe. + if (F_status_is_error_not(status) && !failsafe && global->main->parameters[controller_parameter_validate_e].result == f_console_result_none_e) { + const f_status_t status_wait = controller_rule_wait_all(*global, is_entry, F_true, 0); if (F_status_is_error(status_wait)) { return status_wait; @@ -1579,19 +1585,19 @@ extern "C" { } } - if ((global.main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e && global.main->error.verbosity != f_console_verbosity_quiet_e) || global.main->error.verbosity == f_console_verbosity_verbose_e) { - controller_lock_print(global.main->output.to, global.thread); + if ((global->main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e && global->main->error.verbosity != f_console_verbosity_quiet_e) || global->main->error.verbosity == f_console_verbosity_verbose_e) { + controller_lock_print(global->main->output.to, global->thread); - fl_print_format("%cDone processing %s item '", global.main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); - fl_print_format("%[%s%]", global.main->output.to.stream, global.main->context.set.title, controller_main_s, global.main->context.set.title); - fl_print_format("'.%c", global.main->output.to.stream, f_string_eol_s[0]); + fl_print_format("%cDone processing %s item '", global->main->output.to.stream, f_string_eol_s[0], is_entry ? controller_entry_s : controller_exit_s); + fl_print_format("%[%s%]", global->main->output.to.stream, global->main->context.set.title, controller_main_s, global->main->context.set.title); + fl_print_format("'.%c", global->main->output.to.stream, f_string_eol_s[0]); // failsafe should not print the extra newline because the failure exit from controller_main should handle this. if (!failsafe) { - f_print_terminated(f_string_eol_s, global.main->output.to.stream); + f_print_terminated(f_string_eol_s, global->main->output.to.stream); } - controller_unlock_print_flush(global.main->output.to, global.thread); + controller_unlock_print_flush(global->main->output.to, global->thread); } return status; @@ -1670,7 +1676,7 @@ extern "C" { status = fll_fss_basic_list_read(cache->buffer_file, state, &range, &cache->object_items, &cache->content_items, &cache->delimits, 0, &cache->comments); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fll_fss_basic_list_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fll_fss_basic_list_read", F_true); } else { status = fl_fss_apply_delimit(cache->delimits, &cache->buffer_file); @@ -1813,7 +1819,7 @@ extern "C" { status = controller_dynamic_append_terminated(cache->action.name_item, &entry->items.array[at].name); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true); break; } @@ -1901,7 +1907,8 @@ extern "C" { status = controller_dynamic_append_terminated(entry->items.array[i].name, &cache->action.name_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true); + break; } @@ -2012,7 +2019,6 @@ extern "C" { continue; } - // @todo swap the generic with the path_control so that this can then be swapped again using canonical. cache->action.generic.used = 0; global.setting->path_control.used = 0; diff --git a/level_3/controller/c/private-entry.h b/level_3/controller/c/private-entry.h index 40c701c..f457ba5 100644 --- a/level_3/controller/c/private-entry.h +++ b/level_3/controller/c/private-entry.h @@ -130,14 +130,14 @@ extern "C" { * * @param global * The global data. + * @param cache + * The main/global cache to use. * @param failsafe * If TRUE, operate in failsafe mode (starts at designated failsafe Item). * If FALSE, operate in normal mode (starts at "main" Item). * @param is_entry * If TRUE, then this operate as an entry. * If FALSE, then this operate as an exit. - * @param cache - * The main/global cache to use. * * @return * F_none on success. @@ -156,7 +156,7 @@ extern "C" { * @see controller_dynamic_append_terminated() */ #ifndef _di_controller_entry_process_ - extern f_status_t controller_entry_process(const controller_global_t global, const bool failsafe, const bool is_entry, controller_cache_t * const cache) F_attribute_visibility_internal_d; + extern f_status_t controller_entry_process(const controller_global_t *global, controller_cache_t * const cache, const bool failsafe, const bool is_entry) F_attribute_visibility_internal_d; #endif // _di_controller_entry_process_ /** diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index 4037eed..19caf0e 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -69,7 +69,7 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, parameters); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); return status; } @@ -79,7 +79,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(buffer, *object, ¶meters->array[0]); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true); return status; } @@ -87,7 +87,7 @@ extern "C" { status = f_string_dynamic_terminate_after(¶meters->array[0]); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); return status; } @@ -104,7 +104,7 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, parameters); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); return status; } @@ -114,7 +114,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(buffer, content->array[i], ¶meters->array[parameters->used]); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true); return status; } @@ -122,7 +122,7 @@ extern "C" { status = f_string_dynamic_terminate_after(¶meters->array[parameters->used]); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); return status; } @@ -343,13 +343,13 @@ extern "C" { } if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_extended_list_content_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_extended_list_content_read", F_true); } else if (status == F_fss_found_content) { status = fl_fss_apply_delimit(cache->delimits, &cache->buffer_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true); } else { @@ -360,7 +360,7 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, &actions->array[actions->used].parameters); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); } else { actions->array[actions->used].type = type; @@ -371,13 +371,13 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_action.array[0], &actions->array[actions->used].parameters.array[0]); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_append_nulless", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_append_nulless", F_true); } status = f_string_dynamic_terminate_after(&actions->array[actions->used].parameters.array[0]); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); } else { actions->array[actions->used++].parameters.used = 1; @@ -398,13 +398,13 @@ extern "C" { } if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fll_fss_extended_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fll_fss_extended_read", F_true); } else { status = fl_fss_apply_delimit(cache->delimits, &cache->buffer_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true); } else { f_array_length_t i = 0; @@ -414,7 +414,7 @@ extern "C" { status = controller_rule_actions_increase_by(controller_common_allocation_small_d, actions); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_rule_actions_increase_by", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_actions_increase_by", F_true); break; } @@ -422,7 +422,8 @@ extern "C" { status = f_fss_count_lines(cache->buffer_item, cache->object_actions.array[i].start, &actions->array[actions->used].line); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true); + break; } @@ -434,9 +435,10 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, &actions->array[actions->used].parameters); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); actions->array[actions->used].status = controller_status_simplify_error(F_status_set_fine(status)); + break; } @@ -466,13 +468,13 @@ extern "C" { } if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fll_fss_extended_content_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fll_fss_extended_content_read", F_true); } else if (status == F_fss_found_content) { status = fl_fss_apply_delimit(cache->delimits, &cache->buffer_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true); } else if (type == controller_rule_action_type_pid_file_e) { item->pid_file.used = 0; @@ -480,13 +482,13 @@ extern "C" { status = fl_string_dynamic_rip(cache->buffer_item, cache->content_action.array[0], &item->pid_file); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_string_dynamic_rip", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_string_dynamic_rip", F_true); } else { status = f_string_dynamic_terminate_after(&item->pid_file); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); } } } @@ -660,7 +662,7 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, &actions->array[actions->used].parameters); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); } else { @@ -677,13 +679,13 @@ extern "C" { } // for if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_mash_nulless", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_mash_nulless", F_true); } else { status = f_string_dynamic_terminate_after(&actions->array[actions->used].parameters.array[0]); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); } else { actions->array[actions->used++].parameters.used = 1; @@ -695,7 +697,7 @@ extern "C" { status = f_fss_count_lines(cache->buffer_item, range->start, &actions->array[actions->used].line); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true); } else { actions->array[actions->used].type = type; @@ -706,7 +708,7 @@ extern "C" { status = controller_rule_parameters_read(global, cache->buffer_item, 0, &cache->content_action, &actions->array[actions->used].parameters); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_rule_parameters_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_parameters_read", F_true); actions->array[actions->used++].status = controller_status_simplify_error(F_status_set_fine(status)); } @@ -738,7 +740,7 @@ extern "C" { #endif // _di_controller_rule_action_read_ #ifndef _di_controller_rule_action_read_rerun_number_ - f_status_t controller_rule_action_read_rerun_number(const controller_global_t global, const f_string_t name, controller_cache_t * const cache, f_array_length_t *index, f_number_unsigned_t *number) { + f_status_t controller_rule_action_read_rerun_number(const controller_global_t global, const f_string_t name, controller_cache_t * const cache, f_array_length_t * const index, f_number_unsigned_t * const number) { f_status_t status = F_none; f_number_unsigned_t parsed = 0; @@ -763,7 +765,7 @@ extern "C" { status = F_status_set_fine(status); if (status != F_valid_not && status != F_number && status != F_number_decimal && status != F_number_overflow && status != F_number_underflow && status != F_number_negative) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); } else { controller_lock_print(global.main->error.to, global.thread); @@ -1058,7 +1060,7 @@ extern "C" { status = fll_control_group_prepare(process->rule.cgroup); if (F_status_is_error(status)) { - controller_print_error_file(global.main->error, F_status_set_fine(status), "fll_control_group_prepare", F_true, process->rule.cgroup.path.string, "prepare control groups for", fll_error_file_type_directory_e, global.thread); + controller_print_error_file(global.thread, global.main->error, F_status_set_fine(status), "fll_control_group_prepare", F_true, process->rule.cgroup.path.string, "prepare control groups for", fll_error_file_type_directory_e); return status; } @@ -1092,7 +1094,7 @@ extern "C" { status = fl_environment_load_names(process->rule.environment, &environment); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_environment_load_names", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_environment_load_names", F_true); return status; } @@ -1327,7 +1329,7 @@ extern "C" { status = controller_pids_increase(&process->childs); if (F_status_is_error(status)) { - controller_print_error(main->error, F_status_set_fine(status), "controller_pids_increase", F_true, thread); + controller_print_error(thread, main->error, F_status_set_fine(status), "controller_pids_increase", F_true); return status; } @@ -1519,7 +1521,7 @@ extern "C" { controller_rule_item_print_error_execute(type == controller_rule_item_type_script_e, program ? program : arguments.used ? arguments.array[0].string : f_string_empty_s, status, process); } else { - controller_print_error(main->error, F_status_set_fine(status), "fll_execute_program", F_true, thread); + controller_print_error(thread, main->error, F_status_set_fine(status), "fll_execute_program", F_true); } status = F_status_set_error(status); @@ -1543,7 +1545,7 @@ extern "C" { status = controller_pids_increase(&process->childs); if (F_status_is_error(status)) { - controller_print_error(main->error, F_status_set_fine(status), "controller_pids_increase", F_true, thread); + controller_print_error(thread, main->error, F_status_set_fine(status), "controller_pids_increase", F_true); return status; } @@ -1551,7 +1553,7 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, &process->path_pids); if (F_status_is_error(status)) { - controller_print_error(main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true, thread); + controller_print_error(thread, main->error, F_status_set_fine(status), "f_string_dynamics_increase", F_true); return status; } @@ -1586,13 +1588,13 @@ extern "C" { status = f_file_exists(pid_file.string); if (F_status_is_error(status)) { - controller_print_error_file(main->error, F_status_set_fine(status), "f_file_exists", F_true, pid_file.string, "find", fll_error_file_type_file_e, thread); + controller_print_error_file(thread, main->error, F_status_set_fine(status), "f_file_exists", F_true, pid_file.string, "find", fll_error_file_type_file_e); return status; } if (status == F_true) { - controller_print_error_file(main->error, F_file_found, "f_file_exists", F_true, pid_file.string, "find", fll_error_file_type_file_e, thread); + controller_print_error_file(thread, main->error, F_file_found, "f_file_exists", F_true, pid_file.string, "find", fll_error_file_type_file_e); return F_status_set_error(F_file_found); } @@ -1600,7 +1602,7 @@ extern "C" { status = controller_dynamic_append_terminated(pid_file, child_pid_file); if (F_status_is_error(status)) { - controller_print_error(main->error, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true, thread); + controller_print_error(thread, main->error, F_status_set_fine(status), "controller_dynamic_append_terminated", F_true); return status; } @@ -1775,7 +1777,7 @@ extern "C" { controller_rule_item_print_error_execute(type == controller_rule_item_type_utility_e, program ? program : arguments.used ? arguments.array[0].string : f_string_empty_s, status, process); } else { - controller_print_error(main->error, F_status_set_fine(status), "fll_execute_program", F_true, thread); + controller_print_error(thread, main->error, F_status_set_fine(status), "fll_execute_program", F_true); } return F_status_set_error(status); @@ -1786,7 +1788,7 @@ extern "C" { #endif // _di_controller_rule_execute_pid_with_ #ifndef _di_controller_rule_execute_rerun_ - int8_t controller_rule_execute_rerun(const uint8_t action, controller_process_t * const process, controller_rule_item_t *item) { + int8_t controller_rule_execute_rerun(const uint8_t action, controller_process_t * const process, controller_rule_item_t * const item) { const int result = WIFEXITED(process->result) ? WEXITSTATUS(process->result) : 0; @@ -1857,7 +1859,7 @@ extern "C" { #endif // _di_controller_rule_execute_rerun_ #ifndef _di_controller_rule_id_construct_ - f_status_t controller_rule_id_construct(const controller_global_t global, const f_string_static_t source, const f_string_range_t directory, const f_string_range_t basename, f_string_dynamic_t *alias) { + f_status_t controller_rule_id_construct(const controller_global_t global, const f_string_static_t source, const f_string_range_t directory, const f_string_range_t basename, f_string_dynamic_t * const alias) { f_status_t status = F_none; @@ -1866,7 +1868,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(source, directory, alias); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true); return status; } @@ -1874,7 +1876,7 @@ extern "C" { status = f_string_append(f_path_separator_s, F_path_separator_s_length, alias); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_append", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_append", F_true); return status; } @@ -1882,7 +1884,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(source, basename, alias); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true); return status; } @@ -1890,7 +1892,7 @@ extern "C" { status = f_string_dynamic_terminate_after(alias); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); } return status; @@ -1912,7 +1914,7 @@ extern "C" { #endif // _di_controller_rule_status_is_error_ #ifndef _di_controller_rule_item_read_ - f_status_t controller_rule_item_read(const controller_global_t global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t *item) { + f_status_t controller_rule_item_read(const controller_global_t global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t * const item) { f_status_t status = F_none; controller_state_interrupt_t custom = macro_controller_state_interrupt_t_initialize(is_normal, global.thread); @@ -1931,7 +1933,7 @@ extern "C" { status = fl_fss_extended_list_object_read(cache->buffer_item, state, &range, &cache->range_action, &cache->delimits); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_extended_list_object_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_extended_list_object_read", F_true); break; } @@ -1948,7 +1950,7 @@ extern "C" { status = fl_fss_extended_object_read(cache->buffer_item, state, &range, &cache->range_action, 0, &cache->delimits); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_extended_object_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_extended_object_read", F_true); break; } @@ -1961,14 +1963,16 @@ extern "C" { status = fl_fss_apply_delimit(cache->delimits, &cache->buffer_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true); + break; } status = f_fss_count_lines(cache->buffer_item, cache->range_action.start, &cache->action.line_action); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true); + break; } @@ -1978,7 +1982,8 @@ extern "C" { status = controller_dynamic_rip_nulless_terminated(cache->buffer_item, cache->range_action, &cache->action.name_action); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_dynamic_rip_nulless_terminated", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_dynamic_rip_nulless_terminated", F_true); + break; } @@ -2066,7 +2071,8 @@ extern "C" { status = controller_rule_actions_increase_by(controller_common_allocation_small_d, &item->actions); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_rule_actions_increase_by", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_actions_increase_by", F_true); + break; } @@ -2117,7 +2123,7 @@ extern "C" { #endif // _di_controller_rule_item_type_name_ #ifndef _di_controller_rule_items_increase_by_ - f_status_t controller_rule_items_increase_by(const f_array_length_t amount, controller_rule_items_t *items) { + f_status_t controller_rule_items_increase_by(const f_array_length_t amount, controller_rule_items_t * const items) { if (items->used + amount > items->size) { if (items->used + amount > F_array_length_t_size_d) { @@ -2275,7 +2281,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, process->cache.action, F_status_set_fine(status), "f_string_append", F_true, F_true, global.thread); + controller_rule_print_error(global.thread, global.main->error, process->cache.action, F_status_set_fine(status), "f_string_append", F_true, F_true); return status; } @@ -2283,7 +2289,7 @@ extern "C" { status = f_string_dynamic_append(process->rule.alias, &process->cache.action.name_file); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, process->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true, global.thread); + controller_rule_print_error(global.thread, global.main->error, process->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true); return status; } @@ -2295,7 +2301,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, process->cache.action, F_status_set_fine(status), "f_string_append", F_true, F_true, global.thread); + controller_rule_print_error(global.thread, global.main->error, process->cache.action, F_status_set_fine(status), "f_string_append", F_true, F_true); return status; } @@ -2303,7 +2309,7 @@ extern "C" { status = f_string_dynamic_terminate_after(&process->cache.action.name_file); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, process->cache.action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_true, global.thread); + controller_rule_print_error(global.thread, global.main->error, process->cache.action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_true); return status; } @@ -2715,7 +2721,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_rule_item_print_error(global.main->error, process->cache.action, F_true, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, process->cache.action, F_true, F_status_set_fine(status)); } } } @@ -2847,7 +2853,7 @@ extern "C" { if (F_status_is_error(status)) { controller_lock_print_error_critical(global.main->error, F_status_set_fine(status), F_true, global.thread); - controller_rule_item_print_error(global.main->error, cache.action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache.action, F_false, F_status_set_fine(status)); f_thread_unlock(&global.thread->lock.process); @@ -2939,7 +2945,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_type_array_lengths_resize", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_type_array_lengths_resize", F_true); } else { for (f_array_length_t i = 0; i < stack.used; ++i) { @@ -2961,7 +2967,7 @@ extern "C" { status = f_string_dynamic_append(cache.action.name_item, &process->cache.action.name_item); } else { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_append", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_append", F_true); } } @@ -2977,7 +2983,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_thread_create", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_thread_create", F_true); } } else { @@ -3118,7 +3124,7 @@ extern "C" { f_thread_unlock(&global.thread->lock.rule); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_rule_copy", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_copy", F_true); } else if (!process->action) { @@ -3168,7 +3174,7 @@ extern "C" { status = f_type_array_lengths_increase(controller_common_allocation_small_d, &process->stack); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_type_array_lengths_increase", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_type_array_lengths_increase", F_true); } else { f_thread_unlock(&process->lock); @@ -3399,13 +3405,13 @@ extern "C" { status = f_string_dynamic_append_nulless(alias, &rule->alias); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_append_nulless", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_append_nulless", F_true); } else { status = f_string_dynamic_terminate_after(&rule->alias); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); } else { status = controller_file_load(global, F_true, controller_rules_s, rule->alias, controller_rule_s, controller_rules_s_length, controller_rule_s_length, cache); @@ -3423,13 +3429,13 @@ extern "C" { status = fll_fss_basic_list_read(cache->buffer_file, state, &range, &cache->object_items, &cache->content_items, &cache->delimits, 0, &cache->comments); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fll_fss_basic_list_read", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fll_fss_basic_list_read", F_true); } else { status = fl_fss_apply_delimit(cache->delimits, &cache->buffer_file); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "fl_fss_apply_delimit", F_true); } } } @@ -3439,7 +3445,7 @@ extern "C" { status = controller_rule_items_increase_by(cache->object_items.used, &rule->items); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_rule_items_increase_by", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_rule_items_increase_by", F_true); } else { f_array_length_t i = 0; @@ -3476,7 +3482,8 @@ extern "C" { status = f_fss_count_lines(cache->buffer_file, cache->object_items.array[i].start, &cache->action.line_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_fss_count_lines", F_true); + break; } @@ -3485,7 +3492,8 @@ extern "C" { status = controller_dynamic_rip_nulless_terminated(cache->buffer_file, cache->object_items.array[i], &cache->action.name_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_dynamic_rip_nulless_terminated", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_dynamic_rip_nulless_terminated", F_true); + break; } @@ -3523,14 +3531,16 @@ extern "C" { status = f_string_dynamic_partial_append(cache->buffer_file, cache->content_items.array[i].array[0], &cache->buffer_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_partial_append", F_true); + break; } status = f_string_dynamic_terminate_after(&cache->buffer_item); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); + break; } @@ -3567,7 +3577,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_rule_item_print_error(global.main->error, cache->action, for_item, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, for_item, F_status_set_fine(status)); rule->status[0] = controller_status_simplify_error(F_status_set_fine(status)); @@ -3595,7 +3605,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "fll_fss_extended_read", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "fll_fss_extended_read", F_true, F_false); return status; } @@ -3631,13 +3641,13 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->object_actions.array[i], &cache->action.name_item); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); } else { status = f_string_dynamic_terminate_after(&cache->action.name_item); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false); } } @@ -3657,7 +3667,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -3743,13 +3753,13 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, range2, &cache->action.name_action); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); } else { status = f_string_dynamic_terminate_after(&cache->action.name_action); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false); } } @@ -3761,7 +3771,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -3836,7 +3846,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "macro_f_int32s_t_resize", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "macro_f_int32s_t_resize", F_true, F_false); break; } @@ -3872,7 +3882,7 @@ extern "C" { } } else { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "fl_conversion_string_to_number_signed", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "fl_conversion_string_to_number_signed", F_true, F_false); status = F_status_set_error(status); @@ -3913,7 +3923,7 @@ extern "C" { status = f_string_maps_increase(controller_common_allocation_small_d, setting_maps); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_maps_increase", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_maps_increase", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -3930,7 +3940,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -3941,7 +3951,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[0], &setting_maps->array[setting_maps->used].name); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -3958,7 +3968,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -3966,19 +3976,20 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[1], &setting_maps->array[setting_maps->used].value); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); } else { status = f_string_dynamic_terminate_after(&setting_maps->array[setting_maps->used].value); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false); } } if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_memory_not) { status_return = status; + break; } @@ -3992,7 +4003,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -4036,7 +4047,7 @@ extern "C" { status = f_string_dynamic_append(global.setting->path_cgroup, &rule->cgroup.path); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_false); } else { rule->cgroup.groups.used = 0; @@ -4046,7 +4057,7 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, &rule->cgroup.groups); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamics_increase", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamics_increase", F_true, F_false); break; } @@ -4055,7 +4066,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[j], &rule->cgroup.groups.array[rule->cgroup.groups.used]); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); break; } @@ -4081,7 +4092,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -4212,7 +4223,7 @@ extern "C" { macro_f_limit_sets_t_increase(status, controller_common_allocation_small_d, rule->limits); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_limit_sets_increase", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_limit_sets_increase", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -4229,7 +4240,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -4270,7 +4281,7 @@ extern "C" { } } else { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "fl_conversion_string_to_number_signed", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "fl_conversion_string_to_number_signed", F_true, F_false); status = F_status_set_error(status); @@ -4342,7 +4353,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -4379,13 +4390,13 @@ extern "C" { else { // this function should only return F_complete_not_utf on error. - controller_rule_print_error(global.main->error, cache->action, F_complete_not_utf, "controller_validate_has_graph", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_complete_not_utf, "controller_validate_has_graph", F_true, F_false); if (F_status_is_error_not(status_return)) { status_return = status; } - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); } setting_value->used = 0; @@ -4399,13 +4410,13 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[0], setting_value); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); } else { status = f_string_dynamic_terminate_after(setting_value); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false); } } @@ -4427,7 +4438,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -4539,7 +4550,7 @@ extern "C" { } } else { - controller_rule_print_error(global.main->error, cache->action, status, "fl_conversion_string_to_number_signed", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, status, "fl_conversion_string_to_number_signed", F_true, F_false); status = F_status_set_error(status); if (F_status_is_error_not(status_return)) { @@ -4639,7 +4650,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_print_error(global.main->error, cache->action, status, "fl_conversion_string_to_number_signed", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, status, "fl_conversion_string_to_number_signed", F_true, F_false); } if (F_status_is_error_not(status_return)) { @@ -4672,7 +4683,8 @@ extern "C" { status = controller_dynamic_rip_nulless_terminated(cache->buffer_item, cache->content_actions.array[i].array[1], &cache->action.generic); if (F_status_is_error(status)) { - controller_print_error(global.main->error, F_status_set_fine(status), "controller_dynamic_rip_nulless_terminated", F_true, global.thread); + controller_print_error(global.thread, global.main->error, F_status_set_fine(status), "controller_dynamic_rip_nulless_terminated", F_true); + break; } @@ -4709,7 +4721,7 @@ extern "C" { controller_lock_print(global.main->error.to, global.thread); - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); controller_rule_print_error_cache(global.main->error, cache->action, F_false); @@ -4737,7 +4749,7 @@ extern "C" { controller_lock_print(global.main->error.to, global.thread); - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false); controller_rule_print_error_cache(global.main->error, cache->action, F_false); @@ -4766,7 +4778,7 @@ extern "C" { controller_lock_print(global.main->error.to, global.thread); - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_capability_from_text", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_capability_from_text", F_true, F_false); controller_rule_print_error_cache(global.main->error, cache->action, F_false); @@ -4833,7 +4845,7 @@ extern "C" { } } else { - controller_rule_print_error(global.main->error, cache->action, status, "fl_conversion_string_to_number_signed", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, status, "fl_conversion_string_to_number_signed", F_true, F_false); status = F_status_set_error(status); if (F_status_is_error_not(status_return)) { @@ -4864,7 +4876,7 @@ extern "C" { controller_lock_print(global.main->error.to, global.thread); - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), cache->action.generic.used ? "f_string_dynamic_partial_append_nulless" : "f_string_dynamic_terminate_after", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), cache->action.generic.used ? "f_string_dynamic_partial_append_nulless" : "f_string_dynamic_terminate_after", F_true, F_false); controller_rule_print_error_cache(global.main->error, cache->action, F_false); @@ -4911,9 +4923,9 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_print_error(global.main->error, cache->action, status, "controller_get_id_user", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, status, "controller_get_id_user", F_true, F_false); - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); } if (F_status_is_error_not(status_return)) { @@ -4961,7 +4973,7 @@ extern "C" { macro_f_int32s_t_increase_by(status, rule->groups, controller_common_allocation_small_d) if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "macro_f_array_lengths_t_increase_by", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "macro_f_array_lengths_t_increase_by", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -4978,7 +4990,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -5005,9 +5017,9 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_print_error(global.main->error, cache->action, status, "f_account_id_group_by_name", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, status, "f_account_id_group_by_name", F_true, F_false); - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); } if (F_status_is_error_not(status_return)) { @@ -5038,7 +5050,7 @@ extern "C" { status = f_string_dynamics_increase(controller_common_allocation_small_d, setting_values); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamics_increase", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamics_increase", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -5055,7 +5067,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -5065,13 +5077,13 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[j], &setting_values->array[setting_values->used]); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); } else { status = f_string_dynamic_terminate_after(&setting_values->array[setting_values->used]); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true, F_false); } } @@ -5093,7 +5105,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -5128,7 +5140,7 @@ extern "C" { else { // This function should only return F_complete_not_utf on error. - controller_rule_print_error(global.main->error, cache->action, F_complete_not_utf, "controller_validate_environment_name", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_complete_not_utf, "controller_validate_environment_name", F_true, F_false); if (F_status_is_error_not(status_return)) { status_return = status; @@ -5137,7 +5149,7 @@ extern "C" { setting_values->array[setting_values->used].used = 0; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -5240,7 +5252,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "controller_rule_ons_increase", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "controller_rule_ons_increase", F_true, F_false); } else { if (fl_string_dynamic_partial_compare_string(controller_need_s, cache->buffer_item, controller_need_s_length, cache->content_actions.array[i].array[1]) == F_equal_to) { @@ -5282,7 +5294,7 @@ extern "C" { status = f_string_dynamics_increase_by(controller_common_allocation_small_d, setting_values); if (F_status_is_error(status)) { - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamics_increase_by", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_string_dynamics_increase_by", F_true, F_false); } } @@ -5302,7 +5314,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -5327,7 +5339,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_rule_item_print_error(global.main->error, cache->action, F_false, F_status_set_fine(status), global.thread); + controller_rule_item_print_error(global.thread, global.main->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -5339,7 +5351,7 @@ extern "C" { if (F_status_is_error(status)) { setting_values->array[setting_values->used].used = 0; - controller_rule_print_error(global.main->error, cache->action, F_status_set_fine(status), "f_file_name_base", F_true, F_false, global.thread); + controller_rule_print_error(global.thread, global.main->error, cache->action, F_status_set_fine(status), "f_file_name_base", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; diff --git a/level_3/controller/c/private-rule.h b/level_3/controller/c/private-rule.h index 379d552..a5f19a9 100644 --- a/level_3/controller/c/private-rule.h +++ b/level_3/controller/c/private-rule.h @@ -332,7 +332,7 @@ extern "C" { * -2 to designate exit due to signal/disabled thread. */ #ifndef _di_controller_rule_execute_rerun_ - extern int8_t controller_rule_execute_rerun(const uint8_t action, controller_process_t * const process, controller_rule_item_t *item) F_attribute_visibility_internal_d; + extern int8_t controller_rule_execute_rerun(const uint8_t action, controller_process_t * const process, controller_rule_item_t * const item) F_attribute_visibility_internal_d; #endif // _di_controller_rule_execute_rerun_ /** @@ -360,7 +360,7 @@ extern "C" { * @see f_string_dynamic_terminate_after() */ #ifndef _di_controller_rule_id_construct_ - extern f_status_t controller_rule_id_construct(const controller_global_t global, const f_string_static_t source, const f_string_range_t directory, const f_string_range_t basename, f_string_dynamic_t *alias) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_id_construct(const controller_global_t global, const f_string_static_t source, const f_string_range_t directory, const f_string_range_t basename, f_string_dynamic_t * const alias) F_attribute_visibility_internal_d; #endif // _di_controller_rule_id_construct_ /** @@ -428,7 +428,7 @@ extern "C" { * @see f_string_dynamic_terminate_after() */ #ifndef _di_controller_rule_item_read_ - extern f_status_t controller_rule_item_read(const controller_global_t global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t *item) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_item_read(const controller_global_t global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t * const item) F_attribute_visibility_internal_d; #endif // _di_controller_rule_item_read_ /** @@ -464,7 +464,7 @@ extern "C" { * @see f_memory_resize() */ #ifndef _di_controller_rule_items_increase_by_ - extern f_status_t controller_rule_items_increase_by(const f_array_length_t amount, controller_rule_items_t *items) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_items_increase_by(const f_array_length_t amount, controller_rule_items_t * const items) F_attribute_visibility_internal_d; #endif // _di_controller_rule_items_increase_by_ /** @@ -661,7 +661,7 @@ extern "C" { * @see fl_conversion_string_to_number_signed() */ #ifndef _di_controller_rule_action_read_rerun_number_ - extern f_status_t controller_rule_action_read_rerun_number(const controller_global_t global, const f_string_t name, controller_cache_t * const cache, f_array_length_t *index, f_number_unsigned_t *number) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_action_read_rerun_number(const controller_global_t global, const f_string_t name, controller_cache_t * const cache, f_array_length_t * const index, f_number_unsigned_t * const number) F_attribute_visibility_internal_d; #endif // _di_controller_rule_action_read_rerun_number_ /** @@ -704,7 +704,7 @@ extern "C" { * @see fll_path_canonical() */ #ifndef _di_controller_rule_setting_read_ - extern f_status_t controller_rule_setting_read(const controller_global_t global, const bool is_normal, const controller_setting_t setting, controller_cache_t *const cache, controller_rule_t * const rule) F_attribute_visibility_internal_d; + extern f_status_t controller_rule_setting_read(const controller_global_t global, const bool is_normal, const controller_setting_t setting, controller_cache_t * const cache, controller_rule_t * const rule) F_attribute_visibility_internal_d; #endif // _di_controller_rule_setting_read_ /** diff --git a/level_3/controller/c/private-rule_print.c b/level_3/controller/c/private-rule_print.c index 2155a64..5d491ef 100644 --- a/level_3/controller/c/private-rule_print.c +++ b/level_3/controller/c/private-rule_print.c @@ -8,7 +8,7 @@ extern "C" { #endif #ifndef _di_controller_rule_print_error_ - void controller_rule_print_error(const fl_print_t print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item, controller_thread_t *thread) { + void controller_rule_print_error(controller_thread_t * const thread, const fl_print_t print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item) { if (print.verbosity == f_console_verbosity_quiet_e) return; if (status == F_interrupt) return; @@ -58,7 +58,7 @@ extern "C" { #endif // _di_controller_rule_print_error_cache_ #ifndef _di_controller_rule_item_print_error_ - void controller_rule_item_print_error(const fl_print_t print, const controller_cache_action_t cache, const bool item, const f_status_t status, controller_thread_t *thread) { + void controller_rule_item_print_error(controller_thread_t * const thread, const fl_print_t print, const controller_cache_action_t cache, const bool item, const f_status_t status) { if (print.verbosity == f_console_verbosity_quiet_e) return; if (status == F_interrupt) return; diff --git a/level_3/controller/c/private-rule_print.h b/level_3/controller/c/private-rule_print.h index 6922772..144642a 100644 --- a/level_3/controller/c/private-rule_print.h +++ b/level_3/controller/c/private-rule_print.h @@ -17,6 +17,8 @@ extern "C" { * * This is essentially a wrapper to fll_error_print() that includes locking. * + * @param thread + * The thread data. * @param print * Designates how printing is to be performed. * @param cache @@ -29,8 +31,6 @@ extern "C" { * Set to 0 to disable. * @param fallback * Set to F_true to print the fallback error message for unknown errors. - * @param thread - * The thread data. * @param item * If TRUE, then this error is associated with an item. * If FALSE, then this error is associated with a rule setting. @@ -39,7 +39,7 @@ extern "C" { * @see controller_rule_print_error_cache() */ #ifndef _di_controller_rule_print_error_ - extern void controller_rule_print_error(const fl_print_t print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item, controller_thread_t *thread) F_attribute_visibility_internal_d; + extern void controller_rule_print_error(controller_thread_t * const thread, const fl_print_t print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item) F_attribute_visibility_internal_d; #endif // _di_controller_rule_print_error_ /** @@ -72,6 +72,8 @@ extern "C" { * * This is explicitly intended to be used in addition to the error message. * + * @param thread + * The thread data. * @param print * The error or warning print structure. * @param cache @@ -81,13 +83,11 @@ extern "C" { * If FALSE, then this error is associated with a rule setting. * @param status * The status code representing the failure (without the error bit set). - * @param thread - * The thread data. * * @see controller_rule_print_error_cache() */ #ifndef _di_controller_rule_item_print_error_ - extern void controller_rule_item_print_error(const fl_print_t print, const controller_cache_action_t cache, const bool item, const f_status_t status, controller_thread_t *thread) F_attribute_visibility_internal_d; + extern void controller_rule_item_print_error(controller_thread_t * const thread, const fl_print_t print, const controller_cache_action_t cache, const bool item, const f_status_t status) F_attribute_visibility_internal_d; #endif // _di_controller_rule_item_print_error_ /** diff --git a/level_3/controller/c/private-thread.c b/level_3/controller/c/private-thread.c index 0c95307..15110fb 100644 --- a/level_3/controller/c/private-thread.c +++ b/level_3/controller/c/private-thread.c @@ -17,7 +17,7 @@ extern "C" { #endif #ifndef _di_controller_thread_cleanup_ - void * controller_thread_cleanup(void *arguments) { + void * controller_thread_cleanup(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); @@ -31,7 +31,7 @@ extern "C" { while (global->thread->enabled == controller_thread_enabled_e) { - controller_time_sleep_nanoseconds(global->main, global->setting, delay); + nanosleep(&delay, 0); if (global->thread->enabled != controller_thread_enabled_e) break; @@ -155,7 +155,7 @@ extern "C" { #endif // _di_controller_thread_cleanup_ #ifndef _di_controller_thread_is_enabled_ - f_status_t controller_thread_is_enabled(const bool is_normal, controller_thread_t *thread) { + f_status_t controller_thread_is_enabled(const bool is_normal, controller_thread_t * const thread) { if (is_normal) { return thread->enabled == controller_thread_enabled_e; @@ -166,21 +166,21 @@ extern "C" { #endif // _di_controller_thread_is_enabled_ #ifndef _di_controller_thread_is_enabled_process_ - f_status_t controller_thread_is_enabled_process(controller_process_t * const process, controller_thread_t *thread) { + f_status_t controller_thread_is_enabled_process(controller_process_t * const process, controller_thread_t * const thread) { return controller_thread_is_enabled_process_type(process->type, thread); } #endif // _di_controller_thread_is_enabled_process_ #ifndef _di_controller_thread_is_enabled_process_type_ - f_status_t controller_thread_is_enabled_process_type(const uint8_t type, controller_thread_t *thread) { + f_status_t controller_thread_is_enabled_process_type(const uint8_t type, controller_thread_t * const thread) { return controller_thread_is_enabled(type != controller_process_type_exit_e, thread); } #endif // _di_controller_thread_is_enabled_process_type_ #ifndef _di_controller_thread_main_ - f_status_t controller_thread_main(controller_main_t *main, controller_setting_t *setting) { + f_status_t controller_thread_main(controller_main_t * const main, controller_setting_t * const setting) { f_status_t status = F_none; @@ -199,7 +199,7 @@ extern "C" { status = controller_processs_increase(&thread.processs); if (F_status_is_error(status)) { - controller_print_error(main->error, F_status_set_fine(status), "controller_processs_increase", F_true, &thread); + controller_print_error(&thread, main->error, F_status_set_fine(status), "controller_processs_increase", F_true); } } @@ -211,7 +211,7 @@ extern "C" { thread.id_signal = 0; if (main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error(main->error, F_status_set_fine(status), "f_thread_create", F_true, &thread); + controller_print_error(&thread, main->error, F_status_set_fine(status), "f_thread_create", F_true); } } else { @@ -240,7 +240,7 @@ extern "C" { if (F_status_is_error(status)) { if (main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error(main->error, F_status_set_fine(status), "f_thread_create", F_true, &thread); + controller_print_error(&thread, main->error, F_status_set_fine(status), "f_thread_create", F_true); } } else { @@ -266,13 +266,6 @@ extern "C" { thread.id_rule = 0; } else { - status = f_thread_create(0, &thread.id_control, &controller_thread_control, (void *) &global); - } - - if (F_status_is_error(status)) { - thread.id_control = 0; - } - else { status = f_thread_create(0, &thread.id_cleanup, &controller_thread_cleanup, (void *) &global); } @@ -280,7 +273,7 @@ extern "C" { thread.id_cleanup = 0; if (main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error(main->error, F_status_set_fine(status), "f_thread_create", F_true, &thread); + controller_print_error(&thread, main->error, F_status_set_fine(status), "f_thread_create", F_true); } } } @@ -307,14 +300,21 @@ extern "C" { controller_thread_process_exit(&global); + if (thread.id_listen) { + f_thread_cancel(thread.id_listen); + } + if (thread.id_signal) f_thread_join(thread.id_signal, 0); if (thread.id_cleanup) f_thread_join(thread.id_cleanup, 0); if (thread.id_control) f_thread_join(thread.id_control, 0); + if (thread.id_listen) f_thread_join(thread.id_listen, 0); if (thread.id_entry) f_thread_join(thread.id_entry, 0); if (thread.id_rule) f_thread_join(thread.id_rule, 0); thread.id_cleanup = 0; thread.id_control = 0; + thread.id_listen = 0; + thread.id_entry = 0; thread.id_rule = 0; thread.id_signal = 0; @@ -339,7 +339,7 @@ extern "C" { #endif // _di_controller_thread_main_ #ifndef _di_controller_thread_join_ - f_status_t controller_thread_join(f_thread_id_t *id) { + f_status_t controller_thread_join(f_thread_id_t * const id) { if (!id || !*id) return F_data_not; diff --git a/level_3/controller/c/private-thread.h b/level_3/controller/c/private-thread.h index ff56595..cc63292 100644 --- a/level_3/controller/c/private-thread.h +++ b/level_3/controller/c/private-thread.h @@ -23,7 +23,7 @@ extern "C" { * 0, always. */ #ifndef _di_controller_thread_cleanup_ - extern void * controller_thread_cleanup(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_cleanup(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_cleanup_ /** @@ -40,7 +40,7 @@ extern "C" { * FALSE when disabled. */ #ifndef _di_controller_thread_is_enabled_ - extern f_status_t controller_thread_is_enabled(const bool is_normal, controller_thread_t *thread) F_attribute_visibility_internal_d; + extern f_status_t controller_thread_is_enabled(const bool is_normal, controller_thread_t * const thread) F_attribute_visibility_internal_d; #endif // _di_controller_thread_is_enabled_ /** @@ -58,7 +58,7 @@ extern "C" { * @see controller_thread_is_enabled_process_type() */ #ifndef _di_controller_thread_is_enabled_process_ - extern f_status_t controller_thread_is_enabled_process(controller_process_t * const process, controller_thread_t *thread) F_attribute_visibility_internal_d; + extern f_status_t controller_thread_is_enabled_process(controller_process_t * const process, controller_thread_t * const thread) F_attribute_visibility_internal_d; #endif // _di_controller_thread_is_enabled_process_ /** @@ -76,7 +76,7 @@ extern "C" { * @see controller_thread_is_enabled() */ #ifndef _di_controller_thread_is_enabled_process_type_ - extern f_status_t controller_thread_is_enabled_process_type(const uint8_t type, controller_thread_t *thread) F_attribute_visibility_internal_d; + extern f_status_t controller_thread_is_enabled_process_type(const uint8_t type, controller_thread_t * const thread) F_attribute_visibility_internal_d; #endif // _di_controller_thread_is_enabled_process_type_ /** @@ -95,7 +95,7 @@ extern "C" { * F_interrupt (with error bit) on receiving a process signal, such as an interrupt signal. */ #ifndef _di_controller_thread_main_ - extern f_status_t controller_thread_main(controller_main_t *main, controller_setting_t *setting) F_attribute_visibility_internal_d; + extern f_status_t controller_thread_main(controller_main_t * const main, controller_setting_t * const setting) F_attribute_visibility_internal_d; #endif // _di_controller_thread_main_ /*** @@ -116,7 +116,7 @@ extern "C" { * @see f_thread_join() */ #ifndef _di_controller_thread_join_ - extern f_status_t controller_thread_join(f_thread_id_t *id) F_attribute_visibility_internal_d; + extern f_status_t controller_thread_join(f_thread_id_t * const id) F_attribute_visibility_internal_d; #endif // _di_controller_thread_join_ #ifdef __cplusplus diff --git a/level_3/controller/c/private-thread_control.c b/level_3/controller/c/private-thread_control.c index a22cbc1..cb65183 100644 --- a/level_3/controller/c/private-thread_control.c +++ b/level_3/controller/c/private-thread_control.c @@ -1,5 +1,7 @@ #include "controller.h" #include "private-common.h" +#include "private-control.h" +#include "private-controller_print.h" #include "private-thread.h" #include "private-thread_control.h" @@ -8,18 +10,55 @@ extern "C" { #endif #ifndef _di_controller_thread_control_ - void * controller_thread_control(void *arguments) { + void * controller_thread_control(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_global_t *global = (controller_global_t *) arguments; + const controller_global_t *global = (controller_global_t *) arguments; if (global->thread->enabled != controller_thread_enabled_e) return 0; + f_status_t status = F_none; + f_socket_t * const server = &global->setting->control_socket; + controller_packet_t packet = controller_packet_t_initialize; + + controller_control_configure_server(global, server); + + do { + status = controller_control_accept(global, server, &packet); + } while (F_status_is_fine(status) && status != F_child && global->thread->enabled == controller_thread_enabled_e); + + controller_packet_delete_simple(&packet); + return 0; } #endif // _di_controller_thread_control_ +#ifndef _di_controller_thread_control_listen_ + void * controller_thread_control_listen(void * const arguments) { + + f_thread_cancel_state_set(PTHREAD_CANCEL_ASYNCHRONOUS, 0); + + const controller_global_t *global = (controller_global_t *) arguments; + + if (global->thread->enabled != controller_thread_enabled_e) return 0; + + if (global->setting->interruptible) { + f_signal_mask(SIG_UNBLOCK, &global->main->signal.set, 0); + } + + f_socket_t * const server = &global->setting->control_socket; + + const f_status_t status = f_socket_listen(server, controller_control_default_socket_backlog_d); + + if (F_status_is_error(status)) { + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_socket_listen", F_true); + } + + return 0; + } +#endif // _di_controller_thread_control_listen_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/controller/c/private-thread_control.h b/level_3/controller/c/private-thread_control.h index 5f0e225..b8f49d2 100644 --- a/level_3/controller/c/private-thread_control.h +++ b/level_3/controller/c/private-thread_control.h @@ -23,9 +23,26 @@ extern "C" { * 0, always. */ #ifndef _di_controller_thread_control_ - extern void * controller_thread_control(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_control(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_control_ +/** + * Thread for handling the control listener. + * + * This runs on a separate thread entirely to be interuptable and closable distinctly from the main control thread. + * This is simple and has nothing that needs to be cleaned up and so immediately exits on cancel. + * + * @param arguments + * The thread arguments. + * Must be of type controller_global_t. + * + * @return + * 0, always. + */ +#ifndef _di_controller_thread_control_listen_ + extern void * controller_thread_control_listen(void * const arguments) F_attribute_visibility_internal_d; +#endif // _di_controller_thread_control_listen_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/controller/c/private-thread_entry.c b/level_3/controller/c/private-thread_entry.c index e2a76a6..12fb524 100644 --- a/level_3/controller/c/private-thread_entry.c +++ b/level_3/controller/c/private-thread_entry.c @@ -11,7 +11,7 @@ extern "C" { #endif #ifndef _di_controller_thread_entry_ - void * controller_thread_entry(void *arguments) { + void * controller_thread_entry(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); @@ -53,7 +53,7 @@ extern "C" { *status = F_status_set_error(F_available_not); } else { - *status = controller_entry_process(*entry->global, F_false, F_true, cache); + *status = controller_entry_process(entry->global, cache, F_false, F_true); if (F_status_is_error(*status)) { entry->setting->ready = controller_setting_ready_fail_e; @@ -75,7 +75,7 @@ extern "C" { f_thread_create(0, &entry->global->thread->id_signal, &controller_thread_signal_normal, (void *) entry->global); } - const f_status_t status_failsafe = controller_entry_process(*entry->global, F_true, F_true, cache); + const f_status_t status_failsafe = controller_entry_process(entry->global, cache, F_true, F_true); if (F_status_is_error(status_failsafe)) { if (main->error.verbosity != f_console_verbosity_quiet_e) { @@ -137,7 +137,7 @@ extern "C" { #endif // _di_controller_thread_entry_ #ifndef _di_controller_thread_exit_ - void * controller_thread_exit(void *arguments) { + void * controller_thread_exit(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); @@ -165,7 +165,7 @@ extern "C" { if (F_status_is_error_not(*status) && *status != F_child && *status != F_file_found_not) { if (main->parameters[controller_parameter_validate_e].result == f_console_result_none_e || main->parameters[controller_parameter_simulate_e].result == f_console_result_found_e) { - *status = controller_entry_process(*entry->global, F_false, F_false, cache); + *status = controller_entry_process(entry->global, cache, F_false, F_false); if (F_status_is_error(*status)) { entry->setting->ready = controller_setting_ready_fail_e; @@ -190,7 +190,7 @@ extern "C" { } } - const f_status_t status_failsafe = controller_entry_process(*entry->global, F_true, F_false, cache); + const f_status_t status_failsafe = controller_entry_process(entry->global, cache, F_true, F_false); if (F_status_is_error(status_failsafe)) { if (main->error.verbosity != f_console_verbosity_quiet_e) { diff --git a/level_3/controller/c/private-thread_entry.h b/level_3/controller/c/private-thread_entry.h index bd9074f..553096e 100644 --- a/level_3/controller/c/private-thread_entry.h +++ b/level_3/controller/c/private-thread_entry.h @@ -26,7 +26,7 @@ extern "C" { * 0, always. */ #ifndef _di_controller_thread_entry_ - extern void * controller_thread_entry(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_entry(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_entry_ /** @@ -46,7 +46,7 @@ extern "C" { * 0, always. */ #ifndef _di_controller_thread_exit_ - extern void * controller_thread_exit(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_exit(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_exit_ #ifdef __cplusplus diff --git a/level_3/controller/c/private-thread_process.c b/level_3/controller/c/private-thread_process.c index 3775634..a254215 100644 --- a/level_3/controller/c/private-thread_process.c +++ b/level_3/controller/c/private-thread_process.c @@ -177,6 +177,7 @@ extern "C" { time.tv_nsec = controller_thread_exit_process_cancel_wait_d; nanosleep(&time, 0); + continue; } else { @@ -250,7 +251,7 @@ extern "C" { #endif // _di_controller_thread_process_cancel_ #ifndef _di_controller_thread_process_exit_ - void controller_thread_process_exit(controller_global_t *global) { + void controller_thread_process_exit(controller_global_t * const global) { if (global->thread->enabled != controller_thread_enabled_exit_e) { return; @@ -277,7 +278,7 @@ extern "C" { if (F_status_is_error(status)) { if (global->main->error.verbosity != f_console_verbosity_quiet_e) { - controller_print_error(global->main->error, F_status_set_fine(status), "f_thread_create", F_true, global->thread); + controller_print_error(global->thread, global->main->error, F_status_set_fine(status), "f_thread_create", F_true); } if (F_status_is_error_not(f_thread_mutex_lock(&global->thread->lock.alert))) { @@ -345,7 +346,7 @@ extern "C" { #endif // _di_controller_thread_process_exit_ #ifndef _di_controller_thread_process_normal_ - void * controller_thread_process_normal(void *arguments) { + void * controller_thread_process_normal(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); @@ -356,7 +357,7 @@ extern "C" { #endif // _di_controller_thread_process_normal_ #ifndef _di_controller_thread_process_other_ - void * controller_thread_process_other(void *arguments) { + void * controller_thread_process_other(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); diff --git a/level_3/controller/c/private-thread_process.h b/level_3/controller/c/private-thread_process.h index 3411b6f..2e9cbf5 100644 --- a/level_3/controller/c/private-thread_process.h +++ b/level_3/controller/c/private-thread_process.h @@ -56,7 +56,7 @@ extern "C" { * The global thread data. */ #ifndef _di_controller_thread_process_exit_ - extern void controller_thread_process_exit(controller_global_t *global) F_attribute_visibility_internal_d; + extern void controller_thread_process_exit(controller_global_t * const global) F_attribute_visibility_internal_d; #endif // _di_controller_thread_process_exit_ /** @@ -72,7 +72,7 @@ extern "C" { * @see controller_thread_process() */ #ifndef _di_controller_thread_process_normal_ - extern void * controller_thread_process_normal(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_process_normal(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_process_normal_ /** @@ -88,7 +88,7 @@ extern "C" { * @see controller_thread_process() */ #ifndef _di_controller_thread_process_other_ - extern void * controller_thread_process_other(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_process_other(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_process_other_ #ifdef __cplusplus diff --git a/level_3/controller/c/private-thread_rule.c b/level_3/controller/c/private-thread_rule.c index d747f39..c8a0655 100644 --- a/level_3/controller/c/private-thread_rule.c +++ b/level_3/controller/c/private-thread_rule.c @@ -8,11 +8,11 @@ extern "C" { #endif #ifndef _di_controller_thread_rule_ - void * controller_thread_rule(void *arguments) { + void * controller_thread_rule(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_global_t *global = (controller_global_t *) arguments; + const controller_global_t *global = (controller_global_t *) arguments; if (!controller_thread_is_enabled(F_true, global->thread)) return 0; diff --git a/level_3/controller/c/private-thread_rule.h b/level_3/controller/c/private-thread_rule.h index 4ff6bde..61cf96d 100644 --- a/level_3/controller/c/private-thread_rule.h +++ b/level_3/controller/c/private-thread_rule.h @@ -28,7 +28,7 @@ extern "C" { * 0, always. */ #ifndef _di_controller_thread_rule_ - extern void * controller_thread_rule(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_rule(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_rule_ #ifdef __cplusplus diff --git a/level_3/controller/c/private-thread_signal.c b/level_3/controller/c/private-thread_signal.c index cabdff1..d216ab5 100644 --- a/level_3/controller/c/private-thread_signal.c +++ b/level_3/controller/c/private-thread_signal.c @@ -11,7 +11,7 @@ extern "C" { #endif #ifndef _di_controller_thread_signal_ - void controller_thread_signal(const bool is_normal, controller_global_t *global) { + void controller_thread_signal(controller_global_t * const global, const bool is_normal) { if (!controller_thread_is_enabled(is_normal, global->thread)) return; @@ -43,7 +43,7 @@ extern "C" { #endif // _di_controller_thread_signal_ #ifndef _di_controller_thread_signal_state_fss_ - f_status_t controller_thread_signal_state_fss(void *state, void *internal) { + f_status_t controller_thread_signal_state_fss(void * const state, void * const internal) { if (!state) { return F_interrupt_not; @@ -71,7 +71,7 @@ extern "C" { #endif // _di_controller_thread_signal_state_fss_ #ifndef _di_controller_thread_signal_state_iki_ - f_status_t controller_thread_signal_state_iki(void *state, void *internal) { + f_status_t controller_thread_signal_state_iki(void * const state, void * const internal) { if (!state) { return F_interrupt_not; @@ -99,22 +99,22 @@ extern "C" { #endif // _di_controller_thread_signal_state_iki_ #ifndef _di_controller_thread_signal_normal_ - void * controller_thread_signal_normal(void *arguments) { + void * controller_thread_signal_normal(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_thread_signal(F_true, (controller_global_t *) arguments); + controller_thread_signal((controller_global_t *) arguments, F_true); return 0; } #endif // _di_controller_thread_signal_normal_ #ifndef _di_controller_thread_signal_other_ - void * controller_thread_signal_other(void *arguments) { + void * controller_thread_signal_other(void * const arguments) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_thread_signal(F_false, (controller_global_t *) arguments); + controller_thread_signal((controller_global_t *) arguments, F_false); return 0; } diff --git a/level_3/controller/c/private-thread_signal.h b/level_3/controller/c/private-thread_signal.h index 2984659..e0fefd6 100644 --- a/level_3/controller/c/private-thread_signal.h +++ b/level_3/controller/c/private-thread_signal.h @@ -15,14 +15,14 @@ extern "C" { /** * Thread for handling signals/interrupts. * + * @param global + * The global data. * @param is_normal * If TRUE, then process as if this operates during a normal operation (entry and control). * If FALSE, then process as if this operates during a an exit operation. - * @param global - * The global data. */ #ifndef _di_controller_thread_signal_ - extern void controller_thread_signal(const bool is_normal, controller_global_t *global) F_attribute_visibility_internal_d; + extern void controller_thread_signal(controller_global_t * const global, const bool is_normal) F_attribute_visibility_internal_d; #endif // _di_controller_thread_signal_ /** @@ -39,7 +39,7 @@ extern "C" { * F_interrupt (with error bit) if interrupted. */ #ifndef _di_controller_thread_signal_state_fss_ - extern f_status_t controller_thread_signal_state_fss(void *state, void *internal) F_attribute_visibility_internal_d; + extern f_status_t controller_thread_signal_state_fss(void * const state, void * const internal) F_attribute_visibility_internal_d; #endif // _di_controller_thread_signal_state_fss_ /** @@ -56,7 +56,7 @@ extern "C" { * F_interrupt (with error bit) if interrupted. */ #ifndef _di_controller_thread_signal_state_iki_ - extern f_status_t controller_thread_signal_state_iki(void *state, void *internal) F_attribute_visibility_internal_d; + extern f_status_t controller_thread_signal_state_iki(void * const state, void * const internal) F_attribute_visibility_internal_d; #endif // _di_controller_thread_signal_state_iki_ /** @@ -74,7 +74,7 @@ extern "C" { * @see controller_thread_signal() */ #ifndef _di_controller_thread_signal_normal_ - extern void * controller_thread_signal_normal(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_signal_normal(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_signal_normal_ /** @@ -92,7 +92,7 @@ extern "C" { * @see controller_thread_signal() */ #ifndef _di_controller_thread_signal_other_ - extern void * controller_thread_signal_other(void *arguments) F_attribute_visibility_internal_d; + extern void * controller_thread_signal_other(void * const arguments) F_attribute_visibility_internal_d; #endif // _di_controller_thread_signal_other_ #ifdef __cplusplus diff --git a/level_3/controller/data/build/settings b/level_3/controller/data/build/settings index 3ef7dd0..84190ab 100644 --- a/level_3/controller/data/build/settings +++ b/level_3/controller/data/build/settings @@ -31,7 +31,7 @@ build_libraries-monolithic -lfll build_libraries_shared build_libraries_static build_sources_library controller.c private-common.c private-process.c -build_sources_library common/private-cache.c common/private-lock.c common/private-rule.c common/private-task.c common/private-process.c common/private-entry.c common/private-setting.c common/private-thread.c +build_sources_library common/private-cache.c common/private-control.c common/private-entry.c common/private-lock.c common/private-process.c common/private-rule.c common/private-setting.c common/private-task.c common/private-thread.c build_sources_library private-control.c private-controller.c private-entry.c private-rule.c private-task.c build_sources_library private-control_print.c private-controller_print.c private-entry_print.c private-lock.c private-lock_print.c private-rule_print.c private-task_print.c build_sources_library private-thread.c private-thread_control.c private-thread_entry.c private-thread_process.c private-thread_rule.c private-thread_signal.c -- 1.8.3.1