]> Kevux Git Server - controller/commitdiff
Progress: Continue migrating the project.
authorKevin Day <kevin@kevux.org>
Mon, 15 Apr 2024 04:12:45 +0000 (23:12 -0500)
committerKevin Day <kevin@kevux.org>
Mon, 15 Apr 2024 04:12:45 +0000 (23:12 -0500)
23 files changed:
data/build/settings
sources/c/controller/controller.c
sources/c/controller/controller.h
sources/c/controller/main.c
sources/c/init/init.h
sources/c/init/main.c
sources/c/main/common.c
sources/c/main/common.h
sources/c/main/common/define/thread.h [new file with mode: 0644]
sources/c/main/common/enumeration/thread.h [new file with mode: 0644]
sources/c/main/common/print.c
sources/c/main/common/print.h
sources/c/main/common/type/cache.h
sources/c/main/common/type/control.h
sources/c/main/common/type/entry.h
sources/c/main/common/type/lock.c [new file with mode: 0644]
sources/c/main/common/type/lock.h [new file with mode: 0644]
sources/c/main/common/type/process.c
sources/c/main/common/type/process.h
sources/c/main/common/type/rule.h
sources/c/main/common/type/thread.c [new file with mode: 0644]
sources/c/main/common/type/thread.h [new file with mode: 0644]
sources/c/main/controller.h

index e6bc61c3792abca8c9d57e68397485cb4d6e9089..d1ef3f91f81e8aea20a7033ee14f19b5914d34ff 100644 (file)
@@ -41,16 +41,16 @@ 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/common/type/cache.c main/common/type/control.c main/common/type/entry.c main/common/type/lock.c main/common/type/process.c main/common/type/rule.c main/common/type/thread.c
 build_sources_library main/common/string/general.c main/common/string/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/define/control.h main/common/define/entry.h main/common/define/rule.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/define/control.h main/common/define/entry.h main/common/define/rule.h main/common/define/thread.h
+build_sources_headers main/common/enumeration/control.h main/common/enumeration/entry.h main/common/enumeration/process.h main/common/enumeration/rule.h main/common/enumeration/thread.h
 build_sources_headers main/common/string/general.h main/common/string/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/common/type/cache.h main/common/type/control.h main/common/type/entry.h main/common/type/lock.h main/common/type/process.h main/common/type/rule.h main/common/type/thread.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
 
