From: Kevin Day Date: Fri, 10 Sep 2021 03:10:18 +0000 (-0500) Subject: Feature: Controller Program should support uninterruptable and define default behavior. X-Git-Tag: 0.5.6~43 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=fb32adbd195863007fed2b4b38bde7ec90504d9e;p=fll Feature: Controller Program should support uninterruptable and define default behavior. After designing the Controller to support operating directly as "init", it later occurred to me that the default behavior of uninterruptable makes sense for "init" but not for "controller". Change the behavior to default to interruptable for the "controller" program. This change further implies that the program needs an opposite to the "--interuptable" parameter. Implement the "--uninterruptable" parameter for this purpose. I also noticed that there is already an "interrupted" variable but that code is dead. Oops. Resurrect this variable and use it for identifying for this updated interruptable behavior. --- diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index df7b1ef..db82e7c 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -29,20 +29,23 @@ extern "C" { f_print_character(f_string_eol_s[0], main.output.stream); - fll_program_print_help_option(main.output, main.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(main.output, main.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(main.output, main.context, controller_short_init, controller_long_init, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " The program will run as an init replacement."); - fll_program_print_help_option(main.output, main.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(main.output, main.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 "'."); - fll_program_print_help_option(main.output, main.context, controller_short_settings, controller_long_settings, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom settings path, such as '" controller_path_settings "'."); - fll_program_print_help_option(main.output, main.context, controller_short_simulate, controller_long_simulate, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Run as a simulation."); - fll_program_print_help_option(main.output, main.context, controller_short_validate, controller_long_validate, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Validate the settings (entry and rules) without running (does not simulate)."); + fll_program_print_help_option(main.output, main.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(main.output, main.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(main.output, main.context, controller_short_init, controller_long_init, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " The program will run as an init replacement."); + fll_program_print_help_option(main.output, main.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 by a signal."); + fll_program_print_help_option(main.output, main.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 "'."); + fll_program_print_help_option(main.output, main.context, controller_short_settings, controller_long_settings, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom settings path, such as '" controller_path_settings "'."); + fll_program_print_help_option(main.output, main.context, controller_short_simulate, controller_long_simulate, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Run as a simulation."); + fll_program_print_help_option(main.output, main.context, controller_short_uninterruptable, controller_long_uninterruptable, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, "Designate that this program cannot be interrupted by a signal."); + fll_program_print_help_option(main.output, main.context, controller_short_validate, controller_long_validate, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Validate the settings (entry and rules) without running (does not simulate)."); fll_program_print_help_usage(main.output, main.context, main.program_name, "entry"); fl_print_format(" When both the %[%s%s%] parameter and the", main.output.stream, main.context.set.notable, f_console_symbol_long_enable_s, controller_long_simulate, main.context.set.notable); fl_print_format(" %[%s%s%] parameter are specified, then additional information on each would be executed rule is printed but no simulation is performed.%c%c", main.output.stream, main.context.set.notable, f_console_symbol_long_enable_s, controller_long_validate, main.context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); + fl_print_format(" The default interrupt behavior is to operate as if the %[%s%s%] parameter is passed.%c%c", main.output.stream, main.context.set.notable, f_console_symbol_long_enable_s, main.setting_default.used ? controller_long_uninterruptable : controller_long_interruptable, main.context.set.notable, f_string_eol_s[0], f_string_eol_s[0]); + funlockfile(main.output.stream); return F_none; @@ -332,6 +335,18 @@ extern "C" { } } + // when a default setting is not provided, then make the program interruptable by default. + if (main->setting_default.used) { + if (main->parameters[controller_parameter_interruptable].result == f_console_result_found) { + setting.interruptable = F_true; + } + } + else { + if (main->parameters[controller_parameter_uninterruptable].result == f_console_result_none) { + setting.interruptable = F_true; + } + } + if (F_status_is_error_not(status)) { f_signal_set_fill(&main->signal.set); diff --git a/level_3/controller/c/controller.h b/level_3/controller/c/controller.h index a390a49..3bb0502 100644 --- a/level_3/controller/c/controller.h +++ b/level_3/controller/c/controller.h @@ -142,23 +142,25 @@ extern "C" { #define controller_path_settings_length 10 #define controller_path_suffix_length 4 - #define controller_short_control "c" - #define controller_short_daemon "d" - #define controller_short_init "I" - #define controller_short_interruptable "i" - #define controller_short_pid "p" - #define controller_short_settings "s" - #define controller_short_simulate "S" - #define controller_short_validate "v" - - #define controller_long_control "control" - #define controller_long_daemon "daemon" - #define controller_long_init "init" - #define controller_long_interruptable "interruptable" - #define controller_long_pid "pid" - #define controller_long_settings "settings" - #define controller_long_simulate "simulate" - #define controller_long_validate "validate" + #define controller_short_control "c" + #define controller_short_daemon "d" + #define controller_short_init "I" + #define controller_short_interruptable "i" + #define controller_short_pid "p" + #define controller_short_settings "s" + #define controller_short_simulate "S" + #define controller_short_uninterruptable "U" + #define controller_short_validate "v" + + #define controller_long_control "control" + #define controller_long_daemon "daemon" + #define controller_long_init "init" + #define controller_long_interruptable "interruptable" + #define controller_long_pid "pid" + #define controller_long_settings "settings" + #define controller_long_simulate "simulate" + #define controller_long_uninterruptable "uninterruptable" + #define controller_long_validate "validate" enum { controller_parameter_help, @@ -178,6 +180,7 @@ extern "C" { controller_parameter_pid, controller_parameter_settings, controller_parameter_simulate, + controller_parameter_uninterruptable, controller_parameter_validate, }; @@ -199,10 +202,11 @@ extern "C" { f_console_parameter_t_initialize(controller_short_pid, controller_long_pid, 0, 1, f_console_type_normal), \ f_console_parameter_t_initialize(controller_short_settings, controller_long_settings, 0, 1, f_console_type_normal), \ f_console_parameter_t_initialize(controller_short_simulate, controller_long_simulate, 0, 0, f_console_type_normal), \ + f_console_parameter_t_initialize(controller_short_uninterruptable, controller_long_uninterruptable, 0, 0, f_console_type_normal), \ f_console_parameter_t_initialize(controller_short_validate, controller_long_validate, 0, 0, f_console_type_normal), \ } - #define controller_total_parameters 17 + #define controller_total_parameters 18 #endif // _di_controller_defines_ #ifndef _di_controller_main_t_ diff --git a/level_3/controller/c/private-thread.c b/level_3/controller/c/private-thread.c index 48eaca8..fb58d3b 100644 --- a/level_3/controller/c/private-thread.c +++ b/level_3/controller/c/private-thread.c @@ -991,8 +991,7 @@ extern "C" { if (errno == EAGAIN) continue; } - if (global->main->parameters[controller_parameter_interruptable].result == f_console_result_found) { - + if (global->setting->interruptable) { if (information.si_signo == F_signal_interrupt || information.si_signo == F_signal_abort || information.si_signo == F_signal_quit || information.si_signo == F_signal_termination) { global->thread->signal = information.si_signo;