From: Kevin Day Date: Thu, 11 Apr 2024 03:46:56 +0000 (-0500) Subject: Progress: Continue migrating the project. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=e9ab2ac39e0504bddda36264ce5d9fc995e42375;p=controller Progress: Continue migrating the project. Start brining in the enumerations and types. There is still a lot of inconsistency in the type delete functions to deal with. Many of the "delete" functions may end up being replaced with a "resize" method. This removes the "--init" parameter. I figure I might as well simplify the design a little and have the init and controller be more separate. --- diff --git a/data/build/settings b/data/build/settings index 6510fdb..0741a74 100644 --- a/data/build/settings +++ b/data/build/settings @@ -41,10 +41,13 @@ build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library main/common.c main/common/define.c main/common/enumeration.c main/common/print.c main/common/string.c main/common/type.c +build_sources_library main/common/type/cache.c main/common/type/control.c main/common/type/entry.c main/common/type/process.c main/common/type/rule.c build_sources_library main/print/data.c main/print/debug.c main/print/error.c main/print/message.c main/print/verbose.c main/print/warning.c build_sources_library main/signal.c main/thread.c build_sources_headers main/common.h main/controller.h main/common/define.h main/common/enumeration.h main/common/print.h main/common/string.h main/common/type.h +build_sources_headers main/common/enumeration/control.h main/common/enumeration/entry.h main/common/enumeration/process.h main/common/enumeration/rule.h +build_sources_headers main/common/type/cache.h main/common/type/control.h main/common/type/entry.h main/common/type/process.h main/common/type/rule.h build_sources_headers main/print/data.h main/print/debug.h main/print/error.h main/print/message.h main/print/verbose.h main/print/warning.h build_sources_headers main/signal.h main/thread.h diff --git a/sources/c/controller/controller.h b/sources/c/controller/controller.h index db61552..2eed854 100644 --- a/sources/c/controller/controller.h +++ b/sources/c/controller/controller.h @@ -24,14 +24,20 @@ #include #include #include +#include #include #include #include +#include #include +#include +#include +#include #include #include #include #include +#include #ifndef _di_thread_support_ #include @@ -51,6 +57,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/sources/c/init/init.h b/sources/c/init/init.h index 5e4d01d..09bf2d0 100644 --- a/sources/c/init/init.h +++ b/sources/c/init/init.h @@ -24,14 +24,20 @@ #include #include #include +#include #include #include #include +#include #include +#include +#include +#include #include #include #include #include +#include #ifndef _di_thread_support_ #include @@ -51,6 +57,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/sources/c/main/common/enumeration.h b/sources/c/main/common/enumeration.h index fedbd4d..8abba74 100644 --- a/sources/c/main/common/enumeration.h +++ b/sources/c/main/common/enumeration.h @@ -64,7 +64,6 @@ extern "C" { \ macro_f_console_parameter_t_initialize_3(controller_short_cgroup_s, controller_long_cgroup_s, 1, f_console_flag_normal_e), \ macro_f_console_parameter_t_initialize_3(controller_short_daemon_s, controller_long_daemon_s, 0, f_console_flag_normal_e), \ - macro_f_console_parameter_t_initialize_3(controller_short_init_s, controller_long_init_s, 0, f_console_flag_normal_e), \ macro_f_console_parameter_t_initialize_3(controller_short_interruptible_s, controller_long_interruptible_s, 0, f_console_flag_normal_e), \ macro_f_console_parameter_t_initialize_3(controller_short_pid_s, controller_long_pid_s, 1, f_console_flag_normal_e), \ macro_f_console_parameter_t_initialize_3(controller_short_settings_s, controller_long_settings_s, 1, f_console_flag_normal_e), \ @@ -74,7 +73,7 @@ extern "C" { macro_f_console_parameter_t_initialize_3(controller_short_validate_s, controller_long_validate_s, 0, f_console_flag_normal_e), \ } - #define controller_parameter_total_d (f_console_parameter_state_type_total_d + 10) + #define controller_parameter_total_d (f_console_parameter_state_type_total_d + 9) #endif // _di_controller_parameter_e_ /** diff --git a/sources/c/main/common/enumeration/control.h b/sources/c/main/common/enumeration/control.h new file mode 100644 index 0000000..aaf2268 --- /dev/null +++ b/sources/c/main/common/enumeration/control.h @@ -0,0 +1,61 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common control enumerations. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_enumeration_control_h +#define _controller_main_common_enumeration_control_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Controller Control flags. + * + * controller_control_flag_*_e: + * - none: Nothing set. + * - readonly: Control is set to read-only mode. + * - has_user: A user is manually specified. + * - has_group: A group is manually specified. + * - has_mode: A file mode is manually specified. + */ +#ifndef _di_controller_control_e_ + enum { + controller_control_flag_none_e = 0x0, + controller_control_flag_readonly_e = 0x1, + controller_control_flag_has_user_e = 0x2, + controller_control_flag_has_group_e = 0x4, + controller_control_flag_has_mode_e = 0x8, + }; // enum +#endif // _di_controller_control_e_ + +/** + * Controller Control payload type enumeration. + * + * controller_control_payload_type_*_e: + * - none: Nothing set. + * - controller: The item type represents a command operation. + * - error: The item type represents a script operation. + * - init: The item type represents an init operation (Only fo init mode). + */ +#ifndef _di_controller_control_payload_type_e_ + enum { + controller_control_payload_type_none_e = 0, + controller_control_payload_type_controller_e, + controller_control_payload_type_error_e, + controller_control_payload_type_init_e, + }; // enum +#endif // _di_controller_control_payload_type_e_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_enumeration_control_h diff --git a/sources/c/main/common/enumeration/entry.h b/sources/c/main/common/enumeration/entry.h new file mode 100644 index 0000000..5d6925c --- /dev/null +++ b/sources/c/main/common/enumeration/entry.h @@ -0,0 +1,149 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common entry enumerations. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_enumeration_entry_h +#define _controller_main_common_enumeration_entry_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Controller Entry Action flags. + * + * controller_entry_action_flag_*_e: + * - undefined: The given type and code are designated as undefined. + */ +#ifndef _di_controller_entry_action_e_ + enum { + controller_entry_action_flag_none_e = 0x0, + controller_entry_action_flag_undefined_e = 0x1, + }; // enum +#endif // _di_controller_entry_action_e_ + +/** + * Controller Entry Action type enumeration. + * + * controller_entry_action_type_*_e: + * - none: Nothing set. + * - consider: Perform the consider controller operation. + * - execute: Perform the execute controller operation. + * - freeze: Perform the freeze controller operation.. + * - item: Perform the item controller operation. + * - kexec: Perform the kexec controller operation (only for init mode). + * - kill: Perform the kill controller operation. + * - pause: Perform the pause controller operation. + * - ready: Perform the ready controller operation. + * - reboot: Perform the reboot controller operation (only for init mode). + * - reload: Perform the reload controller operation. + * - restart: Perform the restart controller operation. + * - resume: Perform the resume controller operation. + * - shutdown: Perform the shutdown controller operation (only for init mode). + * - start: Perform the start controller operation. + * - stop: Perform the stop controller operation. + * - timeout: Perform the timeout controller operation. + * - thaw: Perform the thaw controller operation. + */ +#ifndef _di_controller_entry_action_type_e_ + enum { + controller_entry_action_type_none_e = 0, + controller_entry_action_type_consider_e, + controller_entry_action_type_execute_e, + controller_entry_action_type_failsafe_e, + controller_entry_action_type_freeze_e, + controller_entry_action_type_item_e, + controller_entry_action_type_kexec_e, + controller_entry_action_type_kill_e, + controller_entry_action_type_pause_e, + controller_entry_action_type_ready_e, + controller_entry_action_type_reboot_e, + controller_entry_action_type_reload_e, + controller_entry_action_type_restart_e, + controller_entry_action_type_resume_e, + controller_entry_action_type_shutdown_e, + controller_entry_action_type_start_e, + controller_entry_action_type_stop_e, + controller_entry_action_type_timeout_e, + controller_entry_action_type_thaw_e, + }; // enum +#endif // _di_controller_entry_action_type_e_ + +/** + * Controller Entry flags. + * + * controller_entry_flag_*_e: + * - none_e: No flags are set. + * - timeout_exit_no_e: The exit timeout is disabled. + * - timeout_kill_no_e: The kill timeout is disabled for Rules by default. + * - timeout_start_no_e: The start timeout is disabled for Rules by default. + * - timeout_stop_no_e: The stop timeout is disabled for Rules by default. + */ +#ifndef _di_controller_entry_flag_e_ + enum { + controller_entry_flag_none_e = 0x0, + controller_entry_flag_timeout_exit_no_e = 0x1, + controller_entry_flag_timeout_kill_no_e = 0x2, + controller_entry_flag_timeout_start_no_e = 0x4, + controller_entry_flag_timeout_stop_no_e = 0x8, + }; // enum +#endif // _di_controller_entry_flag_e_ + +/** + * Controller Entry PID enumeration. + * + * controller_entry_pid_*_e: + * - disable: Do not check for or create a PID file to represent the entry execution. + * - require: Check to see if the PID file exists for an entry at startup and then when "ready" create a pid file, display error on pid file already exists or on failure and then fail. + * - ready: When "ready" create a pid file, display error on failure and then fail (does not check if PID file exists). + */ +#ifndef _di_controller_entry_pid_e_ + enum { + controller_entry_pid_disable_e = 0, + controller_entry_pid_require_e, + controller_entry_pid_ready_e, + }; // enum +#endif // _di_controller_entry_pid_e_ + +/** + * Controller Entry session enumeration. + * + * controller_entry_session_*_e: + * - none: No special session configuration specified, use built in defaults. + * - new: Designate the default to use a new session, ignoring built in defaults (passing FL_execute_parameter_option_session_d to the execute functions). + * - same: Designate the default to use a same session, ignoring built in defaults. + */ +#ifndef _di_controller_entry_session_e_ + enum { + controller_entry_session_none_e = 0, + controller_entry_session_new_e, + controller_entry_session_same_e, + }; // enum +#endif // _di_controller_entry_session_e_ + +/** + * Controller Entry show enumeration. + * + * controller_entry_show_*_e: + * - normal: Do not print anything other than warnings and errors, but allow executed programs and scripts to output however they like. + * - init: Print like an init program, printing status of entry and rules as they are being started, stopped, etc... + */ +#ifndef _di_controller_entry_show_e_ + enum { + controller_entry_show_normal_e = 0, + controller_entry_show_init_e, + }; // enum +#endif // _di_controller_entry_show_e_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_enumeration_entry_h diff --git a/sources/c/main/common/enumeration/process.h b/sources/c/main/common/enumeration/process.h new file mode 100644 index 0000000..7f1f98f --- /dev/null +++ b/sources/c/main/common/enumeration/process.h @@ -0,0 +1,77 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common process enumerations. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_enumeration_process_h +#define _controller_main_common_enumeration_process_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Controller process flags. + * + * controller_setting_flag_*_e: + * - interruptible: When specified, program responds to interrupt signals, otherwise block/ignore interrupt signals. + * - pid_created: When specified, the program responds to interrupt signals, otherwise block/ignore interrupt signals. + * - failsafe: When specified, failsafe mode is enabled, otherwise failsafe mode is disabled. + */ +#ifndef _di_controller_process_flag_e_ + enum { + controller_process_flag_interruptible_e = 0x1, + controller_process_flag_pid_created_e = 0x2, + controller_process_flag_failsafe_e = 0x4, + }; // enum +#endif // _di_controller_process_flag_e_ + +/** + * Controller process mode enumeration. + * + * controller_setting_mode_*: + * - helper: Run as a helper, exiting when finished prrocess entry (and any respective exit). + * - program: Run as a program, exiting when finished prrocess entry (and any respective exit). + * - service: Run as a service, listening for requests after processing entry. + */ +#ifndef _di_controller_process_mode_e_ + enum { + controller_process_mode_service_e = 0, + controller_process_mode_helper_e, + controller_process_mode_program_e, + }; // enum +#endif // _di_controller_process_mode_e_ + +/** + * Controller Process ready enumeration. + * + * controller_process_ready_*_e: + * - no: Entry/Exit is not ready. + * - wait: Entry/Exit has "ready" somewhere in the file but is not yet ready. + * - yes: Entry/Exit is now ready (Entry/Exit is still being processed). + * - done: Entry/Exit is ready and processing is complete. + * - fail: Entry/Exit processing failed. + * - abort: Abort received before finished processing Entry/Exit. + */ +#ifndef _di_controller_process_ready_e_ + enum { + controller_process_ready_no_e = 0, + controller_process_ready_wait_e, + controller_process_ready_yes_e, + controller_process_ready_done_e, + controller_process_ready_fail_e, + controller_process_ready_abort_e, + }; // enum +#endif // _di_controller_process_ready_e_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_enumeration_process_h diff --git a/sources/c/main/common/enumeration/rule.h b/sources/c/main/common/enumeration/rule.h new file mode 100644 index 0000000..f7a8942 --- /dev/null +++ b/sources/c/main/common/enumeration/rule.h @@ -0,0 +1,181 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common rule enumerations. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_enumeration_rule_h +#define _controller_main_common_enumeration_rule_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Controller Rule Action execute type enumeration index. + * + * Execute type starts at 0 because it is intended to be used as an index within a static array. + * + * controller_rule_action_execute_type_*_e: + * - freeze: The Freeze execution instructions. + * - kill: The Kill execution instructions. + * - pause: The Pause execution instructions. + * - reload: The Reload execution instructions. + * - restart: The Restart execution instructions. + * - resume: The Resume execution instructions. + * - start: The Start execution instructions. + * - stop: The Stop execution instructions. + * - thaw: The Thaw execution instructions. + */ +#ifndef _di_controller_rule_action_execute_type_e_ + enum { + controller_rule_action_execute_type_freeze_e = 0, + controller_rule_action_execute_type_kill_e, + controller_rule_action_execute_type_pause_e, + controller_rule_action_execute_type_reload_e, + controller_rule_action_execute_type_restart_e, + controller_rule_action_execute_type_resume_e, + controller_rule_action_execute_type_start_e, + controller_rule_action_execute_type_stop_e, + controller_rule_action_execute_type_thaw_e, + + // Designate the largest value in the enum, the '__' is intentional. + controller_rule_action_execute_type__enum_size_e, + }; // enum +#endif // _di_controller_rule_action_execute_type_e_ + +/** + * Controller Rule Action method enumeration. + * + * controller_rule_action_method_*_e: + * - none: Nothing set. + * - extended: Designate that this Action is represented using FSS Extended. + * - extended_list: Designate that this Action is represented using FSS Extended List. + */ +#ifndef _di_controller_rule_action_method_e_ + enum { + controller_rule_action_method_none_e = 0, + controller_rule_action_method_extended_e, + controller_rule_action_method_extended_list_e, + }; // enum +#endif // _di_controller_rule_action_method_e_ + +/** + * Controller Rule Action type enumeration. + * + * controller_rule_action_type_*_e: + * - none: Nothing set. + * - freeze: The Freeze execution instructions. + * - group: The Group setting. + * - kill: The Kill execution instructions. + * - pause: The Pause execution instructions. + * - pid_file: The PID file setting. + * - rerun: The Re-run execution after success or failure. + * - reload: The Reload execution instructions. + * - restart: The Restart execution instructions. + * - resume: The Resume execution instructions. + * - start: The Start execution instructions. + * - stop: The Stop execution instructions. + * - thaw: The Thaw execution instructions. + * - user: The User setting. + * - with: The With flags. + */ +#ifndef _di_controller_rule_action_type_e_ + enum { + controller_rule_action_type_none_e = 0, + controller_rule_action_type_freeze_e, + controller_rule_action_type_group_e, + controller_rule_action_type_kill_e, + controller_rule_action_type_pause_e, + controller_rule_action_type_pid_file_e, + controller_rule_action_type_reload_e, + controller_rule_action_type_rerun_e, + controller_rule_action_type_restart_e, + controller_rule_action_type_resume_e, + controller_rule_action_type_start_e, + controller_rule_action_type_stop_e, + controller_rule_action_type_thaw_e, + controller_rule_action_type_user_e, + controller_rule_action_type_with_e, + + // Designate the largest value in the enum, the '__' is intentional. + controller_rule_action_type__enum_size_e, + }; // enum +#endif // _di_controller_rule_action_type_e_ + +/** + * Controller Rule Item type enumeration. + * + * controller_rule_item_type_*_e: + * - none: Nothing set. + * - command: The item type represents a command operation. + * - script: The item type represents a script operation. + * - service: The item type represents a service operation. + * - settings: The item type represents a setting operation. + * - utility: The item type represents a utility operation. + */ +#ifndef _di_controller_rule_item_type_e_ + enum { + controller_rule_item_type_none_e = 0, + controller_rule_item_type_command_e, + controller_rule_item_type_script_e, + controller_rule_item_type_service_e, + controller_rule_item_type_settings_e, + controller_rule_item_type_utility_e, + }; // enum +#endif // _di_controller_rule_item_type_e_ + +/** + * Contoller Rule setting type enumeration. + * + * controller_rule_setting_type_*_e: + * - none: Nothing set. + * - affinity: Setting type representing a affinity. + * - capability: Setting type representing a capability. + * - cgroup: Setting type representing a control group. + * - define: Setting type representing a define. + * - engine: Setting type representing a engine. + * - engine_arguments: Setting type representing a engine. + * - environment: Setting type representing a environment. + * - group: Setting type representing a group. + * - limit: Setting type representing a limit. + * - name: Setting type representing a name. + * - nice: Setting type representing a nice. + * - on: Setting type representing a on. + * - parameter: Setting type representing a parameter. + * - path: Setting type representing a path. + * - scheduler: Setting type representing a scheduler. + * - user: Setting type representing a user. + */ +#ifndef _di_controller_rule_setting_type_e_ + enum { + controller_rule_setting_type_none_e = 0, + controller_rule_setting_type_affinity_e, + controller_rule_setting_type_capability_e, + controller_rule_setting_type_cgroup_e, + controller_rule_setting_type_define_e, + controller_rule_setting_type_engine_e, + controller_rule_setting_type_environment_e, + controller_rule_setting_type_group_e, + controller_rule_setting_type_limit_e, + controller_rule_setting_type_name_e, + controller_rule_setting_type_nice_e, + controller_rule_setting_type_on_e, + controller_rule_setting_type_parameter_e, + controller_rule_setting_type_path_e, + controller_rule_setting_type_scheduler_e, + controller_rule_setting_type_timeout_e, + controller_rule_setting_type_user_e, + }; // enum +#endif // _di_controller_rule_setting_type_e_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_enumeration_rule_h diff --git a/sources/c/main/common/string.c b/sources/c/main/common/string.c index 8630663..ed85272 100644 --- a/sources/c/main/common/string.c +++ b/sources/c/main/common/string.c @@ -11,7 +11,6 @@ extern "C" { #ifndef _di_controller_parameter_s_ const f_string_static_t controller_short_cgroup_s = macro_f_string_static_t_initialize_1(CONTROLLER_short_cgroup_s, 0, CONTROLLER_short_cgroup_s_length); const f_string_static_t controller_short_daemon_s = macro_f_string_static_t_initialize_1(CONTROLLER_short_daemon_s, 0, CONTROLLER_short_daemon_s_length); - const f_string_static_t controller_short_init_s = macro_f_string_static_t_initialize_1(CONTROLLER_short_init_s, 0, CONTROLLER_short_init_s_length); const f_string_static_t controller_short_interruptible_s = macro_f_string_static_t_initialize_1(CONTROLLER_short_interruptible_s, 0, CONTROLLER_short_interruptible_s_length); const f_string_static_t controller_short_pid_s = macro_f_string_static_t_initialize_1(CONTROLLER_short_pid_s, 0, CONTROLLER_short_pid_s_length); const f_string_static_t controller_short_settings_s = macro_f_string_static_t_initialize_1(CONTROLLER_short_settings_s, 0, CONTROLLER_short_settings_s_length); @@ -22,7 +21,6 @@ extern "C" { const f_string_static_t controller_long_cgroup_s = macro_f_string_static_t_initialize_1(CONTROLLER_long_cgroup_s, 0, CONTROLLER_long_cgroup_s_length); const f_string_static_t controller_long_daemon_s = macro_f_string_static_t_initialize_1(CONTROLLER_long_daemon_s, 0, CONTROLLER_long_daemon_s_length); - const f_string_static_t controller_long_init_s = macro_f_string_static_t_initialize_1(CONTROLLER_long_init_s, 0, CONTROLLER_long_init_s_length); const f_string_static_t controller_long_interruptible_s = macro_f_string_static_t_initialize_1(CONTROLLER_long_interruptible_s, 0, CONTROLLER_long_interruptible_s_length); const f_string_static_t controller_long_pid_s = macro_f_string_static_t_initialize_1(CONTROLLER_long_pid_s, 0, CONTROLLER_long_pid_s_length); const f_string_static_t controller_long_settings_s = macro_f_string_static_t_initialize_1(CONTROLLER_long_settings_s, 0, CONTROLLER_long_settings_s_length); diff --git a/sources/c/main/common/string.h b/sources/c/main/common/string.h index 42d2f76..03a7b9a 100644 --- a/sources/c/main/common/string.h +++ b/sources/c/main/common/string.h @@ -61,8 +61,7 @@ extern "C" { #ifndef _di_controller_parameter_s_ #define CONTROLLER_short_cgroup_s "c" #define CONTROLLER_short_daemon_s "d" - #define CONTROLLER_short_init_s "I" - #define CONTROLLER_short_interruptible_s "i" + #define CONTROLLER_short_interruptible_s "I" #define CONTROLLER_short_pid_s "p" #define CONTROLLER_short_settings_s "s" #define CONTROLLER_short_simulate_s "S" @@ -72,7 +71,6 @@ extern "C" { #define CONTROLLER_long_cgroup_s "cgroup" #define CONTROLLER_long_daemon_s "daemon" - #define CONTROLLER_long_init_s "init" #define CONTROLLER_long_interruptible_s "interruptible" #define CONTROLLER_long_pid_s "pid" #define CONTROLLER_long_settings_s "settings" @@ -83,7 +81,6 @@ extern "C" { #define CONTROLLER_short_cgroup_s_length 1 #define CONTROLLER_short_daemon_s_length 1 - #define CONTROLLER_short_init_s_length 1 #define CONTROLLER_short_interruptible_s_length 1 #define CONTROLLER_short_pid_s_length 1 #define CONTROLLER_short_settings_s_length 1 @@ -94,7 +91,6 @@ extern "C" { #define CONTROLLER_long_cgroup_s_length 6 #define CONTROLLER_long_daemon_s_length 6 - #define CONTROLLER_long_init_s_length 4 #define CONTROLLER_long_interruptible_s_length 13 #define CONTROLLER_long_pid_s_length 3 #define CONTROLLER_long_settings_s_length 8 @@ -105,7 +101,6 @@ extern "C" { extern const f_string_static_t controller_short_cgroup_s; extern const f_string_static_t controller_short_daemon_s; - extern const f_string_static_t controller_short_init_s; extern const f_string_static_t controller_short_interruptible_s; extern const f_string_static_t controller_short_pid_s; extern const f_string_static_t controller_short_settings_s; diff --git a/sources/c/main/common/type.c b/sources/c/main/common/type.c index f3101a4..dd56813 100644 --- a/sources/c/main/common/type.c +++ b/sources/c/main/common/type.c @@ -4,15 +4,6 @@ extern "C" { #endif -#ifndef _di_controller_cache_delete_ - void controller_cache_delete(controller_cache_t * const cache) { - - if (!cache) return; - - f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size); - } -#endif // _di_controller_cache_delete_ - #ifndef _di_controller_main_delete_ void controller_main_delete(controller_main_t * const main) { diff --git a/sources/c/main/common/type.h b/sources/c/main/common/type.h index 0bd3ca9..49a69b0 100644 --- a/sources/c/main/common/type.h +++ b/sources/c/main/common/type.h @@ -17,22 +17,6 @@ extern "C" { #endif /** - * The controller main program cache. - * - * buffer: A generic buffer. - */ -#ifndef _di_controller_cache_t_ - typedef struct { - f_string_dynamic_t buffer; - } controller_cache_t; - - #define controller_cache_t_initialize \ - { \ - f_string_dynamic_t_initialize, \ - } -#endif // _di_controller_cache_t_ - -/** * The controller main program settings. * * This is passed to the program-specific main entry point to designate program settings. @@ -91,20 +75,6 @@ extern "C" { /** * Deallocate main program data. * - * @param cache - * The program cache. - * - * Must not be NULL. - * - * @see f_memory_array_resize() - */ -#ifndef _di_controller_cache_delete_ - extern void controller_cache_delete(controller_cache_t * const cache); -#endif // _di_controller_cache_delete_ - -/** - * Deallocate main program data. - * * @param main * The main program data. * diff --git a/sources/c/main/common/type/cache.c b/sources/c/main/common/type/cache.c new file mode 100644 index 0000000..8ef1eb2 --- /dev/null +++ b/sources/c/main/common/type/cache.c @@ -0,0 +1,18 @@ +#include "../../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_cache_delete_ + void controller_cache_delete(controller_cache_t * const cache) { + + if (!cache) return; + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size); + } +#endif // _di_controller_cache_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/common/type/cache.h b/sources/c/main/common/type/cache.h new file mode 100644 index 0000000..9833033 --- /dev/null +++ b/sources/c/main/common/type/cache.h @@ -0,0 +1,53 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common type cache structures. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_type_cache_h +#define _controller_main_common_type_cache_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The Controller main program cache. + * + * buffer: A generic buffer. + */ +#ifndef _di_controller_cache_t_ + typedef struct { + f_string_dynamic_t buffer; + } controller_cache_t; + + #define controller_cache_t_initialize \ + { \ + f_string_dynamic_t_initialize, \ + } +#endif // _di_controller_cache_t_ + +/** + * Deallocate the Controller cache. + * + * @param cache + * The cache. + * + * Must not be NULL. + * + * @see f_memory_array_resize() + */ +#ifndef _di_controller_cache_delete_ + extern void controller_cache_delete(controller_cache_t * const cache); +#endif // _di_controller_cache_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_type_cache_h diff --git a/sources/c/main/common/type/control.c b/sources/c/main/common/type/control.c new file mode 100644 index 0000000..aac9a39 --- /dev/null +++ b/sources/c/main/common/type/control.c @@ -0,0 +1,24 @@ +#include "../../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_control_delete_ + f_status_t controller_control_delete(controller_control_t * const control) { + + if (!control) return F_status_set_error(F_parameter); + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_1.string, &control->cache_1.used, &control->cache_1.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_2.string, &control->cache_2.used, &control->cache_2.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_3.string, &control->cache_3.used, &control->cache_3.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->input.string, &control->input.used, &control->input.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->output.string, &control->output.used, &control->output.size); + + return F_okay; + } +#endif // _di_controller_control_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/common/type/control.h b/sources/c/main/common/type/control.h new file mode 100644 index 0000000..23aa30d --- /dev/null +++ b/sources/c/main/common/type/control.h @@ -0,0 +1,91 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common type control structures. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_type_control_h +#define _controller_main_common_type_control_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Controller control data. + * + * flag: Flags from controller_control_flag_*_e. + * user: The user ID, if specified. + * group: The group ID, if specified. + * mode: The file mode, if specified. + * server: The server socket connection. + * client: The client socket connection. + * cache_1: A generic buffer used for caching control related data. + * cache_2: A generic buffer used for caching control related data. + * cache_3: A generic buffer used for caching control related data. + * input: A buffer used for receiving data from the client. + * output: A buffer used for transmitting data to the client. + * address: The socket address structure. + */ +#ifndef _di_controller_control_t_ + typedef struct { + uint8_t flag; + + uid_t user; + gid_t group; + mode_t mode; + + f_socket_t server; + f_socket_t client; + + f_string_dynamic_t cache_1; + f_string_dynamic_t cache_2; + f_string_dynamic_t cache_3; + + f_string_dynamic_t input; + f_string_dynamic_t output; + + struct sockaddr_un address; + } controller_control_t; + + #define controller_control_t_initialize { \ + 0, \ + -1, \ + -1, \ + 0, \ + f_socket_t_initialize, \ + f_socket_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + { }, \ + } +#endif // _di_controller_control_t_ + +/** + * Delete the Controller control data. + * + * @param control + * The controller control data. + * + * @return + * F_okay on success. + * + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_controller_control_delete_ + extern f_status_t controller_control_delete(controller_control_t * const control); +#endif // _di_controller_control_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_type_control_h diff --git a/sources/c/main/common/type/entry.c b/sources/c/main/common/type/entry.c new file mode 100644 index 0000000..af4b6a3 --- /dev/null +++ b/sources/c/main/common/type/entry.c @@ -0,0 +1,67 @@ +#include "../../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_entry_action_delete_ + f_status_t controller_entry_action_delete(controller_entry_action_t * const action) { + + if (!action) return F_status_set_error(F_parameter); + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &action->parameters.array, &action->parameters.used, &action->parameters.size, &f_string_dynamics_delete_callback); + + return F_okay; + } +#endif // _di_controller_entry_action_delete_ + +#ifndef _di_controller_entry_actions_delete_ + f_status_t controller_entry_actions_delete(controller_entry_actions_t * const actions) { + + if (!actions) return F_status_set_error(F_parameter); + + actions->used = actions->size; + + while (actions->used) { + controller_entry_action_delete(&actions->array[--actions->used]); + } // while + + f_memory_array_resize(0, sizeof(controller_entry_action_t), (void **) &actions->array, &actions->used, &actions->size); + + return F_okay; + } +#endif // _di_controller_entry_actions_delete_ + +#ifndef _di_controller_entry_item_delete_ + f_status_t controller_entry_item_delete(controller_entry_item_t * const item) { + + if (!item) return F_status_set_error(F_parameter); + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &item->name.string, &item->name.used, &item->name.size); + + controller_entry_actions_delete(&item->actions); + + return F_okay; + } +#endif // _di_controller_entry_item_delete_ + +#ifndef _di_controller_entry_items_delete_ + f_status_t controller_entry_items_delete(controller_entry_items_t * const items) { + + if (!items) return F_status_set_error(F_parameter); + + items->used = items->size; + + while (items->used) { + controller_entry_item_delete(&items->array[--items->used]); + } // while + + f_memory_array_resize(0, sizeof(controller_entry_item_t), (void **) &items->array, &items->used, &items->size); + + return F_okay; + } +#endif // _di_controller_entry_items_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/common/type/entry.h b/sources/c/main/common/type/entry.h new file mode 100644 index 0000000..c966a05 --- /dev/null +++ b/sources/c/main/common/type/entry.h @@ -0,0 +1,257 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common type entry structures. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_type_entry_h +#define _controller_main_common_type_entry_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Controller Entry Item Action. + * + * type: The type of Action. + * code: A single code or sub-type associated with the Action. + * flag: A set of flags to describe special behavior for the given type and code (flags may be different per type and code). + * line: The line number where the Entry Item begins. + * number: The unsigned number that some types use instead of the "parameters". + * status: The overall status. + * parameters: The values associated with the Action. + */ +#ifndef _di_controller_entry_action_t_ + typedef struct { + uint8_t type; + uint8_t code; + uint8_t flag; + + f_number_unsigned_t line; + f_number_unsigned_t number; + + f_status_t status; + + f_string_dynamics_t parameters; + } controller_entry_action_t; + + #define controller_entry_action_t_initialize { \ + 0, \ + 0, \ + 0, \ + controller_entry_action_flag_none_e, \ + 0, \ + F_known_not, \ + f_string_dynamics_t_initialize, \ + } +#endif // _di_controller_entry_action_t_ + +/** + * Controller Entry Item Actions. + * + * array: An array of Entry Item Actions. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_controller_entry_actions_t_ + typedef struct { + controller_entry_action_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } controller_entry_actions_t; + + #define controller_entry_actions_t_initialize { \ + 0, \ + 0, \ + 0, \ + } +#endif // _di_controller_entry_actions_t_ + +/** + * Controller Entry Item. + * + * line: The line number where the Entry Item begins. + * name: The name of the Entry Item. + * actions: The Actions associated with the Entry Item. + */ +#ifndef _di_controller_entry_item_t_ + typedef struct { + f_number_unsigned_t line; + f_string_dynamic_t name; + + controller_entry_actions_t actions; + } controller_entry_item_t; + + #define controller_entry_item_t_initialize \ + { \ + 0, \ + f_string_dynamic_t_initialize, \ + controller_entry_actions_t_initialize, \ + } +#endif // _di_controller_entry_item_t_ + +/** + * Controller Entry Items. + * + * array: An array of Entry Items. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_controller_entry_items_t_ + typedef struct { + controller_entry_item_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } controller_entry_items_t; + + #define controller_entry_items_t_initialize { \ + 0, \ + 0, \ + 0, \ + } + + #define macro_controller_entry_items_t_clear(items) \ + items.array = 0; \ + items.size = 0; \ + items.used = 0; +#endif // _di_controller_entry_items_t_ + +/** + * Controller Entry (or Exit). + * + * Entry and Exit files are essentially the same structure with minor differences in settings and behavior. + * The structure is identical and due to lacking any particularly good name to represent both "entry" or "exit", the name "entry" is being used for both. + * + * define: Any defines (environment variables) made available to all Rules in this entry for IKI substitution or just as environment variables. + * flag: A set of flags, primarily used to designate that timeouts are disabled. + * items: The array of entry items. + * parameter: Any parameters made available to all Rules in this entry for IKI substitution. + * pid: The PID file generation setting. + * session: The default session settings (when NULL, no default is specified). + * show: The show setting for controlling what to show when executing entry items and rules. + * status: The overall status. + * timeout_exit: The timeout to wait when exiting the Controller program after sending the terminate signal to send the kill signal. + * timeout_kill: The timeout to wait relating to using a kill signal. + * timeout_start: The timeout to wait relating to starting a process. + * timeout_stop: The timeout to wait relating to stopping a process. + */ +#ifndef _di_controller_entry_t_ + typedef struct { + f_status_t status; + + uint8_t pid; + uint8_t session; + uint8_t show; + uint8_t flag; + + f_number_unsigned_t timeout_exit; + f_number_unsigned_t timeout_kill; + f_number_unsigned_t timeout_start; + f_number_unsigned_t timeout_stop; + + f_string_maps_t define; + f_string_maps_t parameter; + + controller_entry_items_t items; + } controller_entry_t; + + #define controller_entry_t_initialize { \ + F_known_not, \ + controller_entry_pid_require_e, \ + 0, \ + 0, \ + 0, \ + controller_thread_exit_timeout_d, \ + 0, \ + 0, \ + 0, \ + f_string_maps_t_initialize, \ + f_string_maps_t_initialize, \ + controller_entry_items_t_initialize, \ + } +#endif // _di_controller_entry_t_ + +/** + * Delete the Controller Entry Action data. + * + * @param actions + * The Controller Entry Action. + * + * @return + * F_okay on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see f_memory_arrays_resize() + */ +#ifndef _di_controller_entry_action_delete_ + extern f_status_t controller_entry_action_delete(controller_entry_action_t * const action); +#endif // _di_controller_entry_action_delete_ + +/** + * Delete the Controller Entry Actions data. + * + * @param actions + * The Controller Entry Actions. + * + * @return + * F_okay on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see controller_entry_action_delete() + * + * @see f_memory_array_resize() + */ +#ifndef _di_controller_entry_actions_delete_ + extern f_status_t controller_entry_actions_delete(controller_entry_actions_t * const actions); +#endif // _di_controller_entry_actions_delete_ + +/** + * Delete the Controller Entry Item data. + * + * @param item + * The Controller Entry Item. + * + * @return + * F_okay on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see f_memory_array_resize() + */ +#ifndef _di_controller_entry_item_delete_ + extern f_status_t controller_entry_item_delete(controller_entry_item_t * const item); +#endif // _di_controller_entry_item_delete_ + +/** + * Delete the Controller Entry Items data. + * + * @param items + * The Controller Entry Items. + * + * @return + * F_okay on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * @see controller_entry_item_delete() + * @see f_memory_delete() + */ +#ifndef _di_controller_entry_items_delete_ + extern f_status_t controller_entry_items_delete(controller_entry_items_t * const items); +#endif // _di_controller_entry_items_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_type_entry_h diff --git a/sources/c/main/common/type/process.c b/sources/c/main/common/type/process.c new file mode 100644 index 0000000..7289a1d --- /dev/null +++ b/sources/c/main/common/type/process.c @@ -0,0 +1,37 @@ +#include "../../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_process_delete_ + f_status_t controller_process_delete(controller_process_t * const process) { + + if (!process) return F_status_set_error(F_parameter); + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->name_entry.string, &process->name_entry.used, &process->name_entry.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_cgroup.string, &process->path_cgroup.used, &process->path_cgroup.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_control.string, &process->path_control.used, &process->path_control.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_current.string, &process->path_current.used, &process->path_current.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_pid.string, &process->path_pid.used, &process->path_pid.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_setting.string, &process->path_setting.used, &process->path_setting.size); + + controller_control_delete(&process->control); + + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->entry.define.array, &process->entry.define.used, &process->entry.define.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->entry.parameter.array, &process->entry.parameter.used, &process->entry.parameter.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->exit.define.array, &process->exit.define.used, &process->exit.define.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->exit.parameter.array, &process->exit.parameter.used, &process->exit.parameter.size, &f_string_maps_delete_callback); + + controller_entry_items_delete(&process->entry.items); + controller_entry_items_delete(&process->exit.items); + + controller_rules_delete(&process->rules); + + return F_okay; + } +#endif // _di_controller_process_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/common/type/process.h b/sources/c/main/common/type/process.h new file mode 100644 index 0000000..ea96a63 --- /dev/null +++ b/sources/c/main/common/type/process.h @@ -0,0 +1,92 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common type process structures. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_type_process_h +#define _controller_main_common_type_process_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Controller process data. + * + * ready: State representing if the settings are all loaded and is ready to run program operations. + * mode: Controller setting mode based on the setting mode enumerator. + * control: The control socket data. + * failsafe_item_id: The Entry Item ID to execute when failsafe execution is enabled. + * path_cgroup: Directory path to the cgroup directory. + * path_control: File path to the control socket (used for printing the path). + * path_pid: File path to the PID file. + * path_setting: File path to the setting directory. + * entry: The Entry settings. + * rules: All rules and their respective settings. + */ +#ifndef _di_controller_process_t_ + typedef struct { + uint8_t ready; + uint8_t mode; + + f_number_unsigned_t failsafe_item_id; + + controller_control_t control; + + f_string_dynamic_t path_cgroup; + f_string_dynamic_t path_control; + f_string_dynamic_t path_current; + f_string_dynamic_t path_pid; + f_string_dynamic_t path_setting; + + f_string_dynamic_t name_entry; + + controller_entry_t entry; + controller_entry_t exit; + controller_rules_t rules; + } controller_process_t; + + #define controller_process_t_initialize { \ + 0, \ + 0, \ + 0, \ + 0, \ + controller_control_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + controller_entry_t_initialize, \ + controller_entry_t_initialize, \ + controller_rules_t_initialize, \ + } +#endif // _di_controller_process_t_ + +/** + * Delete the Controller process data. + * + * @param process + * The controller process data. + * + * @return + * F_okay on success. + * + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_controller_process_delete_ + extern f_status_t controller_process_delete(controller_process_t * const process); +#endif // _di_controller_process_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_type_process_h diff --git a/sources/c/main/common/type/rule.c b/sources/c/main/common/type/rule.c new file mode 100644 index 0000000..2516436 --- /dev/null +++ b/sources/c/main/common/type/rule.c @@ -0,0 +1,132 @@ +#include "../../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_rule_delete_ + void controller_rule_delete(controller_rule_t * const rule) { + + if (!rule) return; + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->engine.string, &rule->engine.used, &rule->engine.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->name.string, &rule->name.used, &rule->name.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->path.string, &rule->path.used, &rule->path.size); + + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &rule->define.array, &rule->define.used, &rule->define.size, &f_string_maps_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &rule->parameter.array, &rule->parameter.used, &rule->parameter.size, &f_string_maps_delete_callback); + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->engine_arguments.array, &rule->engine_arguments.used, &rule->engine_arguments.size, &f_string_dynamics_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->environment.array, &rule->environment.used, &rule->environment.size, &f_string_dynamics_delete_callback); + + f_memory_array_resize(0, sizeof(int32_t), (void **) &rule->affinity.array, &rule->affinity.used, &rule->affinity.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->cgroup.path.string, &rule->cgroup.path.used, &rule->cgroup.path.size); + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->cgroup.groups.array, &rule->cgroup.groups.used, &rule->cgroup.groups.size, &f_string_dynamics_delete_callback); + f_memory_array_resize(0, sizeof(int32_t), (void **) &rule->groups.array, &rule->groups.used, &rule->groups.size); + f_memory_array_resize(0, sizeof(f_limit_set_t), (void **) &rule->limits.array, &rule->limits.used, &rule->limits.size); + + if (rule->capability) { + f_capability_delete(&rule->capability); + } + + controller_rule_ons_delete(&rule->ons); + controller_rule_items_delete(&rule->items); + } +#endif // _di_controller_rule_delete_ + +#ifndef _di_controller_rule_action_delete_ + void controller_rule_action_delete(controller_rule_action_t * const action) { + + if (!action) return; + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &action->parameters.array, &action->parameters.used, &action->parameters.size, &f_string_dynamics_delete_callback); + + f_memory_array_resize(0, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size); + } +#endif // _di_controller_rule_action_delete_ + +#ifndef _di_controller_rule_actions_delete_ + void controller_rule_actions_delete(controller_rule_actions_t * const actions) { + + if (!actions) return; + + actions->used = actions->size; + + while (actions->used) { + controller_rule_action_delete(&actions->array[--actions->used]); + } // while + + f_memory_array_resize(0, sizeof(controller_rule_action_t), (void **) &actions->array, &actions->used, &actions->size); + } +#endif // _di_controller_rule_actions_delete_ + +#ifndef _di_controller_rule_item_delete_ + void controller_rule_item_delete(controller_rule_item_t * const item) { + + if (!item) return; + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &item->pid_file.string, &item->pid_file.used, &item->pid_file.size); + + controller_rule_actions_delete(&item->actions); + } +#endif // _di_controller_rule_item_delete_ + +#ifndef _di_controller_rule_items_delete_ + void controller_rule_items_delete(controller_rule_items_t * const items) { + + if (!items) return; + + items->used = items->size; + + while (items->used) { + controller_rule_item_delete(&items->array[--items->used]); + } // while + + f_memory_array_resize(0, sizeof(controller_rule_item_t), (void **) &items->array, &items->used, &items->size); + } +#endif // _di_controller_rule_items_delete_ + +#ifndef _di_controller_rule_on_delete_ + void controller_rule_on_delete(controller_rule_on_t * const on) { + + if (!on) return; + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->need.array, &on->need.used, &on->need.size, &f_string_dynamics_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->want.array, &on->want.used, &on->want.size, &f_string_dynamics_delete_callback); + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->wish.array, &on->wish.used, &on->wish.size, &f_string_dynamics_delete_callback); + } +#endif // _di_controller_rule_on_delete_ + +#ifndef _di_controller_rule_ons_delete_ + void controller_rule_ons_delete(controller_rule_ons_t * const ons) { + + if (!ons) return; + + ons->used = ons->size; + + while (ons->used) { + controller_rule_on_delete(&ons->array[--ons->used]); + } // while + + f_memory_array_resize(0, sizeof(controller_rule_on_t), (void **) &ons->array, &ons->used, &ons->size); + } +#endif // _di_controller_rule_ons_delete_ + +#ifndef _di_controller_rules_delete_ + void controller_rules_delete(controller_rules_t * const rules) { + + if (!rules) return; + + rules->used = rules->size; + + while (rules->used) { + controller_rule_delete(&rules->array[--rules->used]); + } // while + + f_memory_array_resize(0, sizeof(controller_rule_t), (void **) &rules->array, &rules->used, &rules->size); + } +#endif // _di_controller_rules_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/common/type/rule.h b/sources/c/main/common/type/rule.h new file mode 100644 index 0000000..13fb4c0 --- /dev/null +++ b/sources/c/main/common/type/rule.h @@ -0,0 +1,482 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common type rules structures. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_type_rule_h +#define _controller_main_common_type_rule_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The Rule "rerun" item for controlling re-execution. + * + * count: A count of the number of executions. + * delay: The time to wait before attempting to re-run. + * max: The maximum number of times to re-run (with 0 representing re-run infinitely) for executions. + */ +#ifndef _di_controller_rule_rerun_item_t_ + typedef struct { + bool reset; + + f_number_unsigned_t count; + f_number_unsigned_t delay; + f_number_unsigned_t max; + } controller_rule_rerun_item_t; + + #define controller_rule_rerun_item_initialize { \ + F_false, \ + 0, \ + 5000, \ + 0, \ + + #define macro_controller_rule_rerun_item_initialize(item) { \ + item.reset = F_false; \ + item.count = 0; \ + item.delay = 5000; \ + item.max = 0; \ + } +#endif // _di_controller_rule_rerun_item_t_ + +/** + * The Rule "rerun" values for controlling re-execution. + * + * is: A bitwise set of options to designate whether rerun is enabled or not and other options. + * count_failure: A count of the number of failed executions. + * count_success: A count of the number of successful executions. + * delay_failure: The time to wait before attempting to "rerun" for failed executions. + * delay_success: The time to wait before attempting to "rerun" for successful executions. + * max_failure: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for failed executions. + * max_success: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for successful executions. + */ +#ifndef _di_controller_rule_rerun_t_ + typedef struct { + uint8_t is; + + controller_rule_rerun_item_t failure; + controller_rule_rerun_item_t success; + } controller_rule_rerun_t; + + #define controller_rule_rerun_initialize { \ + 0, \ + controller_rule_rerun_item_initialize, \ + controller_rule_rerun_item_initialize, \ + } +#endif // _di_controller_rule_rerun_t_ + +/** + * Controller Rule Action. + * + * type: The Rule Action type. + * line: The line number where the Rule Action begins. + * status: The last execution status of the Rule Action. + * parameters: All parameters associated with the Rule Action. + */ +#ifndef _di_controller_rule_action_t_ + typedef struct { + uint8_t type; + f_number_unsigned_t line; + f_status_t status; + + f_string_dynamics_t parameters; + f_iki_datas_t ikis; + } controller_rule_action_t; + + #define controller_rule_action_t_initialize { \ + 0, \ + 0, \ + F_known_not, \ + f_string_dynamics_t_initialize, \ + f_iki_datas_t_initialize, \ + } +#endif // _di_controller_rule_action_t_ + +/** + * Controller Rule Actions. + * + * array: An array of Rule Actions. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_controller_rule_actions_t_ + typedef struct { + controller_rule_action_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } controller_rule_actions_t; + + #define controller_rule_actions_t_initialize { \ + 0, \ + 0, \ + 0, \ + } +#endif // _di_controller_rule_actions_t_ + +/** + * Controller Rule Item. + * + * type: The type of the Rule Item. + * with: A bitwise number representing execute "with" options. + * line: The line number where the Rule Item begins. + * reruns: An array designating rerun settings for each execution type available. + * actions: The actions associated with the Rule Item. + */ +#ifndef _di_controller_rule_item_t_ + typedef struct { + uint8_t type; + uint8_t with; + f_number_unsigned_t line; + + f_string_dynamic_t pid_file; + controller_rule_rerun_t reruns[controller_rule_action_execute_type__enum_size_e]; + controller_rule_actions_t actions; + } controller_rule_item_t; + + #define controller_rule_item_t_initialize \ + { \ + 0, \ + 0, \ + 0, \ + f_string_dynamic_t_initialize, \ + { \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + controller_rule_rerun_t_initialize, \ + }, \ + controller_rule_actions_t_initialize, \ + } +#endif // _di_controller_rule_item_t_ + +/** + * Controller Rule Items. + * + * array: An array of Rule Items. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_controller_rule_items_t_ + typedef struct { + controller_rule_item_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } controller_rule_items_t; + + #define controller_rule_items_initialize { \ + 0, \ + 0, \ + 0, \ + } +#endif // _di_controller_rule_items_t_ + +/** + * The Rule "on" values for designating dependencies. + * + * action: The Rule Action type this "on" dependencies are associated with. + * need: The Rule Alias for a required Rule. + * want: The Rule Alias for an optional Rule that is required to succeed if found. + * wish: The Rule Alias for an optional Rule that is not required. + */ +#ifndef _di_controller_rule_on_t_ + typedef struct { + uint8_t action; + + f_string_dynamics_t need; + f_string_dynamics_t want; + f_string_dynamics_t wish; + } controller_rule_on_t; + + #define controller_rule_on_initialize { \ + 0, \ + f_string_dynamics_t_initialize, \ + f_string_dynamics_t_initialize, \ + f_string_dynamics_t_initialize, \ + } +#endif // _di_controller_rule_on_t_ + +/** + * The Rule "on" array. + * + * array: An array of Rule "on" values. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_controller_rule_ons_t_ + typedef struct { + controller_rule_on_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } controller_rule_ons_t; + + #define controller_rule_ons_t_initialize { \ + 0, \ + 0, \ + 0, \ + } +#endif // _di_controller_rule_ons_t_ + +/** + * Controller Rule. + * + * affinity: The cpu affinity to be used when executing the Rule. + * alias: The distinct ID (machine name) of the Rule, such as "service/ssh". + * capability: The capability setting if the Rule "has" a capability. + * cgroup: The control group setting if the Rule "has" a control group. + * define: Any defines (environment variables) made available to the Rule for IKI substitution or just as environment variables. + * engine: The program or path to the program of the scripting engine to use when processing scripts in this Rule. + * engine_arguments: Any arguments to pass to the engine program. + * environment: All environment variables allowed to be exposed to the Rule when processing. + * group: The group ID if the Rule "has" a group. + * groups: A set of group IDs to run the process with (first specified group is the primary group). + * has: Bitwise set of "has" codes representing what the Rule has. + * items: All items associated with the Rule. + * limits: The cpu/resource limits to use when executing the Rule. + * name: A human name for the Rule (does not have to be distinct), such as "Bash Script". + * nice: The niceness value if the Rule "has" nice. + * on: A set of parameters for defining dependencies and how they are needed, wanted, or wished for. + * parameter: Any parameters made available to the Rule for IKI substitution. + * path: The path to the Rule file. + * scheduler: The scheduler setting if the Rule "has" a scheduler. + * status: A set of action-specific success/failure status of the Rule. Each index represents a controller_rule_action_type_* enum value. Index 0 represents a global status. + * timeout_exit: The timeout to wait when exiting the Controller program after sending the terminate signal to send the kill signal. + * timeout_kill: The timeout to wait relating to using a kill signal. + * timeout_start: The timeout to wait relating to starting a process. + * timeout_stop: The timeout to wait relating to stopping a process. + * timestamp: The timestamp when the Rule was loaded. + * user: The User ID if the Rule "has" a user. + */ +#ifndef _di_controller_rule_t_ + typedef struct { + f_status_t status[controller_rule_action_type__enum_size_e]; + + f_number_unsigned_t timeout_kill; + f_number_unsigned_t timeout_start; + f_number_unsigned_t timeout_stop; + + uint8_t has; + int nice; + uid_t user; + gid_t group; + + f_time_spec_t timestamp; + + f_string_dynamic_t alias; + f_string_dynamic_t engine; + f_string_dynamic_t name; + f_string_dynamic_t path; + + f_string_maps_t define; + f_string_maps_t parameter; + + f_string_dynamics_t engine_arguments; + f_string_dynamics_t environment; + + f_int32s_t affinity; + f_capability_t capability; + f_control_group_t cgroup; + f_int32s_t groups; + f_limit_sets_t limits; + f_execute_scheduler_t scheduler; + + controller_rule_ons_t ons; + controller_rule_items_t items; + } controller_rule_t; + + #define controller_rule_t_initialize { \ + { \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + F_known_not, \ + }, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + f_time_spec_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ + f_string_maps_t_initialize, \ + f_string_maps_t_initialize, \ + f_string_dynamics_t_initialize, \ + f_string_dynamics_t_initialize, \ + f_int32s_t_initialize, \ + f_capability_t_initialize, \ + f_control_group_t_initialize, \ + f_int32s_t_initialize, \ + f_limit_sets_t_initialize, \ + f_execute_scheduler_t_initialize, \ + controller_rule_ons_initialize, \ + controller_rule_items_initialize, \ + } +#endif // _di_controller_rule_t_ + +/** + * Controller Rules. + * + * array: An array of Rules. + * size: Total amount of allocated space. + * used: Total number of allocated spaces used. + */ +#ifndef _di_controller_rules_t_ + typedef struct { + controller_rule_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } controller_rules_t; + + #define controller_rules_t_initialize { \ + 0, \ + 0, \ + 0, \ + } +#endif // _di_controller_rules_t_ + +/** + * Fully deallocate all memory for the given Rule without caring about return status. + * + * @param rule + * The rule to deallocate. + * + * @see controller_rule_items_delete() + * @see controller_rule_ons_delete() + * + * @see f_capability_delete() + * @see f_memory_array_resize() + * @see f_memory_arrays_resize() + */ +#ifndef _di_controller_rule_delete_ + extern void controller_rule_delete(controller_rule_t * const rule); +#endif // _di_controller_rule_delete_ + +/** + * Delete the Controller Rule Action data. + * + * @param action + * The Rule Action data. + * + * @see f_memory_array_resize() + * @see f_memory_arrays_resize() + */ +#ifndef _di_controller_rule_action_delete_ + extern void controller_rule_action_delete(controller_rule_action_t * const action); +#endif // _di_controller_rule_action_delete_ + +/** + * Delete the Controller Rule Actions data. + * + * @param actions + * The Rule Actions data. + * + * @see controller_rule_action_delete() + * + * @see f_memory_array_resize() + */ +#ifndef _di_controller_rule_actions_delete_ + extern void controller_rule_actions_delete(controller_rule_actions_t * const actions); +#endif // _di_controller_rule_actions_delete_ + +/** + * Delete the Controller Rule Item data. + * + * @param item + * The Rule Item data. + * + * @see controller_rule_actions_delete() + * + * @see f_memory_array_resize() + */ +#ifndef _di_controller_rule_item_delete_ + extern void controller_rule_item_delete(controller_rule_item_t * const item); +#endif // _di_controller_rule_item_delete_ + +/** + * Delete the Controller Rule Items data. + * + * @param items + * The Rule Items data. + * + * @see controller_rule_item_delete() + * + * @see f_memory_array_resize() + */ +#ifndef _di_controller_rule_items_delete_ + extern void controller_rule_items_delete(controller_rule_items_t * const items); +#endif // _di_controller_rule_items_delete_ + +/** + * Delete the Controller Rule "on" data. + * + * @param on + * The Rule "on" data. + * + * @see f_memory_arrays_resize() + */ +#ifndef _di_controller_rule_on_delete_ + extern void controller_rule_on_delete(controller_rule_on_t * const on); +#endif // _di_controller_rule_on_delete_ + +/** + * Delete the Controller Rule "ons" data. + * + * @param ons + * The Rule "ons" data. + * + * @see controller_rule_on_delete() + * + * @see f_memory_delete() + */ +#ifndef _di_controller_rule_ons_delete_ + extern void controller_rule_ons_delete(controller_rule_ons_t * const ons); +#endif // _di_controller_rule_ons_delete_ + +/** + * Delete the Controller Rules data. + * + * @param rules + * The Controller Rules data. + * + * @see controller_rules_resize() + */ +#ifndef _di_controller_rules_delete_ + extern void controller_rules_delete(controller_rules_t * const rules); +#endif // _di_controller_rules_delete_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_type_rule_h diff --git a/sources/c/main/controller.h b/sources/c/main/controller.h index 5edeb9c..2610190 100644 --- a/sources/c/main/controller.h +++ b/sources/c/main/controller.h @@ -24,15 +24,20 @@ #include #include #include +#include #include #include -#include #include +#include #include +#include +#include +#include #include #include #include #include +#include #ifndef _di_thread_support_ #include @@ -52,6 +57,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/sources/c/main/print/message.c b/sources/c/main/print/message.c index 6a3ee16..d163d08 100644 --- a/sources/c/main/print/message.c +++ b/sources/c/main/print/message.c @@ -21,7 +21,6 @@ extern "C" { fll_program_print_help_option(print, controller_short_cgroup_s, controller_long_cgroup_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Specify a custom control group file path, such as '" F_control_group_path_system_prefix_s F_control_group_path_system_default_s "'."); fll_program_print_help_option(print, controller_short_daemon_s, controller_long_daemon_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Run in daemon only mode (do not process the entry)."); - fll_program_print_help_option(print, controller_short_init_s, controller_long_init_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " The program will run as an init replacement."); fll_program_print_help_option(print, controller_short_interruptible_s, controller_long_interruptible_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Designate that this program can be interrupted by a signal."); fll_program_print_help_option(print, controller_short_pid_s, controller_long_pid_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Specify a custom pid file path, such as 'controller/run/default.pid'."); fll_program_print_help_option(print, controller_short_settings_s, controller_long_settings_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Specify a custom settings path, such as 'controller/'.");