index 86ae34cec8a0b6a726c015b2350239a2856cf176..579f58bd9d7622d3c8221548f68c681656453fc9 100644 (file)
@@ -5,9 +5,9 @@ extern "C" {
 #endif
 
 #ifndef _di_controller_controller_main_
-  void controller_controller_main(controller_main_t * const main) {
+  void controller_controller_main(controller_main_t * const main, controller_process_t * const process) {
 
-    if (!main) return;
+    if (!main || !process) return;
 
     if (F_status_is_error(main->setting.state.status)) {
       if ((main->setting.flag & controller_main_flag_print_last_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
index a1e4fd6153358b24cd4634993c069021d463d0d3..000a2b63db89a0117354d85a767a5d75962247a4 100644 (file)
@@ -38,6 +38,7 @@
 #include <fll/level_0/execute.h>
 #include <fll/level_0/iki.h>
 #include <fll/level_0/limit.h>
+#include <fll/level_0/path.h>
 #include <fll/level_0/pipe.h>
 #include <fll/level_0/print.h>
 #include <fll/level_0/rip.h>
 #include <program/controller/main/common/define/control.h>
 #include <program/controller/main/common/define/entry.h>
 #include <program/controller/main/common/define/rule.h>
+#include <program/controller/main/common/define/thread.h>
 #include <program/controller/main/common/enumeration/control.h>
 #include <program/controller/main/common/enumeration/entry.h>
 #include <program/controller/main/common/enumeration/rule.h>
 #include <program/controller/main/common/enumeration/process.h>
+#include <program/controller/main/common/enumeration/thread.h>
 #include <program/controller/main/common/type/cache.h>
 #include <program/controller/main/common/type/control.h>
 #include <program/controller/main/common/type/entry.h>
+#include <program/controller/main/common/type/lock.h>
 #include <program/controller/main/common/type/rule.h>
 #include <program/controller/main/common/type/process.h>
+#include <program/controller/main/common/type/thread.h>
 #include <program/controller/main/common/type.h>
 #include <program/controller/main/common.h>
 #include <program/controller/main/print/data.h>
@@ -106,6 +111,8 @@ extern "C" {
  * @param main
  *   The main program data and settings.
  *
+ *   Must not be NULL.
+ *
  *   This alters main.setting.state.status:
  *     F_okay on success.
  *     F_true on success when performing verification and verify passed.
@@ -113,9 +120,13 @@ extern "C" {
  *     F_interrupt on (exit) signal received.
  *
  *     F_parameter (with error bit) if main is NULL or setting is NULL.
+ * @param process
+ *   A pointer to the current process settings.
+ *
+ *   Must not be NULL.
  */
 #ifndef _di_controller_controller_main_
-  extern void controller_controller_main(controller_main_t * const main);
+  extern void controller_controller_main(controller_main_t * const main, controller_process_t * const process);
 #endif // _di_controller_controller_main_
 
 #ifdef __cplusplus
index 4483d448977b78f2b64723a31812e527f474e972..01ef621b91430d1101ee52d4bd594767016f80ef 100644 (file)
@@ -3,6 +3,7 @@
 int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   controller_main_t data = controller_main_t_initialize;
+  controller_process_t process = controller_process_t_initialize;
 
   data.program.debug.flag |= controller_print_flag_debug_e | controller_print_flag_out_e;
   data.program.error.flag |= controller_print_flag_error_e | controller_print_flag_out_e;
@@ -33,10 +34,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
     {
       const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp);
 
-      controller_main_setting_load(arguments, &data);
+      controller_main_setting_load(arguments, &data, &process);
     }
 
-    controller_controller_main(&data);
+    controller_controller_main(&data, &process);
   #else
     {
       f_thread_id_t id_signal;
@@ -52,11 +53,11 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
         {
           const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp);
 
-          controller_main_setting_load(arguments, &data);
+          controller_main_setting_load(arguments, &data, &process);
         }
 
         if (!controller_main_signal_check(&data)) {
-          controller_controller_main(&data);
+          controller_controller_main(&data, &process);
         }
 
         f_thread_cancel(id_signal);
index 5717cf29dfd36fbb4db464d6a27b43b4e4d19f16..f47ded6e4289e59da272a9f9b38b4e91e5c255d0 100644 (file)
@@ -38,6 +38,7 @@
 #include <fll/level_0/execute.h>
 #include <fll/level_0/iki.h>
 #include <fll/level_0/limit.h>
+#include <fll/level_0/path.h>
 #include <fll/level_0/pipe.h>
 #include <fll/level_0/print.h>
 #include <fll/level_0/rip.h>
 #include <program/controller/main/common/define/control.h>
 #include <program/controller/main/common/define/entry.h>
 #include <program/controller/main/common/define/rule.h>
+#include <program/controller/main/common/define/thread.h>
 #include <program/controller/main/common/enumeration/control.h>
 #include <program/controller/main/common/enumeration/entry.h>
 #include <program/controller/main/common/enumeration/rule.h>
 #include <program/controller/main/common/enumeration/process.h>
+#include <program/controller/main/common/enumeration/thread.h>
 #include <program/controller/main/common/type/cache.h>
 #include <program/controller/main/common/type/control.h>
 #include <program/controller/main/common/type/entry.h>
+#include <program/controller/main/common/type/lock.h>
 #include <program/controller/main/common/type/rule.h>
 #include <program/controller/main/common/type/process.h>
+#include <program/controller/main/common/type/thread.h>
 #include <program/controller/main/common/type.h>
 #include <program/controller/main/common.h>
 #include <program/controller/main/print/data.h>
index 1aff3da60c58a7400940a4371b97063f7060db6d..aeee890ffaea6ab54ee3fd548a96c3cda97f0b0f 100644 (file)
@@ -3,6 +3,7 @@
 int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
 
   controller_main_t data = controller_main_t_initialize;
+  controller_process_t process = controller_process_t_initialize;
 
   data.program.debug.flag |= controller_print_flag_debug_e | controller_print_flag_out_e;
   data.program.error.flag |= controller_print_flag_error_e | controller_print_flag_out_e;
@@ -33,7 +34,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
     {
       const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp);
 
-      controller_main_setting_load(arguments, &data);
+      controller_main_setting_load(arguments, &data, &process);
     }
 
     controller_init_main(&data);
@@ -52,7 +53,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) {
         {
           const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp);
 
-          controller_main_setting_load(arguments, &data);
+          controller_main_setting_load(arguments, &data, &process);
         }
 
         if (!controller_main_signal_check(&data)) {
index 8c1f8a369fc0366fe75674b524097db6c4f65a49..cadd124885d3ee506712200598a53ab8604ed33e 100644 (file)
@@ -5,7 +5,7 @@ extern "C" {
 #endif
 
 #ifndef _di_controller_main_setting_load_
-  void controller_main_setting_load(const f_console_arguments_t arguments, controller_main_t * const main) {
+  void controller_main_setting_load(const f_console_arguments_t arguments, controller_main_t * const main, controller_process_t * const process) {
 
     if (!main) return;
 
@@ -87,6 +87,39 @@ extern "C" {
     else {
       main->setting.flag &= ~controller_main_flag_pipe_e;
     }
+
+    f_string_static_t * const args = main->program.parameters.arguments.array;
+
+    process->control.server.domain = f_socket_protocol_family_local_e;
+    process->control.server.type = f_socket_type_stream_e;
+    process->control.server.form = f_socket_address_form_local_e;
+
+    memset(&process->control.server.address, 0, sizeof(f_socket_address_t));
+
+    // The first remaining argument represents the entry name.
+    main->setting.state.status = f_string_dynamic_append(main->program.parameters.remaining.used ? args[main->program.parameters.remaining.array[0]] : controller_default_s, &process->name_entry);
+
+    if (F_status_is_error(main->setting.state.status)) {
+      if ((main->setting.flag & controller_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+        fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+      }
+
+      controller_main_print_error(&main->program.error, macro_controller_f(fll_program_parameter_process_verbosity_standard));
+
+      return;
+    }
+
+    main->setting.state.status = f_path_current(F_false, &process->path_current);
+
+    if (F_status_is_error(main->setting.state.status)) {
+      if ((main->setting.flag & controller_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+        fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+      }
+
+      controller_main_print_error(&main->program.error, macro_controller_f(f_path_current));
+
+      return;
+    }
   }
 #endif // _di_controller_main_setting_load_
 
index 9d1a594ecb47a04da46da2940dcf20cd4d71c689..1ed85821af3031a60de17607ac7acc0bed60437e 100644 (file)
@@ -33,12 +33,16 @@ extern "C" {
  *
  *     Errors (with error bit) from: f_console_parameter_process().
  *     Errors (with error bit) from: fll_program_parameter_process_context().
+ * @param process
+ *   A pointer to the current process settings.
+ *
+ *   Must not be NULL.
  *
  * @see f_console_parameter_process()
  * @see fll_program_parameter_process_context()
  */
 #ifndef _di_controller_main_setting_load_
-  extern void controller_main_setting_load(const f_console_arguments_t arguments, controller_main_t * const main);
+  extern void controller_main_setting_load(const f_console_arguments_t arguments, controller_main_t * const main, controller_process_t * const process);
 #endif // _di_controller_main_setting_load_
 
 #ifdef __cplusplus
diff --git a/sources/c/main/common/define/thread.h b/sources/c/main/common/define/thread.h
new file mode 100644 (file)
index 0000000..0a72c81
--- /dev/null
@@ -0,0 +1,62 @@
+/**
+ * FLL - Level 3
+ *
+ * Project: Controller
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Provides the common thread defines.
+ *
+ * This is auto-included and should not need to be explicitly included.
+ */
+#ifndef _controller_main_common_define_thread_h
+#define _controller_main_common_define_thread_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Thread related defines.
+ */
+#ifndef _di_controller_thread_d_
+  #define controller_thread_cleanup_interval_long_d     3600      // 1 hour in seconds.
+  #define controller_thread_cleanup_interval_short_d    180       // 3 minutes in seconds.
+  #define controller_thread_exit_timeout_d              500       // 0.5 seconds in milliseconds.
+  #define controller_thread_exit_process_cancel_wait_d  600000000 // 0.6 seconds in nanoseconds.
+  #define controller_thread_exit_process_cancel_total_d 150       // 90 seconds in multiples of wait.
+  #define controller_thread_simulation_timeout_d        200       // 0.2 seconds in milliseconds.
+
+  #define controller_thread_signal_wait_timeout_seconds_d     70
+  #define controller_thread_signal_wait_timeout_nanoseconds_d 0
+
+  #define controller_thread_lock_read_timeout_seconds_d      3
+  #define controller_thread_lock_read_timeout_nanoseconds_d  0
+  #define controller_thread_lock_write_timeout_seconds_d     3
+  #define controller_thread_lock_write_timeout_nanoseconds_d 0
+
+  #define controller_thread_wait_timeout_1_before_d 4
+  #define controller_thread_wait_timeout_2_before_d 12
+  #define controller_thread_wait_timeout_3_before_d 28
+
+  #define controller_thread_wait_timeout_1_seconds_d     0
+  #define controller_thread_wait_timeout_1_nanoseconds_d 20000000  // 0.02 seconds in nanoseconds.
+  #define controller_thread_wait_timeout_2_seconds_d     0
+  #define controller_thread_wait_timeout_2_nanoseconds_d 200000000 // 0.2 seconds in nanoseconds.
+  #define controller_thread_wait_timeout_3_seconds_d     2
+  #define controller_thread_wait_timeout_3_nanoseconds_d 0
+  #define controller_thread_wait_timeout_4_seconds_d     20
+  #define controller_thread_wait_timeout_4_nanoseconds_d 0
+
+  #define controller_thread_exit_helper_timeout_seconds_d     0
+  #define controller_thread_exit_helper_timeout_nanoseconds_d 100000000 // 0.1 seconds in nanoseconds.
+
+  #define controller_thread_exit_ready_timeout_seconds_d     0
+  #define controller_thread_exit_ready_timeout_nanoseconds_d 500000000 // 0.5 seconds in nanoseconds.
+#endif // _di_controller_thread_d_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _controller_main_common_define_thread_h
diff --git a/sources/c/main/common/enumeration/thread.h b/sources/c/main/common/enumeration/thread.h
new file mode 100644 (file)
index 0000000..5be6ec6
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * FLL - Level 3
+ *
+ * Project: Controller
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Provides the common thread enumerations.
+ *
+ * This is auto-included and should not need to be explicitly included.
+ */
+#ifndef _controller_main_common_enumeration_thread_h
+#define _controller_main_common_enumeration_thread_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+  /**
+   * States for the thread, designating how to stop the process.
+   *
+   * controller_thread_*_e:
+   *   - enabled_not:          The controller is no longer enabled, shut down and abort all work.
+   *   - enabled:              The controller is operating normally.
+   *   - enabled_execute:      The controller is executing another process, all running operations must terminate.
+   *   - enabled_exit:         The controller is shutting down, only process exit rules.
+   *   - enabled_exit_execute: The controller is executing another process while in failsafe mode, all running operations must terminate.
+   *   - enabled_exit_ready:   The controller is shutting down, only process exit rules, and now ready to send termination signals.
+   */
+  enum {
+    controller_thread_enabled_not_e = 0,
+    controller_thread_enabled_e,
+    controller_thread_enabled_execute_e,
+    controller_thread_enabled_exit_e,
+    controller_thread_enabled_exit_execute_e,
+    controller_thread_enabled_exit_ready_e,
+  }; // enum
+
+  /**
+   * States for the thread, designating how the process is cancelled.
+   *
+   * controller_thread_cancel_*_e:
+   *   - signal:       Cancellation is triggered by a signal.
+   *   - call:         Cancellation is explicitly called.
+   *   - execute:      Cancellation is explicitly called due to an "execute" Item Action, when not during Exit.
+   *   - exit:         Cancellation is explicitly called during Exit.
+   *   - exit_execute: Cancellation is explicitly called due to an "execute" Item Action during Exit.
+   */
+  enum {
+    controller_thread_cancel_signal_e = 0,
+    controller_thread_cancel_call_e,
+    controller_thread_cancel_execute_e,
+    controller_thread_cancel_exit_e,
+    controller_thread_cancel_exit_execute_e,
+  }; // enum
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _controller_main_common_enumeration_thread_h
index 484125e8e290d71af9061e6b564f066132fd55e8..a259bf2ef6a88ddd07d120c25da55fa9a068070a 100644 (file)
@@ -7,6 +7,8 @@ extern "C" {
 #ifndef _di_controller_f_a_
   const f_string_t controller_f_a[] = {
     "f_console_parameter_process",
+    "f_path_current",
+    "f_string_dynamic_append",
     "f_thread_create",
     "fll_program_parameter_process_context_standard",
     "fll_program_parameter_process_verbosity_standard",
index 3d489678016afefd15af38e1cec204086c65f164..df22450b36c4693978ca17f8566506512ce6ea74 100644 (file)
@@ -40,6 +40,8 @@ extern "C" {
 #ifndef _di_controller_f_e_
   enum {
     controller_f_f_console_parameter_process_e,
+    controller_f_f_path_current_e,
+    controller_f_f_string_dynamic_append_e,
     controller_f_f_thread_create_e,
     controller_f_fll_program_parameter_process_context_standard_e,
     controller_f_fll_program_parameter_process_verbosity_standard_e,
index 9833033f0c124424a45e27881086a2ad4ee9f912..342155f6a862f6db810ee07968a124384f5cb76e 100644 (file)
@@ -5,7 +5,7 @@
  * API Version: 0.7
  * Licenses: lgpl-2.1-or-later
  *
- * Provides the common type cache structures.
+ * Provides the common cache type structures.
  *
  * This is auto-included and should not need to be explicitly included.
  */
index 23aa30d7735b8d94e2ea96c5f49a43a9728263eb..17fbf402673d244bb4575f4e41b8fd52df9fd6b6 100644 (file)
@@ -5,7 +5,7 @@
  * API Version: 0.7
  * Licenses: lgpl-2.1-or-later
  *
- * Provides the common type control structures.
+ * Provides the common control type structures.
  *
  * This is auto-included and should not need to be explicitly included.
  */
@@ -19,23 +19,24 @@ extern "C" {
 /**
  * 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.
+ * 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;
@@ -49,8 +50,6 @@ extern "C" {
 
     f_string_dynamic_t input;
     f_string_dynamic_t output;
-
-    struct sockaddr_un address;
   } controller_control_t;
 
   #define controller_control_t_initialize { \
@@ -65,7 +64,6 @@ extern "C" {
     f_string_dynamic_t_initialize, \
     f_string_dynamic_t_initialize, \
     f_string_dynamic_t_initialize, \
-    { }, \
   }
 #endif // _di_controller_control_t_
 
index c966a05bfa067ec1f06f362e90768af46d4f0d1a..e4874da1a4f034f0f698f543797afa9ed8bd3aa3 100644 (file)
@@ -5,7 +5,7 @@
  * API Version: 0.7
  * Licenses: lgpl-2.1-or-later
  *
- * Provides the common type entry structures.
+ * Provides the common entry type structures.
  *
  * This is auto-included and should not need to be explicitly included.
  */
diff --git a/sources/c/main/common/type/lock.c b/sources/c/main/common/type/lock.c
new file mode 100644 (file)
index 0000000..563cf6e
--- /dev/null
@@ -0,0 +1,59 @@
+#include "../../controller.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _di_controller_lock_delete_mutex_
+  void controller_lock_delete_mutex(f_thread_mutex_t *mutex) {
+
+    const f_status_t status = f_thread_mutex_delete(mutex);
+
+    if (F_status_is_error(status)) {
+      if (F_status_set_fine(status) == F_busy) {
+        if (f_thread_mutex_delete(mutex) == F_okay) {
+          mutex = 0;
+        }
+      }
+    }
+    else {
+      mutex = 0;
+    }
+  }
+#endif // _di_controller_lock_delete_mutex_
+
+#ifndef _di_controller_lock_delete_rw_
+  void controller_lock_delete_rw(f_thread_lock_t *lock) {
+
+    const f_status_t status = f_thread_lock_delete(lock);
+
+    if (F_status_is_error(status)) {
+      if (F_status_set_fine(status) == F_busy) {
+        if (f_thread_lock_delete(lock) == F_okay) {
+          lock = 0;
+        }
+      }
+    }
+    else {
+      lock = 0;
+    }
+  }
+#endif // _di_controller_lock_delete_rw_
+
+#ifndef _di_controller_lock_delete_
+  void controller_lock_delete(controller_lock_t * const lock) {
+
+    controller_lock_delete_mutex(&lock->alert);
+    controller_lock_delete_mutex(&lock->cancel);
+    controller_lock_delete_mutex(&lock->print);
+
+    controller_lock_delete_rw(&lock->process);
+    controller_lock_delete_rw(&lock->rule);
+
+    f_thread_condition_delete(&lock->alert_condition);
+  }
+#endif // _di_controller_lock_delete_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/sources/c/main/common/type/lock.h b/sources/c/main/common/type/lock.h
new file mode 100644 (file)
index 0000000..9bd5a90
--- /dev/null
@@ -0,0 +1,103 @@
+/**
+ * FLL - Level 3
+ *
+ * Project: Controller
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Provides the common lock type structures.
+ *
+ * This is auto-included and should not need to be explicitly included.
+ */
+#ifndef _controller_main_common_type_lock_h
+#define _controller_main_common_type_lock_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+/**
+ * A structure for sharing mutexes globally between different threads.
+ *
+ * The alert lock is intended for a generic waiting on alerts operations.
+ * The cancel lock is intended for preventing double cancellation calls (which can happen due to interrupts).
+ * The print lock is intended to lock any activity printing to stdout/stderr.
+ * The process lock is intended to lock any activity on the process structure.
+ * The rule lock is intended to lock any activity on the rules structure.
+ *
+ * alert:           The alert mutex lock for waking up on alerts.
+ * cancel:          The cancel mutex lock for locking the cancel operation.
+ * print:           The print mutex lock.
+ * process:         The process r/w lock.
+ * rule:            The rule r/w lock.
+ * alert_condition: The condition used to trigger alerts.
+ */
+#ifndef _di_controller_lock_t_
+  typedef struct {
+    f_thread_mutex_t alert;
+    f_thread_mutex_t cancel;
+    f_thread_mutex_t print;
+
+    f_thread_lock_t process;
+    f_thread_lock_t rule;
+
+    f_thread_condition_t alert_condition;
+  } controller_lock_t;
+
+  #define controller_lock_t_initialize { \
+    f_thread_mutex_t_initialize, \
+    f_thread_mutex_t_initialize, \
+    f_thread_mutex_t_initialize, \
+    f_thread_lock_t_initialize, \
+    f_thread_lock_t_initialize, \
+    f_thread_condition_t_initialize, \
+  }
+#endif // _di_controller_lock_t_
+
+/**
+ * Delete the mutex lock and if the mutex lock is busy, forcibly unlock it and then delete it.
+ *
+ * @param mutex
+ *   The mutex lock to delete.
+ *   Will be set to NULL if delete succeeded.
+ *
+ *   This pointer cannot be "* const" because of pthread_mutex_destroy().
+ *
+ * @see f_thread_mutex_delete()
+ */
+#ifndef _di_controller_lock_delete_mutex_
+  extern void controller_lock_delete_mutex(f_thread_mutex_t *mutex);
+#endif // _di_controller_lock_delete_mutex_
+
+/**
+ * Delete the r/w lock and if the r/w lock is busy, forcibly unlock it and then delete it.
+ *
+ * @param lock
+ *   The r/w lock to delete.
+ *   Will be set to NULL if delete succeeded.
+ *
+ *   This pointer cannot be "* const" because of pthread_rwlock_destroy().
+ *
+ * @see f_thread_lock_delete()
+ */
+#ifndef _di_controller_lock_delete_rw_
+  extern void controller_lock_delete_rw(f_thread_lock_t *lock);
+#endif // _di_controller_lock_delete_rw_
+
+/**
+ * Fully deallocate all memory for the given lock without caring about return status.
+ *
+ * @param lock
+ *   The lock to deallocate.
+ *
+ * @see f_thread_lock_delete()
+ * @see f_thread_mutex_delete()
+ */
+#ifndef _di_controller_lock_delete_
+  extern void controller_lock_delete(controller_lock_t * const lock);
+#endif // _di_controller_lock_delete_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _controller_main_common_type_lock_h
index 7289a1dab69e8ea0a9fe40036901e8b8e8eb2d83..f2b4b0036171623e204e58d3568dce780280bfc6 100644 (file)
@@ -16,13 +16,12 @@ extern "C" {
     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_control_delete(&process->control);
     controller_entry_items_delete(&process->entry.items);
     controller_entry_items_delete(&process->exit.items);
 
index ea96a6349a5dbbc67c8a07b1fd73c2fff441ab96..170d610d057ddf439f2707e3e8136ed236b85237 100644 (file)
@@ -5,7 +5,7 @@
  * API Version: 0.7
  * Licenses: lgpl-2.1-or-later
  *
- * Provides the common type process structures.
+ * Provides the common process type structures.
  *
  * This is auto-included and should not need to be explicitly included.
  */
@@ -19,16 +19,22 @@ extern "C" {
 /**
  * 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.
+ * 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.
+ *
  * 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.
+ *
+ * name_entry:   The name of the entry file.
+ * path_cgroup:  Directory path to the cgroup directory.
+ * path_control: File path to the control socket (used for printing the path).
+ * path_current: The current path.
+ * path_pid:     File path to the PID file.
+ * path_setting: File path to the setting directory.
+ *
+ * control: The control socket data.
+ * entry:   The Entry settings.
+ * exit:    The Exit settings.
+ * rules:   All rules and their respective settings.
  */
 #ifndef _di_controller_process_t_
   typedef struct {
@@ -37,16 +43,14 @@ extern "C" {
 
     f_number_unsigned_t failsafe_item_id;
 
-    controller_control_t control;
-
+    f_string_dynamic_t name_entry;
     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_control_t control;
     controller_entry_t entry;
     controller_entry_t exit;
     controller_rules_t rules;
@@ -56,14 +60,13 @@ extern "C" {
     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_control_t_initialize, \
     controller_entry_t_initialize, \
     controller_entry_t_initialize, \
     controller_rules_t_initialize, \
index 13fb4c086c00529e7cbdae3e15ac57893081709f..2ffcbac42d76528d3ebad4b92e4ca4412eb715ef 100644 (file)
@@ -5,7 +5,7 @@
  * API Version: 0.7
  * Licenses: lgpl-2.1-or-later
  *
- * Provides the common type rules structures.
+ * Provides the common rules type structures.
  *
  * This is auto-included and should not need to be explicitly included.
  */
diff --git a/sources/c/main/common/type/thread.c b/sources/c/main/common/type/thread.c
new file mode 100644 (file)
index 0000000..00cf7b6
--- /dev/null
@@ -0,0 +1,18 @@
+#include "../../controller.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _di_controller_thread_delete_simple_
+  void controller_thread_delete_simple(controller_thread_t * const thread) {
+
+    controller_lock_delete(&thread->lock);
+    controller_process_delete(&thread->process);
+    controller_cache_delete(&thread->cache);
+  }
+#endif // _di_controller_thread_delete_simple_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/sources/c/main/common/type/thread.h b/sources/c/main/common/type/thread.h
new file mode 100644 (file)
index 0000000..41c2fc7
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+ * FLL - Level 3
+ *
+ * Project: Controller
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Provides the common thread type structures.
+ *
+ * This is auto-included and should not need to be explicitly included.
+ */
+#ifndef _controller_main_common_type_thread_h
+#define _controller_main_common_type_thread_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * A structure for managing threads.
+ *
+ * This is essentially data shared globally between threads, about threads.
+ *
+ * The "enabled" and "signal" utilize the lock: lock.process.
+ *
+ * enabled: TRUE when threads are active, FALSE when inactive and the program is essentially shutting down, no new threads should be started when FALSE.
+ * signal:  The code of any signal received.
+ * status:  A status used by the main entry/rule processing thread for synchronous operations.
+ *
+ * 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_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.
+ * process: All Rule Process thread data.
+ * cache:    A cache used by the main entry/rule processing thread for synchronous operations.
+ */
+#ifndef _di_controller_thread_t_
+  typedef struct {
+    uint8_t enabled;
+    int signal;
+    f_status_t status;
+
+    f_thread_id_t id_cleanup;
+    f_thread_id_t id_control;
+    f_thread_id_t id_entry;
+    f_thread_id_t id_rule;
+    f_thread_id_t id_signal;
+
+    controller_lock_t lock;
+    controller_process_t process;
+    controller_cache_t cache;
+  } controller_thread_t;
+
+  #define controller_thread_t_initialize { \
+    controller_thread_enabled_e, \
+    0, \
+    F_none, \
+    f_thread_id_t_initialize, \
+    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, \
+  }
+#endif // _di_controller_thread_t_
+
+/**
+ * Fully deallocate all memory for the given setting without caring about return status.
+ *
+ * @param thread
+ *   The thread to deallocate.
+ *
+ * @see controller_asynchronouss_resize()
+ * @see f_thread_mutex_unlock()
+ */
+#ifndef _di_controller_thread_delete_simple_
+  extern void controller_thread_delete_simple(controller_thread_t * const thread);
+#endif // _di_controller_thread_delete_simple_
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _controller_main_common_type_thread_h
index f7103908e930294e4fca9949b2d1f3090b27a490..73de6cc282d0cd2dc1875d5f4f0234f2a5fcf9f5 100644 (file)
@@ -38,6 +38,7 @@
 #include <fll/level_0/execute.h>
 #include <fll/level_0/iki.h>
 #include <fll/level_0/limit.h>
+#include <fll/level_0/path.h>
 #include <fll/level_0/pipe.h>
 #include <fll/level_0/print.h>
 #include <fll/level_0/rip.h>
 #include <program/controller/main/common/define/control.h>
 #include <program/controller/main/common/define/entry.h>
 #include <program/controller/main/common/define/rule.h>
+#include <program/controller/main/common/define/thread.h>
 #include <program/controller/main/common/enumeration/control.h>
 #include <program/controller/main/common/enumeration/entry.h>
 #include <program/controller/main/common/enumeration/rule.h>
 #include <program/controller/main/common/enumeration/process.h>
+#include <program/controller/main/common/enumeration/thread.h>
 #include <program/controller/main/common/type/cache.h>
 #include <program/controller/main/common/type/control.h>
 #include <program/controller/main/common/type/entry.h>
+#include <program/controller/main/common/type/lock.h>
 #include <program/controller/main/common/type/rule.h>
 #include <program/controller/main/common/type/process.h>
+#include <program/controller/main/common/type/thread.h>
 #include <program/controller/main/common/type.h>
 #include <program/controller/main/common.h>
 #include <program/controller/main/print/data.h>