From 1583d46875a50d2f6b20a3ed9ae30eb9680c3f92 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 29 May 2021 11:29:49 -0500 Subject: [PATCH] Feature: Allow controller program to run as a non-init (and then do so by default). The controller program is written more generally. Take one step further and make the default to run generally. Then provide the option to operate as an init program. This frees up the controller program's default behavior to just be a "controller" rather than an "init controller". Furthermore, provide options to change easily override the "init controller" paths at compile time without redefining all of the other defines in the "_di_controller_defines_" block. --- level_3/controller/c/controller.c | 16 ++++++++++++-- level_3/controller/c/controller.h | 40 +++++++++++++++++++++++++++++------ level_3/controller/data/build/defines | 5 +++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index 0be7382..7cc45d4 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -29,6 +29,7 @@ extern "C" { 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_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(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 "'."); fll_program_print_help_option(output, 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 "'."); @@ -181,7 +182,12 @@ extern "C" { } } else { - status = f_string_append(controller_path_settings, controller_path_settings_length, &setting.path_setting); + if (main->parameters[controller_parameter_init].result == f_console_result_found) { + status = f_string_append(controller_path_settings_init, controller_path_settings_init_length, &setting.path_setting); + } + else { + status = f_string_append(controller_path_settings, controller_path_settings_length, &setting.path_setting); + } if (F_status_is_error(status)) { if (main->error.verbosity != f_console_verbosity_quiet) { @@ -224,7 +230,13 @@ extern "C" { // a pid file path is required. if (!setting.path_pid.used) { - status = f_string_append(controller_path_pid, controller_path_pid_length, &setting.path_pid); + + if (main->parameters[controller_parameter_init].result == f_console_result_found) { + status = f_string_append(controller_path_pid_init, controller_path_pid_init_length, &setting.path_pid); + } + else { + status = f_string_append(controller_path_pid, controller_path_pid_length, &setting.path_pid); + } if (F_status_is_error_not(status)) { status = f_string_append(setting.name_entry.string, setting.name_entry.used, &setting.path_pid); diff --git a/level_3/controller/c/controller.h b/level_3/controller/c/controller.h index f859927..312d613 100644 --- a/level_3/controller/c/controller.h +++ b/level_3/controller/c/controller.h @@ -90,24 +90,47 @@ extern "C" { #endif // _di_controller_version_ #ifndef _di_controller_name_ - #define controller_name "controller" + #define controller_name "controller" #define controller_name_long "Controller Program" #endif // _di_controller_name_ #ifndef _di_controller_defines_ - #define controller_default_program_script "bash" + // the init pid path is a system-specific path and needs to be more easily contolled at compile time. + #if defined(_override_controller_path_pid_init_) && defined(_override_controller_path_pid_init_length_) + #define controller_path_pid_init _override_controller_path_pid_init_ + #define controller_path_pid_init_length _override_controller_path_pid_init_length_ + #else + #define controller_path_pid_init "/var/run/controller/controller-" + #define controller_path_pid_init_length 31 + #endif /* defined(_override_controller_path_pid_init_) && defined(_override_controller_path_pid_init_length_) */ - #define controller_path_pid "/var/run/controller/controller-" - #define controller_path_settings "/etc/controller" + // the settings path is a system-specific path and needs to be more easily contolled at compile time. + #if defined(_override_controller_path_settings_init_) && defined(_override_controller_path_settings_init_length_) + #define controller_path_settings_init _override_controller_path_settings_init_ + #define controller_path_settings_init_length _override_controller_path_settings_init_length_ + #else + #define controller_path_settings_init "/etc/controller" + #define controller_path_settings_init_length 15 + #endif /* defined(_override_controller_path_settings_init_) && defined(_override_controller_path_settings_init_length_) */ + + #ifdef _override_controller_default_program_script_ + #define controller_default_program_script _override_controller_default_program_script_ + #else + #define controller_default_program_script "bash" + #endif // _override_controller_default_program_script_ + + #define controller_path_pid "controller/run/controller-" + #define controller_path_settings "controller" #define controller_path_suffix ".pid" - #define controller_path_pid_length 31 - #define controller_path_settings_length 15 + #define controller_path_pid_length 26 + #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" @@ -116,6 +139,7 @@ extern "C" { #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" @@ -135,6 +159,7 @@ extern "C" { controller_parameter_control, controller_parameter_daemon, + controller_parameter_init, controller_parameter_interruptable, controller_parameter_pid, controller_parameter_settings, @@ -155,6 +180,7 @@ extern "C" { f_console_parameter_t_initialize(f_console_standard_short_version_s, f_console_standard_long_version_s, 0, 0, f_console_type_inverse), \ f_console_parameter_t_initialize(controller_short_control, controller_long_control, 0, 1, f_console_type_normal), \ f_console_parameter_t_initialize(controller_short_daemon, controller_long_daemon, 0, 0, f_console_type_normal), \ + f_console_parameter_t_initialize(controller_short_init, controller_long_init, 0, 0, f_console_type_normal), \ f_console_parameter_t_initialize(controller_short_interruptable, controller_long_interruptable, 0, 0, f_console_type_normal), \ 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), \ @@ -162,7 +188,7 @@ extern "C" { f_console_parameter_t_initialize(controller_short_validate, controller_long_validate, 0, 0, f_console_type_normal), \ } - #define controller_total_parameters 16 + #define controller_total_parameters 17 #endif // _di_controller_defines_ #ifndef _di_controller_main_t_ diff --git a/level_3/controller/data/build/defines b/level_3/controller/data/build/defines index 427a9c7..618e9b3 100644 --- a/level_3/controller/data/build/defines +++ b/level_3/controller/data/build/defines @@ -2,5 +2,10 @@ _di_libcap_ Disable libcap support, allow for compiling and linking without libcap (-lcap). _libcap_legacy_only_ Disable functionality provided by later versions of libcap (2.43 and later). +_override_controller_default_program_script_ Provide a custom script name string to execute (such as php). +_override_controller_path_pid_init_ Provide a custom init path for the system rather than the default. +_override_controller_path_pid_init_length_ The number of bytes representing the string in _override_controller_path_pid_init_ (not including the terminating NULL). +_override_controller_path_settings_init_ Provide a custom init path for the system rather than the default. +_override_controller_path_settings_init_length_ The number of bytes representing the string in _override_controller_path_settings_init_ (not including the terminating NULL). _pthread_attr_unsupported_ Disable non-portable functionality associated with pthread_attr. _pthread_sigqueue_unsupported_ Disable GNU specific sigqueue(). -- 1.8.3.1