From: Kevin Day Date: Mon, 12 Apr 2021 01:57:36 +0000 (-0500) Subject: Update: properly process and support -c/--control custom control group file path. X-Git-Tag: 0.5.3~50 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b664c4ebb9d4f50842452e2b17d877384a48ca92;p=fll Update: properly process and support -c/--control custom control group file path. This is a directory path to the sysfs cgroups directory. It must end in a path separator '/'. There is existing code that needed to be updated to use the -c/--control. It was being ignored! --- diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index 77abe1b..2c704a0 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -27,7 +27,7 @@ extern "C" { fprintf(output.stream, "%c", f_string_eol_s[0]); - fll_program_print_help_option(output, context, controller_short_control, controller_long_control, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom control group file path, such as '" controller_path_control "'."); + fll_program_print_help_option(output, context, controller_short_control, controller_long_control, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom control group file path, such as '" f_control_group_path_system_prefix f_control_group_path_system_default "'."); fll_program_print_help_option(output, context, controller_short_daemon, controller_long_daemon, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Run in daemon only mode (do not process the entry)."); fll_program_print_help_option(output, context, controller_short_interruptable, controller_long_interruptable, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Designate that this program can be interrupted."); fll_program_print_help_option(output, context, controller_short_pid, controller_long_pid, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom pid file path, such as '" controller_path_pid controller_string_default controller_path_suffix "'."); @@ -262,6 +262,24 @@ extern "C" { fll_error_print(data->error, F_status_set_fine(status), "fll_path_canonical", F_true); } } + else { + status = f_string_append_assure(f_path_separator, 1, &setting.path_control); + + if (F_status_is_error(status)) { + if (data->error.verbosity != f_console_verbosity_quiet) { + fll_error_print(data->error, F_status_set_fine(status), "f_string_append_assure", F_true); + } + } + else { + status = f_string_dynamic_terminate_after(&setting.path_control); + + if (F_status_is_error(status)) { + if (data->error.verbosity != f_console_verbosity_quiet) { + fll_error_print(data->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); + } + } + } + } } else { if (data->warning.verbosity == f_console_verbosity_debug) { @@ -305,11 +323,33 @@ extern "C" { // a control file path is required. if (!setting.path_control.used) { - status = f_string_append(controller_path_control, controller_path_control_length, &setting.path_control); + status = f_string_append_nulless(f_control_group_path_system_prefix, f_control_group_path_system_prefix_length, &setting.path_control); + + if (F_status_is_error_not(status)) { + status = f_string_append_nulless(f_control_group_path_system_default, f_control_group_path_system_default_length, &setting.path_control); + } if (F_status_is_error(status)) { if (data->error.verbosity != f_console_verbosity_quiet) { - fll_error_print(data->error, F_status_set_fine(status), "f_string_append", F_true); + fll_error_print(data->error, F_status_set_fine(status), "f_string_append_nulless", F_true); + } + } + else { + status = f_string_append_assure(f_path_separator, 1, &setting.path_control); + + if (F_status_is_error(status)) { + if (data->error.verbosity != f_console_verbosity_quiet) { + fll_error_print(data->error, F_status_set_fine(status), "f_string_append_assure", F_true); + } + } + else { + status = f_string_dynamic_terminate_after(&setting.path_control); + + if (F_status_is_error(status)) { + if (data->error.verbosity != f_console_verbosity_quiet) { + fll_error_print(data->error, F_status_set_fine(status), "f_string_dynamic_terminate_after", F_true); + } + } } } } diff --git a/level_3/controller/c/controller.h b/level_3/controller/c/controller.h index 3d35094..69be87a 100644 --- a/level_3/controller/c/controller.h +++ b/level_3/controller/c/controller.h @@ -94,12 +94,10 @@ extern "C" { #define controller_default_program_script "bash" - #define controller_path_control "/sys/fs/cgroup/unified" #define controller_path_pid "/var/run/controller/controller-" #define controller_path_settings "/etc/controller" #define controller_path_suffix ".pid" - #define controller_path_control_length 22 #define controller_path_pid_length 31 #define controller_path_settings_length 15 #define controller_path_suffix_length 4 diff --git a/level_3/controller/c/private-common.c b/level_3/controller/c/private-common.c index efa6fd0..6eff715 100644 --- a/level_3/controller/c/private-common.c +++ b/level_3/controller/c/private-common.c @@ -83,6 +83,19 @@ extern "C" { } #endif // _di_controller_entry_items_delete_simple_ +#ifndef _di_controller_error_file_print_ + void controller_error_file_print(const fll_error_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type, controller_thread_t *thread) { + + if (print.verbosity != f_console_verbosity_quiet) { + f_thread_mutex_lock(&thread->lock.print); + + fll_error_file_print(print, status, function, fallback, name, operation, type); + + controller_print_unlock_flush(print.to.stream, &thread->lock.print); + } + } +#endif // _di_controller_error_file_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 74f0011..29a6be4 100644 --- a/level_3/controller/c/private-common.h +++ b/level_3/controller/c/private-common.h @@ -1251,6 +1251,35 @@ extern "C" { #endif // _di_controller_entry_items_delete_simple_ /** + * Print the file error, locking the print mutex during the print. + * + * @param print + * Designates how printing is to be performed. + * @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. + * @param function + * The name of the function where the error happened. + * Set to 0 to disable. + * @param fallback + * Set to F_true to print the fallback error message for unknown errors. + * @param name + * The name of the file or directory. + * @param operation + * The operation that fails, such as 'create' or 'access'. + * @param type + * A valid file type code from the fll_error_file_type enum. + * @param thread + * The thread data. + * + * @see fll_error_file_print() + */ +#ifndef _di_controller_error_file_print_ + extern void controller_error_file_print(const fll_error_print_t print, const f_status_t status, const f_string_t function, const bool fallback, const f_string_t name, const f_string_t operation, const uint8_t type, controller_thread_t *thread) f_gcc_attribute_visibility_internal; +#endif // _di_controller_error_file_print_ + + +/** * Print the error, locking the print mutex during the print. * * @param print diff --git a/level_3/controller/c/private-controller.c b/level_3/controller/c/private-controller.c index 8250911..3052cd9 100644 --- a/level_3/controller/c/private-controller.c +++ b/level_3/controller/c/private-controller.c @@ -265,7 +265,6 @@ extern "C" { f_status_t controller_get_id_user(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t *cache, uid_t *id) { f_number_unsigned_t number = 0; - // @todo fix argument ordering in fl_conversion_string_to_number_unsigned(). f_status_t status = fl_conversion_string_to_number_unsigned(buffer.string, range, &number); if (F_status_is_error(status)) { @@ -307,7 +306,6 @@ extern "C" { f_status_t controller_get_id_group(const f_string_static_t buffer, const f_string_range_t range, controller_cache_t *cache, gid_t *id) { f_number_unsigned_t number = 0; - // @todo fix argument ordering in fl_conversion_string_to_number_unsigned(). f_status_t status = fl_conversion_string_to_number_unsigned(buffer.string, range, &number); if (F_status_is_error(status)) { diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index 804e188..11f76ce 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -780,7 +780,7 @@ extern "C" { status = fll_control_group_prepare(process->rule.control_group); if (F_status_is_error(status)) { - controller_error_print(main.data->error, F_status_set_fine(status), "fll_control_group_prepare", F_true, main.thread); + controller_error_file_print(main.data->error, F_status_set_fine(status), "fll_control_group_prepare", F_true, process->rule.control_group.path.string, "prepare control groups for", fll_error_file_type_directory, main.thread); return status; } @@ -3311,15 +3311,10 @@ extern "C" { rule->control_group.path.used = 0; - // @todo path prefix needs to be configurable via a parameter. - status = f_string_append(f_control_group_path_system_prefix, f_control_group_path_system_prefix_length, &rule->control_group.path); - - if (F_status_is_error_not(status)) { - status = f_string_append(f_control_group_path_system_default, f_control_group_path_system_default_length, &rule->control_group.path); - } + status = f_string_dynamic_append(main.setting->path_control, &rule->control_group.path); if (F_status_is_error(status)) { - controller_rule_error_print(main.data->error, cache->action, F_status_set_fine(status), "f_string_append", F_true, F_false, main.thread); + controller_rule_error_print(main.data->error, cache->action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_false, main.thread); } else { rule->control_group.groups.used = 0;