From 1055e6c06e977ee911a7ca33d0525d2b24a28e5b Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 30 Sep 2021 07:16:39 -0500 Subject: [PATCH] Update: Improve a few initial error printing messages. --- level_3/controller/c/controller.c | 38 +++++++++++++++++++------------ level_3/controller/c/private-common.c | 17 -------------- level_3/controller/c/private-common.h | 19 ---------------- level_3/controller/c/private-controller.c | 11 ++++++--- level_3/controller/c/private-rule.c | 2 ++ 5 files changed, 33 insertions(+), 54 deletions(-) diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index 6802de0..d77b7a0 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -13,7 +13,7 @@ extern "C" { #ifndef _di_controller_print_help_ f_status_t controller_print_help(const controller_main_t main) { - flockfile(main.output.stream); + controller_print_lock(main.output, 0); fll_program_print_help_header(main.output, main.context, main.program_name_long, controller_version); @@ -48,7 +48,7 @@ extern "C" { fl_print_format(" Specify an empty string for the %[%s%s%] parameter to disable pid file creation for this program.%c%c", main.output.stream, main.context.set.notable, f_console_symbol_long_enable_s, controller_long_pid, main.context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); - funlockfile(main.output.stream); + controller_print_unlock_flush(main.output, 0); return F_none; } @@ -134,11 +134,11 @@ extern "C" { } if (main->parameters[controller_parameter_version].result == f_console_result_found) { - flockfile(main->output.stream); + controller_print_lock(main->output, 0); fll_program_print_version(main->output, controller_version); - funlockfile(main->output.stream); + controller_print_unlock_flush(main->output, 0); controller_main_delete(main); return F_none; @@ -179,13 +179,13 @@ extern "C" { if (main->parameters[controller_parameter_settings].result == f_console_result_found) { if (main->error.verbosity != f_console_verbosity_quiet) { - flockfile(main->error.to.stream); + controller_print_lock(main->error.to, 0); fl_print_format("%c%[%SThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix ? main->error.prefix : f_string_empty_s, main->error.context); fl_print_format("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, controller_long_settings, main->context.set.notable); fl_print_format("%[' was specified, but no value was given.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); - funlockfile(main->error.to.stream); + controller_print_unlock_flush(main->error.to, 0); } status = F_status_set_error(F_parameter); @@ -218,13 +218,13 @@ extern "C" { if (F_status_is_error_not(status)) { if (main->parameters[controller_parameter_pid].result == f_console_result_found) { if (main->error.verbosity != f_console_verbosity_quiet) { - flockfile(main->error.to.stream); + controller_print_lock(main->error.to, 0); fl_print_format("%c%[%SThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix ? main->error.prefix : f_string_empty_s, main->error.context); fl_print_format("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, controller_long_pid, main->context.set.notable); fl_print_format("%[' was specified, but no value was given.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); - funlockfile(main->error.to.stream); + controller_print_unlock_flush(main->error.to, 0); } status = F_status_set_error(F_parameter); @@ -270,13 +270,13 @@ extern "C" { if (F_status_is_error_not(status)) { if (main->parameters[controller_parameter_control].result == f_console_result_found) { if (main->error.verbosity != f_console_verbosity_quiet) { - flockfile(main->error.to.stream); + controller_print_lock(main->error.to, 0); fl_print_format("%c%[%SThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix ? main->error.prefix : f_string_empty_s, main->error.context); fl_print_format("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, controller_long_control, main->context.set.notable); fl_print_format("%[' was specified, but no value was given.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); - funlockfile(main->error.to.stream); + controller_print_unlock_flush(main->error.to, 0); } status = F_status_set_error(F_parameter); @@ -307,13 +307,13 @@ extern "C" { } else { if (main->warning.verbosity == f_console_verbosity_debug) { - flockfile(main->warning.to.stream); + controller_print_lock(main->warning.to, 0); fl_print_format("%c%[%SThe parameter '%]", main->warning.to.stream, f_string_eol_s[0], main->warning.context, main->warning.prefix ? main->warning.prefix : f_string_empty_s, main->warning.context); fl_print_format("%[%s%s%]", main->warning.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, controller_long_control, main->context.set.notable); fl_print_format("%[' must be a file directory path but instead is an empty string, falling back to the default.%]%c", main->warning.to.stream, main->warning.context, main->warning.context, f_string_eol_s[0]); - funlockfile(main->warning.to.stream); + controller_print_unlock_flush(main->warning.to, 0); } } } @@ -322,14 +322,14 @@ extern "C" { if (F_status_is_error_not(status) && main->parameters[controller_parameter_daemon].result == f_console_result_found) { if (main->parameters[controller_parameter_validate].result == f_console_result_found) { if (main->error.verbosity != f_console_verbosity_quiet) { - flockfile(main->error.to.stream); + controller_print_lock(main->error.to, 0); fl_print_format("%c%[%SThe parameter '%]", main->error.to.stream, f_string_eol_s[0], main->error.context, main->error.prefix ? main->error.prefix : f_string_empty_s, main->error.context); fl_print_format("%[' must not be specified with the parameter '%]", main->error.to.stream, main->error.context, main->error.context); fl_print_format("%[%s%s%]", main->error.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, controller_long_daemon, main->context.set.notable); fl_print_format("%['.%]%c", main->error.to.stream, main->error.context, main->error.context, f_string_eol_s[0]); - funlockfile(main->error.to.stream); + controller_print_unlock_flush(main->error.to, 0); } status = F_status_set_error(F_parameter); @@ -415,7 +415,15 @@ extern "C" { if (F_status_is_error(status_delete) && main->warning.verbosity == f_console_verbosity_debug) { if (F_status_set_fine(status_delete) == F_number_not) { - controller_error_pid_bad_match_print(main->warning, setting.path_pid.string, 0); + controller_print_lock(main->warning.to, 0); + + fl_print_format("%c%[%SThe pid file '%]", main->warning.to.stream, f_string_eol_s[0], main->warning.context, main->warning.prefix ? main->warning.prefix : f_string_empty_s, main->warning.context); + fl_print_format("%[%Q%]", main->warning.to.stream, main->warning.notable, setting.path_pid, main->warning.notable); + fl_print_format("%[' must not be specified with the parameter '%]", main->warning.to.stream, main->warning.context, main->warning.context); + fl_print_format("%[%i%]", main->warning.to.stream, main->warning.notable, main->pid, main->warning.notable); + fl_print_format("%[' doesn't contain the expected number, not deleting file.%]%c", main->warning.to.stream, main->warning.context, main->warning.context, f_string_eol_s[0]); + + controller_print_unlock_flush(main->warning.to, 0); } else { fll_error_file_print(main->warning, F_status_set_fine(status_delete), "controller_file_pid_delete", F_true, setting.path_pid.string, "delete", fll_error_file_type_file); diff --git a/level_3/controller/c/private-common.c b/level_3/controller/c/private-common.c index 3def5d1..bd69568 100644 --- a/level_3/controller/c/private-common.c +++ b/level_3/controller/c/private-common.c @@ -200,23 +200,6 @@ extern "C" { } } #endif // _di_controller_error_file_print_ - -#ifndef _di_controller_error_pid_bad_match_print_ - void controller_error_pid_bad_match_print(const fll_error_print_t print, const f_string_t path, controller_thread_t *thread) { - - if (print.verbosity == f_console_verbosity_quiet) return; - - controller_print_lock(print.to, thread); - - fl_print_format("%c%[%SThe pid file '%]", print.to.stream, f_string_eol_s[0], print.context, print.prefix ? print.prefix : f_string_empty_s, print.context); - fl_print_format("%[' must not be specified with the parameter '%]", print.to.stream, print.context, print.context); - fl_print_format("%[%S%]", print.to.stream, print.notable, path, print.notable); - fl_print_format("%[' doesn't contain the expected number, not deleting file.%]%c", print.to.stream, print.context, print.context, f_string_eol_s[0]); - - controller_print_unlock_flush(print.to, thread); - } -#endif // _di_controller_error_pid_bad_match_print_ - #ifndef _di_controller_error_print_ void controller_error_print(const fll_error_print_t print, const f_status_t status, const f_string_t function, const bool fallback, controller_thread_t *thread) { diff --git a/level_3/controller/c/private-common.h b/level_3/controller/c/private-common.h index c5ded77..dd6e187 100644 --- a/level_3/controller/c/private-common.h +++ b/level_3/controller/c/private-common.h @@ -1607,25 +1607,6 @@ extern "C" { /** * Print the error, locking the print mutex during the print. * - * This does not check verbosity. - * - * @param print - * Designates how printing is to be performed. - * @param path - * The path to the PID file. - * @param thread - * (optional) The thread data. - * Set to NULL to not use (locking will not be performed). - * - * @see fll_error_print() - */ -#ifndef _di_controller_error_pid_bad_match_print_ - extern void controller_error_pid_bad_match_print(const fll_error_print_t print, const f_string_t path, controller_thread_t *thread) f_attribute_visibility_internal; -#endif // _di_controller_error_pid_bad_match_print_ - -/** - * Print the error, locking the print mutex during the print. - * * @param print * Designates how printing is to be performed. * @param status diff --git a/level_3/controller/c/private-controller.c b/level_3/controller/c/private-controller.c index 1421157..34917a6 100644 --- a/level_3/controller/c/private-controller.c +++ b/level_3/controller/c/private-controller.c @@ -428,9 +428,14 @@ extern "C" { if (global.main->warning.verbosity == f_console_verbosity_debug) { controller_print_lock(global.main->warning.to, global.thread); - controller_error_file_print(global.main->warning, F_status_set_fine(status), "controller_file_pid_create", F_true, global.setting->path_pid.string, "create", fll_error_file_type_file, 0); - - flockfile(global.main->warning.to.stream); + if (F_status_set_fine(status) == F_read_only) { + fl_print_format("%c%[%SThe pid file '%]", global.main->warning.to.stream, f_string_eol_s[0], global.main->warning.context, global.main->warning.prefix ? global.main->warning.prefix : f_string_empty_s, global.main->warning.context); + fl_print_format("%[%Q%]", global.main->warning.to.stream, global.main->warning.notable, global.setting->path_pid, global.main->warning.notable); + fl_print_format("%[' could not be written because the destination is read only.%]%c", global.main->warning.to.stream, global.main->warning.context, global.main->warning.context, f_string_eol_s[0]); + } + else { + controller_error_file_print(global.main->warning, F_status_set_fine(status), "controller_file_pid_create", F_true, global.setting->path_pid.string, "create", fll_error_file_type_file, 0); + } controller_entry_error_print_cache(is_entry, global.main->warning, cache->action); diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index 69b373b..61eab06 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -2156,6 +2156,7 @@ extern "C" { controller_print_lock(global.main->warning.to, global.thread); controller_rule_item_error_print_need_want_wish(global.main->warning, strings[i], dynamics[i]->array[j].string, "was not found"); + controller_rule_error_print_cache(global.main->warning, process->cache.action, F_true); controller_print_unlock_flush(global.main->warning.to, global.thread); @@ -2254,6 +2255,7 @@ extern "C" { controller_print_lock(global.main->warning.to, global.thread); controller_rule_item_error_print_need_want_wish(global.main->warning, strings[i], alias_other_buffer, "failed during execution"); + controller_rule_error_print_cache(global.main->warning, process->cache.action, F_true); controller_print_unlock_flush(global.main->warning.to, global.thread); -- 1.8.3.1