From: Kevin Day Date: Sun, 11 Apr 2021 21:53:54 +0000 (-0500) Subject: Bugfix: rules not properly handling status. X-Git-Tag: 0.5.3~58 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=ccebf74487480a9dd047a8a45b2cf5ec9294010b;p=fll Bugfix: rules not properly handling status. The status F_known_not was incorrectly being treated as busy. Make sure to guarantee lock and then unlock of the process_other lock (read lock) to prevent execution of dependent rule while analyzing state of dependent rule. Read the rule's status after executing from the rule in the rules array and not on the process. The rules on the rules array is updated after execution but the process is not guaranteed this. The status of process is generally reserved for the process to manage the status and not to represent the rule status. Expanded the example serial execution test entries and rules. Add a new alternative serial so that one uses normal execution and other uses dependent execution (execution is executed by something depending on it rather than being directly started via the entry). --- diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index 33304e2..e901eb9 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -1811,64 +1811,70 @@ extern "C" { busy = F_false; - status = f_thread_lock_read_try(&process_other->lock); + f_thread_lock_read(&process_other->lock); - if (status == F_busy) { + if (process_other->state == controller_process_state_active || process_other->state == controller_process_state_busy) { busy = F_true; } - else { - if (process_other->status == F_known_not || process_other->state == controller_process_state_active || process_other->state == controller_process_state_busy) { - busy = F_true; - } + if (busy) { f_thread_unlock(&process_other->lock); - } - if (busy) { controller_process_wait(main, process_other); } else { - rule_options = 0; + f_thread_lock_read(&main.thread->lock.rule); - if (main.data->parameters[controller_parameter_test].result == f_console_result_found) { - rule_options |= controller_rule_option_simulate; - } + if (main.setting->rules.array[id_rule].status == F_known_not) { + f_thread_unlock(&main.thread->lock.rule); + f_thread_unlock(&process_other->lock); - // synchronously execute dependency. - status = controller_rule_process_begin(controller_process_option_execute, alias_other, controller_rule_action_type_start, controller_process_option_execute, process->stack, main, process_other->cache); + rule_options = 0; - if (status == F_child || status == F_signal) { - f_thread_unlock(&process_other->active); + if (main.data->parameters[controller_parameter_test].result == f_console_result_found) { + rule_options |= controller_rule_option_simulate; + } - break; - } + // synchronously execute dependency. + status = controller_rule_process_begin(controller_process_option_execute, alias_other, controller_rule_action_type_start, controller_process_option_execute, process->stack, main, process_other->cache); - if (F_status_is_error(status)) { - if (i == 0 || i == 1 || F_status_set_fine(status) == F_memory_not) { - f_thread_mutex_lock(&main.thread->lock.print); + if (status == F_child || status == F_signal) { + f_thread_unlock(&process_other->active); - controller_rule_item_error_print_need_want_wish(main.data->error, strings[i], alias_other_buffer, "failed during execution"); - controller_rule_error_print_cache(main.data->error, process->cache.action, F_true); + break; + } - controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print); + if (F_status_is_error(status)) { + if (i == 0 || i == 1 || F_status_set_fine(status) == F_memory_not) { + f_thread_mutex_lock(&main.thread->lock.print); - if (!(process_other->options & controller_rule_option_simulate) || F_status_set_fine(status) == F_memory_not) { - f_thread_unlock(&process_other->active); + controller_rule_item_error_print_need_want_wish(main.data->error, strings[i], alias_other_buffer, "failed during execution"); + controller_rule_error_print_cache(main.data->error, process->cache.action, F_true); + + controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print); + + if (!(process_other->options & controller_rule_option_simulate) || F_status_set_fine(status) == F_memory_not) { + f_thread_unlock(&process_other->active); - break; + break; + } } - } - else { - if (main.data->warning.verbosity == f_console_verbosity_debug) { - f_thread_mutex_lock(&main.thread->lock.print); + else { + if (main.data->warning.verbosity == f_console_verbosity_debug) { + f_thread_mutex_lock(&main.thread->lock.print); - controller_rule_item_error_print_need_want_wish(main.data->warning, strings[i], alias_other_buffer, "failed during execution"); - controller_rule_error_print_cache(main.data->warning, process->cache.action, F_true); + controller_rule_item_error_print_need_want_wish(main.data->warning, strings[i], alias_other_buffer, "failed during execution"); + controller_rule_error_print_cache(main.data->warning, process->cache.action, F_true); - controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print); + controller_print_unlock_flush(main.data->output.stream, &main.thread->lock.print); + } } } } + else { + f_thread_unlock(&main.thread->lock.rule); + f_thread_unlock(&process_other->lock); + } } if (!main.thread->enabled) { @@ -1942,7 +1948,7 @@ extern "C" { } if ((process->options & controller_rule_option_wait) && F_status_is_error_not(status)) { - controller_rule_wait_all(main, process); // @fixme review this, it needs to check anything depending on itself! + controller_rule_wait_all(main, process); // @fixme review this, it needs to check anything depending on this! if (!main.thread->enabled) { return F_signal; diff --git a/level_3/controller/data/settings/example/entries/serial-alternate.entry b/level_3/controller/data/settings/example/entries/serial-alternate.entry new file mode 100644 index 0000000..5b26299 --- /dev/null +++ b/level_3/controller/data/settings/example/entries/serial-alternate.entry @@ -0,0 +1,11 @@ +# fss-0005 + +main: + rule serial s_1 + rule serial s_2 + rule serial s_3 + rule serial s_4 + rule serial s_5 + rule serial s_6 + + ready diff --git a/level_3/controller/data/settings/example/entries/serial.entry b/level_3/controller/data/settings/example/entries/serial.entry index fcfcc82..8d6ee33 100644 --- a/level_3/controller/data/settings/example/entries/serial.entry +++ b/level_3/controller/data/settings/example/entries/serial.entry @@ -1,7 +1,6 @@ # fss-0005 main: - consider serial s_1 consider serial s_2 consider serial s_3 diff --git a/level_3/controller/data/settings/example/rules/asynchronous/sleep_1.rule b/level_3/controller/data/settings/example/rules/asynchronous/sleep_1.rule index e055c16..de7c696 100644 --- a/level_3/controller/data/settings/example/rules/asynchronous/sleep_1.rule +++ b/level_3/controller/data/settings/example/rules/asynchronous/sleep_1.rule @@ -7,7 +7,7 @@ setting: need asynchronous sleep_10 script: - start echo "Sleeping 1: $(date -u)" + start echo "Sleeping 1: $(date -u), depends: 10" script: start sleep 1 diff --git a/level_3/controller/data/settings/example/rules/asynchronous/sleep_10.rule b/level_3/controller/data/settings/example/rules/asynchronous/sleep_10.rule index 63d644c..db6a70c 100644 --- a/level_3/controller/data/settings/example/rules/asynchronous/sleep_10.rule +++ b/level_3/controller/data/settings/example/rules/asynchronous/sleep_10.rule @@ -6,7 +6,7 @@ setting: limit nice 1 2 script: - start echo "Sleeping 10: $(date -u)" + start echo "Sleeping 10: $(date -u), depends: none" script: start sleep 10 diff --git a/level_3/controller/data/settings/example/rules/asynchronous/sleep_2.rule b/level_3/controller/data/settings/example/rules/asynchronous/sleep_2.rule index 77cbab5..40f3f4c 100644 --- a/level_3/controller/data/settings/example/rules/asynchronous/sleep_2.rule +++ b/level_3/controller/data/settings/example/rules/asynchronous/sleep_2.rule @@ -7,7 +7,7 @@ setting: need asynchronous sleep_10 script: - start echo "Sleeping 2: $(date -u)" + start echo "Sleeping 2: $(date -u), depends: 10" script: start sleep 2 diff --git a/level_3/controller/data/settings/example/rules/asynchronous/sleep_3.rule b/level_3/controller/data/settings/example/rules/asynchronous/sleep_3.rule index de91412..de403b6 100644 --- a/level_3/controller/data/settings/example/rules/asynchronous/sleep_3.rule +++ b/level_3/controller/data/settings/example/rules/asynchronous/sleep_3.rule @@ -7,7 +7,7 @@ setting: need asynchronous sleep_8 script: - start echo "Sleeping 3: $(date -u)" + start echo "Sleeping 3: $(date -u), depends: 8" script: start sleep 3 diff --git a/level_3/controller/data/settings/example/rules/asynchronous/sleep_5.rule b/level_3/controller/data/settings/example/rules/asynchronous/sleep_5.rule index ecac2f5..f40234b 100644 --- a/level_3/controller/data/settings/example/rules/asynchronous/sleep_5.rule +++ b/level_3/controller/data/settings/example/rules/asynchronous/sleep_5.rule @@ -6,7 +6,7 @@ setting: limit nice 1 2 script: - start echo "Sleeping 5: $(date -u)" + start echo "Sleeping 5: $(date -u), depends: none" script: start sleep 5 diff --git a/level_3/controller/data/settings/example/rules/asynchronous/sleep_8.rule b/level_3/controller/data/settings/example/rules/asynchronous/sleep_8.rule index 34d919b..a05a249 100644 --- a/level_3/controller/data/settings/example/rules/asynchronous/sleep_8.rule +++ b/level_3/controller/data/settings/example/rules/asynchronous/sleep_8.rule @@ -6,7 +6,7 @@ setting: limit nice 1 2 script: - start echo "Sleeping 8: $(date -u)" + start echo "Sleeping 8: $(date -u), depends: none" script: start sleep 8 diff --git a/level_3/controller/data/settings/example/rules/serial/s_1.rule b/level_3/controller/data/settings/example/rules/serial/s_1.rule index f434357..af975d1 100644 --- a/level_3/controller/data/settings/example/rules/serial/s_1.rule +++ b/level_3/controller/data/settings/example/rules/serial/s_1.rule @@ -5,6 +5,7 @@ setting: script: start { - echo "Serial 1: $(date -u)" + echo "Serial 1: sleeping $(date -u)" sleep 1 + echo "Serial 1: slept $(date -u)" } diff --git a/level_3/controller/data/settings/example/rules/serial/s_2.rule b/level_3/controller/data/settings/example/rules/serial/s_2.rule index 1846b09..be526d7 100644 --- a/level_3/controller/data/settings/example/rules/serial/s_2.rule +++ b/level_3/controller/data/settings/example/rules/serial/s_2.rule @@ -6,6 +6,7 @@ setting: script: start { - echo "Serial 2: $(date -u)" + echo "Serial 2: sleeping $(date -u)" sleep 1 + echo "Serial 2: slept $(date -u)" } diff --git a/level_3/controller/data/settings/example/rules/serial/s_3.rule b/level_3/controller/data/settings/example/rules/serial/s_3.rule index 9b0ef02..124de75 100644 --- a/level_3/controller/data/settings/example/rules/serial/s_3.rule +++ b/level_3/controller/data/settings/example/rules/serial/s_3.rule @@ -6,6 +6,7 @@ setting: script: start { - echo "Serial 3: $(date -u)" + echo "Serial 3: sleeping $(date -u)" sleep 1 + echo "Serial 3: slept $(date -u)" } diff --git a/level_3/controller/data/settings/example/rules/serial/s_4.rule b/level_3/controller/data/settings/example/rules/serial/s_4.rule index 46217ab..beb52f7 100644 --- a/level_3/controller/data/settings/example/rules/serial/s_4.rule +++ b/level_3/controller/data/settings/example/rules/serial/s_4.rule @@ -6,6 +6,7 @@ setting: script: start { - echo "Serial 4: $(date -u)" + echo "Serial 4: sleeping $(date -u)" sleep 1 + echo "Serial 4: slept $(date -u)" } diff --git a/level_3/controller/data/settings/example/rules/serial/s_5.rule b/level_3/controller/data/settings/example/rules/serial/s_5.rule index f180252..eb6aab8 100644 --- a/level_3/controller/data/settings/example/rules/serial/s_5.rule +++ b/level_3/controller/data/settings/example/rules/serial/s_5.rule @@ -6,6 +6,7 @@ setting: script: start { - echo "Serial 5: $(date -u)" + echo "Serial 5: sleeping $(date -u)" sleep 1 + echo "Serial 5: slept $(date -u)" } diff --git a/level_3/controller/data/settings/example/rules/serial/s_6.rule b/level_3/controller/data/settings/example/rules/serial/s_6.rule index ec3b020..af3bc82 100644 --- a/level_3/controller/data/settings/example/rules/serial/s_6.rule +++ b/level_3/controller/data/settings/example/rules/serial/s_6.rule @@ -6,6 +6,7 @@ setting: script: start { - echo "Serial 6: $(date -u)" + echo "Serial 6: sleeping $(date -u)" sleep 1 + echo "Serial 6: slept $(date -u)" }