]> Kevux Git Server - controller/commitdiff
Progress: Continue migrating the project.
authorKevin Day <Kevin@kevux.org>
Fri, 28 Jun 2024 03:59:42 +0000 (22:59 -0500)
committerKevin Day <Kevin@kevux.org>
Fri, 28 Jun 2024 03:59:42 +0000 (22:59 -0500)
sources/c/main/print/error/lock.c
sources/c/main/print/error/perform/pid.h
sources/c/main/print/error/rule.c
sources/c/main/print/error/rule.h
sources/c/main/print/error/rule/action.c
sources/c/main/print/error/rule/action.h
sources/c/main/print/error/rule/item.c
sources/c/main/rule/instance.c

index ee0789f5622a39710650ade4b81e622eb6e4ab64..3face961650c02e6e519b714fb2217032bcd7926 100644 (file)
@@ -7,7 +7,6 @@ extern "C" {
 #ifndef _di_controller_print_error_lock_critical_
   f_status_t controller_print_error_lock_critical(fl_print_t * const print, const f_status_t status, const uint8_t is_read) {
 
-    // A signal is not an error.
     if (!print || !print->custom) return F_status_set_error(F_output_not);
     if (print->verbosity < f_console_verbosity_error_e || status == F_interrupt) return F_output_not;
 
index c13c2bf603b4b88662cb1070da33a94cfdcd5ec3..88a8c6c5fdbc5d86d5256959ed0beb2533377d73 100644 (file)
@@ -25,6 +25,8 @@ extern "C" {
  *   This requires print.custom to be controller_t.
  *
  *   This does not alter print.custom.setting.state.status.
+ *
+ *   Must not be NULL.
  * @param status
  *   The status code to process.
  *   Make sure this has F_status_set_fine() called if the status code has any error or warning bits.
index c9a4644ad90a8d0d530476a843581289ab817ab2..56dfe75153e825dfc42bffd997ec6d31a1a8e3ed 100644 (file)
@@ -62,6 +62,28 @@ extern "C" {
   }
 #endif // _di_controller_print_error_rule_cache_
 
+#ifndef _di_controller_print_error_rule_stack_already_
+  f_status_t controller_print_error_rule_stack_already(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const uint8_t item) {
+
+    if (!print || !print->custom || !action) return F_status_set_error(F_output_not);
+    if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
+
+    controller_t * const main = (controller_t *) print->custom;
+
+    controller_lock_print(print->to, &main->thread);
+
+    fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context);
+    fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, name, print->notable);
+    fl_print_format("%[' is already on the execution dependency stack, this recursion is prohibited.%]%r", print->to, print->context, print->context, f_string_eol_s);
+
+    controller_print_error_rule_cache(print, action, item);
+
+    controller_unlock_print_flush(print->to, &main->thread);
+
+    return F_okay;
+  }
+#endif // _di_controller_print_error_rule_stack_already_
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
index 23aa856df65c7d0c54a1cb66b42f7440fffc1808..11931633627b817f1139984c6c523d56cdf05409 100644 (file)
@@ -88,6 +88,37 @@ extern "C" {
   extern f_status_t controller_print_error_rule_cache(fl_print_t * const print, controller_cache_action_t * const action, const uint8_t item);
 #endif // _di_controller_print_error_rule_cache_
 
+/**
+ * Print error regarding the rule already being on the execution stack.
+ *
+ * @param print
+ *   The output structure to print to.
+ *
+ *   This requires print.custom to be controller_t.
+ *
+ *   This does not alter print.custom.setting.state.status.
+ *
+ *   Must not be NULL.
+ * @param action
+ *   The action cache.
+ *
+ *   Must not be NULL.
+ * @param name
+ *   The rule name.
+ * @param item
+ *   If TRUE, then this error is associated with an item.
+ *   If FALSE, then this error is associated with a rule setting.
+ *
+ * @return
+ *   F_okay on success.
+ *   F_output_not on success, but no printing is performed.
+ *
+ *   F_output_not (with error bit) if setting is NULL.
+ */
+#ifndef _di_controller_print_error_rule_stack_already_
+  extern f_status_t controller_print_error_rule_stack_already(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const uint8_t item);
+#endif // _di_controller_print_error_rule_stack_already_
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
index ddb61f3041fa3d6122efba4c111e681b1caacb5c..186202793fec54293cc0676f7a0b949e29bb4fde 100644 (file)
@@ -7,16 +7,86 @@ extern "C" {
 #ifndef _di_controller_print_error_rule_action_missing_pid_
   f_status_t controller_print_error_rule_action_missing_pid(fl_print_t * const print, const f_string_static_t alias) {
 
+    if (!print || !print->custom) return F_status_set_error(F_output_not);
     if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
 
+    controller_t * const main = (controller_t *) print->custom;
+
+    controller_lock_print(print->to, &main->thread);
+
     fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context);
     fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, alias, print->notable);
     fl_print_format("%[' is not designating a pid file.%]%r", print->to, print->context, print->context, f_string_eol_s);
 
+    controller_unlock_print_flush(print->to, &main->thread);
+
     return F_okay;
   }
 #endif // _di_controller_print_error_rule_action_missing_pid_
 
+#ifndef _di_controller_print_error_rule_action_type_supported_not_
+  f_status_t controller_print_error_rule_action_type_supported_not(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t type) {
+
+    if (!print || !print->custom || !action) return F_status_set_error(F_output_not);
+    if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
+
+    controller_t * const main = (controller_t *) print->custom;
+
+    controller_lock_print(print->to, &main->thread);
+
+    fl_print_format("%r%[%QUnsupported action type '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context);
+    fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, type, print->notable);
+    fl_print_format("%[' while attempting to execute rule.%]%r", print->to, print->context, print->context, f_string_eol_s);
+
+    controller_print_error_rule_cache(print, action, F_true);
+
+    controller_unlock_print_flush(print->to, &main->thread);
+
+    return F_okay;
+  }
+#endif // _di_controller_print_error_rule_action_type_supported_not_
+
+#ifndef _di_controller_print_error_rule_action_unknown_execute_
+  f_status_t controller_print_error_rule_action_unknown_execute(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const f_string_static_t type, const f_number_unsigned_t total) {
+
+    if (!print || !print->custom) return F_status_set_error(F_output_not);
+    if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
+
+    controller_t * const main = (controller_t *) print->custom;
+
+    controller_lock_print(print->to, &main->thread);
+
+    if (total) {
+      fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context);
+      fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, name, print->notable);
+      fl_print_format("%[' has no '%]", print->to, print->context, print->context);
+      fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, type, print->notable);
+      fl_print_format("%[' action to execute.%]%r", print->to, print->context, print->context, f_string_eol_s);
+    }
+    else {
+      fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context);
+      fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, name, print->notable);
+      fl_print_format("%[ has no known '%]", print->to, print->context, print->context);
+      fl_print_format("%[%r %r%]", print->to, print->notable, controller_rule_s, controller_type_s, print->notable);
+      fl_print_format("%[' (such as '%]", print->to, print->context, print->context);
+      fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_command_s, print->notable);
+      fl_print_format("%[', '%]", print->to, print->context, print->context);
+      fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_service_s, print->notable);
+      fl_print_format("%[', '%]", print->to, print->context, print->context);
+      fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_script_s, print->notable);
+      fl_print_format("%[', or '%]", print->to, print->context, print->context);
+      fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_utility_s, print->notable);
+      fl_print_format("%[') to execute.%]%r", print->to, print->context, print->context, f_string_eol_s);
+    }
+
+    controller_print_error_rule_cache(print, action, F_true);
+
+    controller_unlock_print_flush(print->to, &main->thread);
+
+    return F_okay;
+  }
+#endif // _di_controller_print_error_rule_action_unknown_execute_
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
index e933fb06dbf25f8c0a74ddd592e3ca350c917cb3..0d50391e8f5cfb9ec80aec1f43b7e9fca0356fe9 100644 (file)
@@ -20,7 +20,13 @@ extern "C" {
  * Print an error or warning message about some rule not having the pid file information.
  *
  * @param print
- *   The error or warning output structure.
+ *   The output structure to print to.
+ *
+ *   This requires print.custom to be controller_t.
+ *
+ *   This does not alter print.custom.setting.state.status.
+ *
+ *   Must not be NULL.
  * @param alias
  *   The rule alias of the rule that is missing the pid file designation.
  *
@@ -34,6 +40,64 @@ extern "C" {
   extern f_status_t controller_print_error_rule_action_missing_pid(fl_print_t * const print, const f_string_static_t alias);
 #endif // _di_controller_print_error_rule_action_missing_pid_
 
+/**
+ * Print an error about Rule Action type not being supported.
+ *
+ * @param print
+ *   The output structure to print to.
+ *
+ *   This requires print.custom to be controller_t.
+ *
+ *   This does not alter print.custom.setting.state.status.
+ *
+ *   Must not be NULL.
+ * @param action
+ *   The action cache.
+ *
+ *   Must not be NULL.
+ * @param type
+ *   The Action type name.
+ *
+ * @return
+ *   F_okay on success.
+ *   F_output_not on success, but no printing is performed.
+ *
+ *   F_output_not (with error bit) if setting is NULL.
+ */
+#ifndef _di_controller_print_error_rule_action_type_supported_not_
+  extern f_status_t controller_print_error_rule_action_type_supported_not(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t type);
+#endif // _di_controller_print_error_rule_action_type_supported_not_
+
+/**
+ * Print an error about Rule Action type not being supported.
+ *
+ * @param print
+ *   The output structure to print to.
+ *
+ *   This requires print.custom to be controller_t.
+ *
+ *   This does not alter print.custom.setting.state.status.
+ *
+ *   Must not be NULL.
+ * @param action
+ *   The action cache.
+ *
+ *   Must not be NULL.
+ * @param name
+ *   The Rule name.
+ * @param type
+ *   The Action type name.
+ *
+ * @return
+ *   F_okay on success.
+ *   F_output_not on success, but no printing is performed.
+ *
+ *   F_output_not (with error bit) if setting is NULL.
+ */
+#ifndef _di_controller_print_error_rule_action_unknown_execute_
+  extern f_status_t controller_print_error_rule_action_unknown_execute(fl_print_t * const print, controller_cache_action_t * const action, const f_string_static_t name, const f_string_static_t type, const f_number_unsigned_t total);
+#endif // _di_controller_print_error_rule_action_unknown_execute_
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
index 11156ed5cda0cfe7e94c141d9a3ebc7c93c7d03d..437ba63a9bf8e611b58b51f960fe5fc975f0d6dd 100644 (file)
@@ -7,9 +7,8 @@ extern "C" {
 #ifndef _di_controller_print_error_rule_item_
   f_status_t controller_print_error_rule_item(fl_print_t * const print, controller_cache_action_t * const action, const uint8_t item, const f_status_t status) {
 
-    if (!print || !print->custom || !action) return F_status_set_error(F_output_not);
+    if (!print || !print->custom || !action || status == F_interrupt) return F_status_set_error(F_output_not);
     if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
-    if (status == F_interrupt) return F_status_set_error(F_output_not);
 
     controller_t * const main = (controller_t *) print->custom;
 
@@ -96,6 +95,8 @@ extern "C" {
     controller_print_error_rule_cache(print, &cache->action, F_true);
 
     controller_unlock_print_flush(print->to, &main->thread);
+
+    return F_okay;
   }
 #endif // _di_controller_print_error_rule_item_action_positive_number_not_
 
@@ -405,6 +406,11 @@ extern "C" {
 #ifndef _di_controller_print_error_rule_item_need_want_wish_
   f_status_t controller_print_error_rule_item_need_want_wish(fl_print_t * const print, const f_string_static_t need_want_wish, const f_string_static_t value, const f_string_t why) {
 
+    if (!print || !print->custom) return F_status_set_error(F_output_not);
+    if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
+
+    controller_t * const main = (controller_t *) print->custom;
+
     if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not;
 
     fl_print_format("%r%[%QThe %r rule '%]", print->to, f_string_eol_s, print->context, print->prefix, need_want_wish, print->context);
@@ -418,6 +424,11 @@ extern "C" {
 #ifndef _di_controller_print_error_rule_item_rule_not_loaded_
   f_status_t controller_print_error_rule_item_rule_not_loaded(fl_print_t * const print, const f_string_static_t alias) {
 
+    if (!print || !print->custom) return F_status_set_error(F_output_not);
+    if (print->verbosity < f_console_verbosity_error_e) return F_output_not;
+
+    controller_t * const main = (controller_t *) print->custom;
+
     if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not;
 
     fl_print_format("%r%[%QThe rule '%]", print->to, f_string_eol_s, print->context, print->prefix, print->context);
index f27fefd017251be6ef4a1f875a97659b7e2c8c24..749a056879a4e64c40e22ebfd1962aef30a8c664 100644 (file)
@@ -24,17 +24,7 @@ extern "C" {
         break;
 
       default:
-        if (main->program.error.verbosity > f_console_verbosity_quiet_e) {
-          controller_lock_print(main->program.error.to, &main->thread);
-
-          fl_print_format("%r%[%QUnsupported action type '%]", main->program.error.to, f_string_eol_s, main->program.error.context, main->program.error.prefix, main->program.error.context);
-          fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, controller_convert_rule_action_type_string(instance->action), main->program.error.notable);
-          fl_print_format("%[' while attempting to execute rule.%]%r", main->program.error.to, main->program.error.context, main->program.error.context, f_string_eol_s);
-
-          controller_print_error_rule_cache(&main->program.error, &instance->cache.action, F_true);
-
-          controller_unlock_print_flush(main->program.error.to, &main->thread);
-        }
+        controller_print_error_rule_action_type_supported_not(&main->program.error, &instance->cache.action, controller_convert_rule_action_type_string(instance->action));
 
         return F_status_set_error(F_parameter);
     }
@@ -444,47 +434,15 @@ extern "C" {
         } // for
 
         if (missing) {
-          if (main->program.error.verbosity > f_console_verbosity_quiet_e) {
-            controller_lock_print(main->program.error.to, &main->thread);
-
-            if (instance->rule.items.used) {
-              fl_print_format("%r%[%QThe rule '%]", main->program.error.to, f_string_eol_s, main->program.error.context, main->program.error.prefix, main->program.error.context);
-              fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, instance->rule.name, main->program.error.notable);
-              fl_print_format("%[' has no '%]", main->program.error.to, main->program.error.context, main->program.error.context);
-              fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, controller_convert_rule_action_type_string(instance->action), main->program.error.notable);
-              fl_print_format("%[' action to execute.%]%r", main->program.error.to, main->program.error.context, main->program.error.context, f_string_eol_s);
-            }
-            else {
-              fl_print_format("%r%[%QThe rule '%]", main->program.error.to, f_string_eol_s, main->program.error.context, main->program.error.prefix, main->program.error.context);
-              fl_print_format(f_string_format_Q_single_s.string, main->program.error.to, main->program.error.notable, instance->rule.name, main->program.error.notable);
-              fl_print_format("%[ has no known '%]", main->program.error.to, main->program.error.context, main->program.error.context);
-              fl_print_format("%[%r %r%]", main->program.error.to, main->program.error.notable, controller_rule_s, controller_type_s, main->program.error.notable);
-              fl_print_format("%[' (such as '%]", main->program.error.to, main->program.error.context, main->program.error.context);
-              fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_command_s, main->program.error.notable);
-              fl_print_format("%[', '%]", main->program.error.to, main->program.error.context, main->program.error.context);
-              fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_service_s, main->program.error.notable);
-              fl_print_format("%[', '%]", main->program.error.to, main->program.error.context, main->program.error.context);
-              fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_script_s, main->program.error.notable);
-              fl_print_format("%[', or '%]", main->program.error.to, main->program.error.context, main->program.error.context);
-              fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_utility_s, main->program.error.notable);
-              fl_print_format("%[') to execute.%]%r", main->program.error.to, main->program.error.context, main->program.error.context, f_string_eol_s);
-            }
-
-            controller_print_error_rule_cache(&main->program.error, &instance->cache.action, F_true);
-
-            controller_unlock_print_flush(main->program.error.to, &main->thread);
-          }
-
           status = F_status_set_error(F_parameter);
+
+          controller_print_error_rule_action_unknown_execute(&main->program.error, &instance->cache.action, instance->rule.name, controller_convert_rule_action_type_string(instance->action), instance->rule.items.used);
         }
       }
 
       if (F_status_is_error_not(status)) {
         status = controller_rule_execute(main, instance->action, instance->options, instance);
-
-        if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) {
-          return status;
-        }
+        if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) return status;
 
         if (F_status_is_error(status)) {
           controller_print_error_rule_item(&main->program.error, &instance->cache.action, F_true, F_status_set_fine(status));
@@ -531,7 +489,7 @@ extern "C" {
 
     // Update the rule status, which is stored separately from the rule status for this instance.
     if (controller_rule_find(instance->rule.alias, main->process.rules, &id_rule) == F_true) {
-      controller_rule_t *rule = &main->process.rules.array[id_rule];
+      controller_rule_t * const rule = &main->process.rules.array[id_rule];
 
       rule->status[instance->action] = instance->rule.status[instance->action];
 
@@ -901,21 +859,12 @@ extern "C" {
         for (f_number_unsigned_t i = 0; i < instance->stack.used && controller_thread_is_enabled_instance(instance); ++i) {
 
           if (instance->stack.array[i] == id_rule) {
-            if (instance->main->program.error.verbosity > f_console_verbosity_quiet_e) {
-              controller_lock_print(instance->main->program.error.to, &instance->main->thread);
-
-              fl_print_format("%r%[%QThe rule '%]", instance->main->program.error.to, f_string_eol_s, instance->main->program.error.context, instance->main->program.error.prefix, instance->main->program.error.context);
-              fl_print_format(f_string_format_Q_single_s.string, instance->main->program.error.to, instance->main->program.error.notable, instance->rule.alias, instance->main->program.error.notable);
-              fl_print_format("%[' is already on the execution dependency stack, this recursion is prohibited.%]%r", instance->main->program.error.to, instance->main->program.error.context, instance->main->program.error.context, f_string_eol_s);
-
-              controller_print_error_rule_cache(&instance->main->program.error, &instance->cache.action, F_true);
-
-              controller_unlock_print_flush(instance->main->program.error.to, &instance->main->thread);
-            }
 
             // Never continue on circular recursion errors even in simulate mode.
             status = F_status_set_error(F_recurse);
 
+            controller_print_error_rule_stack_already(&instance->main->program.error, &instance->cache.action, instance->rule.alias, F_true);
+
             break;
           }
         } // for