From: Kevin Day Date: Wed, 27 Apr 2022 05:08:32 +0000 (-0500) Subject: Bugfix: When compiled as "init" the controller program does not use the correct paths. X-Git-Tag: 0.5.10~179 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b3dca4622c1c30718a24873da64bf3ea7417dd89;p=fll Bugfix: When compiled as "init" the controller program does not use the correct paths. The isolation between the "init" specific changes and the normal "controller" specific code is insufficient. Move all of the special paths into the main program, introducing a new header and source file called "main-common.h" and "main-common.c". The main program is now responsible for providing these strings. --- diff --git a/level_3/controller/c/common.c b/level_3/controller/c/common.c index 8e928d6..30db3ed 100644 --- a/level_3/controller/c/common.c +++ b/level_3/controller/c/common.c @@ -9,28 +9,6 @@ extern "C" { const f_string_static_t controller_program_version_s = macro_f_string_static_t_initialize(CONTROLLER_program_version_s, 0, CONTROLLER_program_version_s_length); #endif // _di_controller_program_version_ -#ifndef _di_controller_program_name_ - const f_string_static_t controller_program_name_s = macro_f_string_static_t_initialize(CONTROLLER_program_name_s, 0, CONTROLLER_program_name_s_length); - const f_string_static_t controller_program_name_long_s = macro_f_string_static_t_initialize(CONTROLLER_program_name_long_s, 0, CONTROLLER_program_name_long_s_length); - - const f_string_static_t controller_program_name_init_s = macro_f_string_static_t_initialize(CONTROLLER_program_name_init_s, 0, CONTROLLER_program_name_init_s_length); - const f_string_static_t controller_program_name_init_long_s = macro_f_string_static_t_initialize(CONTROLLER_program_name_init_long_s, 0, CONTROLLER_program_name_init_long_s_length); -#endif // _di_controller_program_name_ - -#ifndef _di_controller_defines_ - const f_string_static_t controller_default_program_script_s = macro_f_string_static_t_initialize(CONTROLLER_default_program_script_s, 0, CONTROLLER_default_program_script_s_length); - const f_string_static_t controller_path_pid_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_s, 0, CONTROLLER_path_pid_s_length); - const f_string_static_t controller_path_pid_init_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_init_s, 0, CONTROLLER_path_pid_init_s_length); - const f_string_static_t controller_path_pid_prefix_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_prefix_s, 0, CONTROLLER_path_pid_prefix_s_length); - const f_string_static_t controller_path_pid_suffix_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_suffix_s, 0, CONTROLLER_path_pid_suffix_s_length); - const f_string_static_t controller_path_settings_s = macro_f_string_static_t_initialize(CONTROLLER_path_settings_s, 0, CONTROLLER_path_settings_s_length); - const f_string_static_t controller_path_settings_init_s = macro_f_string_static_t_initialize(CONTROLLER_path_settings_init_s, 0, CONTROLLER_path_settings_init_s_length); - const f_string_static_t controller_path_socket_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_s, 0, CONTROLLER_path_socket_s_length); - const f_string_static_t controller_path_socket_init_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_init_s, 0, CONTROLLER_path_socket_s_length); - const f_string_static_t controller_path_socket_prefix_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_prefix_s, 0, CONTROLLER_path_socket_prefix_s_length); - const f_string_static_t controller_path_socket_suffix_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_suffix_s, 0, CONTROLLER_path_socket_suffix_s_length); -#endif // _di_controller_defines_ - #ifndef _di_controller_parameters_ const f_string_static_t controller_short_cgroup_s = macro_f_string_static_t_initialize(CONTROLLER_short_cgroup_s, 0, CONTROLLER_short_cgroup_s_length); const f_string_static_t controller_short_daemon_s = macro_f_string_static_t_initialize(CONTROLLER_short_daemon_s, 0, CONTROLLER_short_daemon_s_length); @@ -241,6 +219,9 @@ extern "C" { macro_f_color_context_t_delete_simple(main->context); + f_string_dynamic_resize(0, &main->path_pid); + f_string_dynamic_resize(0, &main->path_setting); + return F_none; } #endif // _di_controller_main_delete_ diff --git a/level_3/controller/c/common.h b/level_3/controller/c/common.h index 2de0e39..57efb92 100644 --- a/level_3/controller/c/common.h +++ b/level_3/controller/c/common.h @@ -46,163 +46,6 @@ extern "C" { #endif // _di_controller_program_version_ /** - * The program name. - */ -#ifndef _di_controller_program_name_ - #define CONTROLLER_program_name_s "controller" - #define CONTROLLER_program_name_long_s "Controller Program" - - #define CONTROLLER_program_name_init_s "init" - #define CONTROLLER_program_name_init_long_s "Init Program" - - #define CONTROLLER_program_name_s_length 10 - #define CONTROLLER_program_name_long_s_length 18 - - #define CONTROLLER_program_name_init_s_length 4 - #define CONTROLLER_program_name_init_long_s_length 12 - - extern const f_string_static_t controller_program_name_s; - extern const f_string_static_t controller_program_name_long_s; - - extern const f_string_static_t controller_program_name_init_s; - extern const f_string_static_t controller_program_name_init_long_s; -#endif // _di_controller_program_name_ - -/** - * The program defines. - */ -#ifndef _di_controller_defines_ - - // The pid path is a system-specific path and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_pid_) && defined(_override_controller_path_pid_length_) - #define CONTROLLER_path_pid_s _override_controller_path_pid_ - #define CONTROLLER_path_pid_s_length _override_controller_path_pid_length_ - #else - #define CONTROLLER_path_pid_s "controller/run" - #define CONTROLLER_path_pid_s_length 14 - #endif // defined(_override_controller_path_pid_) && defined(_override_controller_path_pid_length_) - - // 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_s _override_controller_path_pid_init_ - #define CONTROLLER_path_pid_init_s_length _override_controller_path_pid_init_length_ - #elif defined(_controller_as_init_) - #define CONTROLLER_path_pid_init_s "/var/run/init" - #define CONTROLLER_path_pid_init_s_length 13 - #else - #define CONTROLLER_path_pid_init_s "/var/run/controller" - #define CONTROLLER_path_pid_init_s_length 19 - #endif // defined(_override_controller_path_pid_init_) && defined(_override_controller_path_pid_init_length_) - - // The pid prefix is a system-specific path part and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_pid_prefix_) && defined(_override_controller_path_pid_prefix_length_) - #define CONTROLLER_path_pid_prefix_s _override_controller_path_pid_prefix_ - - #define CONTROLLER_path_pid_prefix_s_length _override_controller_path_pid_prefix_length_ - #elif defined(_controller_as_init_) - #define CONTROLLER_path_pid_prefix_s "init-" - #define CONTROLLER_path_pid_prefix_s_length 5 - #else - #define CONTROLLER_path_pid_prefix_s "" - #define CONTROLLER_path_pid_prefix_s_length 0 - #endif // defined(_override_controller_name_pid_prefix_) && defined(_override_controller_name_pid_prefix_length_) - - // The socket suffix path is a system-specific path part and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_pid_suffix_) && defined(_override_controller_path_pid_suffix_length_) - #define CONTROLLER_path_pid_suffix_s _override_controller_path_pid_suffix_ - #define CONTROLLER_path_pid_suffix_s_length _override_controller_path_pid_suffix_length_ - #else - #define CONTROLLER_path_pid_suffix_s ".pid" - #define CONTROLLER_path_pid_suffix_s_length 4 - #endif // defined(_override_controller_name_pid_suffix_) && defined(_override_controller_name_pid_suffix_length_) - - // The settings path is a system-specific path part and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_settings_) && defined(_override_controller_path_settings_length_) - #define CONTROLLER_path_settings_s _override_controller_path_settings_ - #define CONTROLLER_path_settings_s_length _override_controller_path_settings_length_ - #else - #define CONTROLLER_path_settings_s "controller" - #define CONTROLLER_path_settings_s_length 10 - #endif // defined(_override_controller_path_settings_) && defined(_override_controller_path_settings_length_) - - // The init settings path is a system-specific path part 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_s _override_controller_path_settings_init_ - #define CONTROLLER_path_settings_init_s_length _override_controller_path_settings_init_length_ - #elif defined(_controller_as_init_) - #define CONTROLLER_path_settings_init_s "/etc/init" - #define CONTROLLER_path_settings_init_s_length 9 - #else - #define CONTROLLER_path_settings_init_s "/etc/controller" - #define CONTROLLER_path_settings_init_s_length 15 - #endif // defined(_override_controller_path_settings_init_) && defined(_override_controller_path_settings_init_length_) - - // The socket path is a system-specific path and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_socket_) && defined(_override_controller_path_socket_length_) - #define CONTROLLER_path_socket_s _override_controller_path_socket_ - #define CONTROLLER_path_socket_s_length _override_controller_path_socket_length_ - #else - #define CONTROLLER_path_socket_s "controller/run" - #define CONTROLLER_path_socket_s_length 14 - #endif // defined(_override_controller_path_socket_) && defined(_override_controller_path_socket_length_) - - // The socket path is a system-specific path and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_socket_init_) && defined(_override_controller_path_socket_init_length_) - #define CONTROLLER_path_socket_init_s _override_controller_path_socket_init_ - - #define CONTROLLER_path_socket_init_s_length _override_controller_path_socket_init_length_ - #elif defined(_controller_as_init_) - #define CONTROLLER_path_socket_init_s "/var/run/init" - #define CONTROLLER_path_socket_init_s_length 13 - #else - #define CONTROLLER_path_socket_init_s "/var/run/controller" - #define CONTROLLER_path_socket_init_s_length 19 - #endif // defined(_override_controller_path_socket_init_) && defined(_override_controller_path_socket_init_length_) - - // The socket prefix path is a system-specific path part and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_socket_prefix_) && defined(_override_controller_path_socket_prefix_length_) - #define CONTROLLER_path_socket_prefix_s _override_controller_path_socket_prefix_ - - #define CONTROLLER_path_socket_prefix_s_length _override_controller_path_socket_prefix_length_ - #elif defined(_controller_as_init_) - #define CONTROLLER_path_socket_prefix_s "init-" - #define CONTROLLER_path_socket_prefix_s_length 5 - #else - #define CONTROLLER_path_socket_prefix_s "" - #define CONTROLLER_path_socket_prefix_s_length 0 - #endif // defined(_override_controller_path_socket_prefix_) && defined(_override_controller_path_socket_prefix_length_) - - // The socket suffix path is a system-specific path part and needs to be more easily contolled at compile time. - #if defined(_override_controller_path_socket_suffix_) && defined(_override_controller_path_socket_suffix_length_) - #define CONTROLLER_path_socket_suffix_s _override_controller_path_socket_suffix_ - #define CONTROLLER_path_socket_suffix_s_length _override_controller_path_socket_suffix_length_ - #else - #define CONTROLLER_path_socket_suffix_s ".socket" - #define CONTROLLER_path_socket_suffix_s_length 7 - #endif // defined(_override_controller_path_socket_suffix_) && defined(_override_controller_path_socket_suffix_length_) - - #if defined(_override_controller_default_program_script_) && defined(_override_controller_default_program_script_length_) - #define CONTROLLER_default_program_script_s _override_controller_default_program_script_ - #define CONTROLLER_default_program_script_s_length _override_controller_default_program_script_length_ - #else - #define CONTROLLER_default_program_script_s "bash" - #define CONTROLLER_default_program_script_s_length 4 - #endif // defined(_override_controller_default_program_script_) && defined(_override_controller_default_program_script_length_) - - extern const f_string_static_t controller_default_program_script_s; - extern const f_string_static_t controller_path_pid_s; - extern const f_string_static_t controller_path_pid_init_s; - extern const f_string_static_t controller_path_pid_prefix_s; - extern const f_string_static_t controller_path_pid_suffix_s; - extern const f_string_static_t controller_path_settings_s; - extern const f_string_static_t controller_path_settings_init_s; - extern const f_string_static_t controller_path_socket_s; - extern const f_string_static_t controller_path_socket_init_s; - extern const f_string_static_t controller_path_socket_prefix_s; - extern const f_string_static_t controller_path_socket_suffix_s; -#endif // _di_controller_defines_ - -/** * The main program parameters. */ #ifndef _di_controller_parameters_ @@ -358,11 +201,22 @@ extern "C" { mode_t umask; int child; - const f_string_static_t *program_name; - const f_string_static_t *program_name_long; - const f_string_static_t *default_path_setting; const f_string_static_t *default_path_pid; + const f_string_static_t *default_path_pid_init; + const f_string_static_t *default_path_pid_prefix; + const f_string_static_t *default_path_pid_suffix; + const f_string_static_t *default_path_setting; + const f_string_static_t *default_path_setting_init; const f_string_static_t *default_path_socket; + const f_string_static_t *default_path_socket_init; + const f_string_static_t *default_path_socket_prefix; + const f_string_static_t *default_path_socket_suffix; + const f_string_static_t *default_program_script; + const f_string_static_t *program_name; + const f_string_static_t *program_name_long; + + f_string_dynamic_t path_pid; + f_string_dynamic_t path_setting; f_color_context_t context; } controller_main_t; @@ -384,6 +238,16 @@ extern "C" { 0, \ 0, \ 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + 0, \ + f_string_dynamic_t_initialize, \ + f_string_dynamic_t_initialize, \ f_color_context_t_initialize, \ } #endif // _di_controller_main_t_ diff --git a/level_3/controller/c/controller.c b/level_3/controller/c/controller.c index ee4560c..69b25cc 100644 --- a/level_3/controller/c/controller.c +++ b/level_3/controller/c/controller.c @@ -15,6 +15,26 @@ extern "C" { #ifndef _di_controller_print_help_ f_status_t controller_print_help(controller_main_t * const main) { + const f_string_static_t *path_setting = main->as_init ? main->default_path_setting_init : main->default_path_setting; + const f_string_static_t *path_socket = main->as_init ? main->default_path_socket_init : main->default_path_socket; + const f_string_static_t *path_pid = main->as_init ? main->default_path_pid_init : main->default_path_pid; + + const int specify_custom_pid_length = 55 + path_pid->used + f_path_separator_s.used + controller_default_s.used + main->default_path_pid_suffix->used; + const int specify_path_settings_length = 50 + path_setting->used + f_path_separator_s.used; + const int specify_path_socket_length = 55 + path_socket->used + f_path_separator_s.used + controller_default_s.used + main->default_path_socket_suffix->used; + + char specify_custom_pid[specify_custom_pid_length + 1]; + char specify_path_settings[specify_path_settings_length + 1]; + char specify_path_socket[specify_path_socket_length + 1]; + + specify_custom_pid[specify_custom_pid_length] = 0; + specify_path_settings[specify_path_settings_length] = 0; + specify_path_socket[specify_path_socket_length] = 0; + + sprintf(specify_custom_pid, " Specify a custom pid file path, such as '%s%s%s%s'.", path_pid->string, f_path_separator_s.string, controller_default_s.string, main->default_path_pid_suffix->string); + sprintf(specify_path_settings, " Specify a custom settings path, such as '%s%s'.", path_setting->string, f_path_separator_s.string); + sprintf(specify_path_socket, " Specify a custom socket file path, such as '%s%s%s%s'.", path_socket->string, f_path_separator_s.string, controller_default_s.string, main->default_path_socket_suffix->string); + controller_lock_print(main->output.to, 0); fll_program_print_help_header(main->output.to, main->context, *main->program_name_long, controller_program_version_s); @@ -26,7 +46,7 @@ extern "C" { fll_program_print_help_option(main->output.to, main->context, f_console_standard_short_quiet_s, f_console_standard_long_quiet_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Decrease verbosity beyond normal main->output.to."); fll_program_print_help_option(main->output.to, main->context, f_console_standard_short_normal_s, f_console_standard_long_normal_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Set verbosity to normal main->output.to."); fll_program_print_help_option(main->output.to, main->context, f_console_standard_short_verbose_s, f_console_standard_long_verbose_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Increase verbosity beyond normal main->output.to."); - fll_program_print_help_option(main->output.to, main->context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, inceasing verbosity beyond normal main->output.to."); + fll_program_print_help_option(main->output.to, main->context, f_console_standard_short_debug_s, f_console_standard_long_debug_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Enable debugging, increasing verbosity beyond normal main->output.to."); fll_program_print_help_option(main->output.to, main->context, f_console_standard_short_version_s, f_console_standard_long_version_s, f_console_symbol_short_disable_s, f_console_symbol_long_disable_s, " Print only the version number."); f_print_dynamic_raw(f_string_eol_s, main->output.to.stream); @@ -35,10 +55,10 @@ extern "C" { fll_program_print_help_option(main->output.to, main->context, controller_short_daemon_s, controller_long_daemon_s, 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.to, main->context, controller_short_init_s, controller_long_init_s, 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.to, main->context, controller_short_interruptible_s, controller_long_interruptible_s, 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.to, main->context, controller_short_pid_s, controller_long_pid_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom pid file path, such as '" CONTROLLER_path_pid_s F_path_separator_s CONTROLLER_default_s CONTROLLER_path_pid_suffix_s "'."); - fll_program_print_help_option(main->output.to, main->context, controller_short_settings_s, controller_long_settings_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom settings path, such as '" CONTROLLER_path_settings_s F_path_separator_s "'."); + fll_program_print_help_option(main->output.to, main->context, controller_short_pid_s, controller_long_pid_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, specify_custom_pid); + fll_program_print_help_option(main->output.to, main->context, controller_short_settings_s, controller_long_settings_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, specify_path_settings); fll_program_print_help_option(main->output.to, main->context, controller_short_simulate_s, controller_long_simulate_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Run as a simulation."); - fll_program_print_help_option(main->output.to, main->context, controller_short_socket_s, controller_long_socket_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Specify a custom socket file path, such as '" CONTROLLER_path_socket_s F_path_separator_s CONTROLLER_default_s CONTROLLER_path_socket_suffix_s "'."); + fll_program_print_help_option(main->output.to, main->context, controller_short_socket_s, controller_long_socket_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, specify_path_socket); fll_program_print_help_option(main->output.to, main->context, controller_short_uninterruptible_s, controller_long_uninterruptible_s, 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.to, main->context, controller_short_validate_s, controller_long_validate_s, f_console_symbol_short_enable_s, f_console_symbol_long_enable_s, " Validate the settings (entry and rules) without running (does not simulate)."); @@ -47,11 +67,7 @@ extern "C" { fl_print_format(" When both the %[%r%r%] parameter and the", main->output.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, controller_long_simulate_s, main->context.set.notable); fl_print_format(" %[%r%r%] parameter are specified, then additional information on each would be executed rule is printed but no simulation is performed.%r%r", main->output.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, controller_long_validate_s, main->context.set.notable, f_string_eol_s, f_string_eol_s); - #ifdef _controller_as_init_ - const f_string_static_t interruptable = controller_long_uninterruptible_s; - #else - const f_string_static_t interruptable = controller_long_interruptible_s; - #endif // _controller_as_init_ + const f_string_static_t interruptable = main->as_init ? controller_long_uninterruptible_s : controller_long_interruptible_s; fl_print_format(" The default interrupt behavior is to operate as if the %[%r%r%] parameter is passed.%r%r", main->output.to.stream, main->context.set.notable, f_console_symbol_long_enable_s, interruptable, main->context.set.notable, f_string_eol_s, f_string_eol_s); @@ -214,14 +230,13 @@ extern "C" { } } else { - if (main->parameters.array[controller_parameter_init_e].result == f_console_result_found_e && !main->as_init) { - status = f_string_dynamic_append(controller_path_settings_init_s, &setting.path_setting); - } - else if (main->default_path_setting->used) { - status = f_string_dynamic_append(*main->default_path_setting, &setting.path_setting); + setting.path_setting.used = 0; + + if (main->as_init) { + status = f_string_dynamic_append(*main->default_path_setting_init, &setting.path_setting); } else { - status = f_string_dynamic_append(controller_path_settings_s, &setting.path_setting); + status = f_string_dynamic_append(*main->default_path_setting, &setting.path_setting); } if (F_status_is_error(status)) { @@ -245,6 +260,8 @@ extern "C" { status = F_status_set_error(F_parameter); } else if (main->parameters.array[controller_parameter_pid_e].locations.used) { + setting.path_pid.used = 0; + const f_array_length_t index = main->parameters.array[controller_parameter_pid_e].values.array[main->parameters.array[controller_parameter_pid_e].values.used - 1]; if (argv[index].used) { @@ -254,15 +271,12 @@ extern "C" { fll_error_file_print(main->error, F_status_set_fine(status), "controller_path_canonical_relative", F_true, argv[index], f_file_operation_verify_s, fll_error_file_type_path_e); } } - else { - setting.path_pid.used = 0; - } } } if (F_status_is_error_not(status) && !setting.path_pid.used && !main->parameters.array[controller_parameter_pid_e].locations.used) { - if (main->parameters.array[controller_parameter_init_e].result == f_console_result_found_e) { - status = f_string_dynamic_append(controller_path_pid_init_s, &setting.path_pid); + if (main->as_init) { + status = f_string_dynamic_append(*main->default_path_pid_init, &setting.path_pid); } else { status = f_string_dynamic_append(*main->default_path_pid, &setting.path_pid); @@ -273,7 +287,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = f_string_dynamic_append(controller_path_pid_prefix_s, &setting.path_pid); + status = f_string_dynamic_append(*main->default_path_pid_prefix, &setting.path_pid); } if (F_status_is_error_not(status)) { @@ -281,7 +295,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = f_string_dynamic_append(controller_path_pid_suffix_s, &setting.path_pid); + status = f_string_dynamic_append(*main->default_path_pid_suffix, &setting.path_pid); } if (F_status_is_error(status)) { diff --git a/level_3/controller/c/main-common.c b/level_3/controller/c/main-common.c new file mode 100644 index 0000000..bae8976 --- /dev/null +++ b/level_3/controller/c/main-common.c @@ -0,0 +1,29 @@ +#include "controller.h" +#include "main-common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_program_name_ + const f_string_static_t controller_program_name_s = macro_f_string_static_t_initialize(CONTROLLER_program_name_s, 0, CONTROLLER_program_name_s_length); + const f_string_static_t controller_program_name_long_s = macro_f_string_static_t_initialize(CONTROLLER_program_name_long_s, 0, CONTROLLER_program_name_long_s_length); +#endif // _di_controller_program_name_ + +#ifndef _di_controller_defines_ + const f_string_static_t controller_default_program_script_s = macro_f_string_static_t_initialize(CONTROLLER_default_program_script_s, 0, CONTROLLER_default_program_script_s_length); + const f_string_static_t controller_path_pid_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_s, 0, CONTROLLER_path_pid_s_length); + const f_string_static_t controller_path_pid_init_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_init_s, 0, CONTROLLER_path_pid_init_s_length); + const f_string_static_t controller_path_pid_prefix_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_prefix_s, 0, CONTROLLER_path_pid_prefix_s_length); + const f_string_static_t controller_path_pid_suffix_s = macro_f_string_static_t_initialize(CONTROLLER_path_pid_suffix_s, 0, CONTROLLER_path_pid_suffix_s_length); + const f_string_static_t controller_path_settings_s = macro_f_string_static_t_initialize(CONTROLLER_path_settings_s, 0, CONTROLLER_path_settings_s_length); + const f_string_static_t controller_path_settings_init_s = macro_f_string_static_t_initialize(CONTROLLER_path_settings_init_s, 0, CONTROLLER_path_settings_init_s_length); + const f_string_static_t controller_path_socket_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_s, 0, CONTROLLER_path_socket_s_length); + const f_string_static_t controller_path_socket_init_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_init_s, 0, CONTROLLER_path_socket_s_length); + const f_string_static_t controller_path_socket_prefix_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_prefix_s, 0, CONTROLLER_path_socket_prefix_s_length); + const f_string_static_t controller_path_socket_suffix_s = macro_f_string_static_t_initialize(CONTROLLER_path_socket_suffix_s, 0, CONTROLLER_path_socket_suffix_s_length); +#endif // _di_controller_defines_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_3/controller/c/main-common.h b/level_3/controller/c/main-common.h new file mode 100644 index 0000000..bb60444 --- /dev/null +++ b/level_3/controller/c/main-common.h @@ -0,0 +1,177 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.5 + * Licenses: lgpl-2.1-or-later + * + * Provides the common data structures to be compiled into the main program rather than the library. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_h +#define _controller_main_common_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The program name. + */ +#ifndef _di_controller_program_name_ + #ifdef _controller_as_init_ + #define CONTROLLER_program_name_s "init" + #define CONTROLLER_program_name_long_s "Init Program" + + #define CONTROLLER_program_name_s_length 4 + #define CONTROLLER_program_name_long_s_length 12 + #else + #define CONTROLLER_program_name_s "controller" + #define CONTROLLER_program_name_long_s "Controller Program" + + #define CONTROLLER_program_name_s_length 10 + #define CONTROLLER_program_name_long_s_length 18 + #endif // _controller_as_init_ + + extern const f_string_static_t controller_program_name_s; + extern const f_string_static_t controller_program_name_long_s; +#endif // _di_controller_program_name_ + +/** + * The program defines. + */ +#ifndef _di_controller_defines_ + + // The pid path is a system-specific path and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_pid_) && defined(_override_controller_path_pid_length_) + #define CONTROLLER_path_pid_s _override_controller_path_pid_ + #define CONTROLLER_path_pid_s_length _override_controller_path_pid_length_ + #else + #define CONTROLLER_path_pid_s "controller/run" + #define CONTROLLER_path_pid_s_length 14 + #endif // defined(_override_controller_path_pid_) && defined(_override_controller_path_pid_length_) + + // The init pid path is a system-specific path and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_pid_init_) && defined(_override_controller_path_pid_init_length_) + #define CONTROLLER_path_pid_init_s _override_controller_path_pid_init_ + #define CONTROLLER_path_pid_init_s_length _override_controller_path_pid_init_length_ + #elif defined(_controller_as_init_) + #define CONTROLLER_path_pid_init_s "/var/run/init" + #define CONTROLLER_path_pid_init_s_length 13 + #else + #define CONTROLLER_path_pid_init_s "/var/run/controller" + #define CONTROLLER_path_pid_init_s_length 19 + #endif // defined(_override_controller_path_pid_init_) && defined(_override_controller_path_pid_init_length_) + + // The pid prefix is a system-specific path part and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_pid_prefix_) && defined(_override_controller_path_pid_prefix_length_) + #define CONTROLLER_path_pid_prefix_s _override_controller_path_pid_prefix_ + + #define CONTROLLER_path_pid_prefix_s_length _override_controller_path_pid_prefix_length_ + #elif defined(_controller_as_init_) + #define CONTROLLER_path_pid_prefix_s "init-" + #define CONTROLLER_path_pid_prefix_s_length 5 + #else + #define CONTROLLER_path_pid_prefix_s "" + #define CONTROLLER_path_pid_prefix_s_length 0 + #endif // defined(_override_controller_name_pid_prefix_) && defined(_override_controller_name_pid_prefix_length_) + + // The socket suffix path is a system-specific path part and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_pid_suffix_) && defined(_override_controller_path_pid_suffix_length_) + #define CONTROLLER_path_pid_suffix_s _override_controller_path_pid_suffix_ + #define CONTROLLER_path_pid_suffix_s_length _override_controller_path_pid_suffix_length_ + #else + #define CONTROLLER_path_pid_suffix_s ".pid" + #define CONTROLLER_path_pid_suffix_s_length 4 + #endif // defined(_override_controller_name_pid_suffix_) && defined(_override_controller_name_pid_suffix_length_) + + // The settings path is a system-specific path part and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_settings_) && defined(_override_controller_path_settings_length_) + #define CONTROLLER_path_settings_s _override_controller_path_settings_ + #define CONTROLLER_path_settings_s_length _override_controller_path_settings_length_ + #else + #define CONTROLLER_path_settings_s "controller" + #define CONTROLLER_path_settings_s_length 10 + #endif // defined(_override_controller_path_settings_) && defined(_override_controller_path_settings_length_) + + // The init settings path is a system-specific path part and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_settings_init_) && defined(_override_controller_path_settings_init_length_) + #define CONTROLLER_path_settings_init_s _override_controller_path_settings_init_ + #define CONTROLLER_path_settings_init_s_length _override_controller_path_settings_init_length_ + #elif defined(_controller_as_init_) + #define CONTROLLER_path_settings_init_s "/etc/init" + #define CONTROLLER_path_settings_init_s_length 9 + #else + #define CONTROLLER_path_settings_init_s "/etc/controller" + #define CONTROLLER_path_settings_init_s_length 15 + #endif // defined(_override_controller_path_settings_init_) && defined(_override_controller_path_settings_init_length_) + + // The socket path is a system-specific path and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_socket_) && defined(_override_controller_path_socket_length_) + #define CONTROLLER_path_socket_s _override_controller_path_socket_ + #define CONTROLLER_path_socket_s_length _override_controller_path_socket_length_ + #else + #define CONTROLLER_path_socket_s "controller/run" + #define CONTROLLER_path_socket_s_length 14 + #endif // defined(_override_controller_path_socket_) && defined(_override_controller_path_socket_length_) + + // The socket path is a system-specific path and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_socket_init_) && defined(_override_controller_path_socket_init_length_) + #define CONTROLLER_path_socket_init_s _override_controller_path_socket_init_ + #define CONTROLLER_path_socket_init_s_length _override_controller_path_socket_init_length_ + #elif defined(_controller_as_init_) + #define CONTROLLER_path_socket_init_s "/var/run/init" + #define CONTROLLER_path_socket_init_s_length 13 + #else + #define CONTROLLER_path_socket_init_s "/var/run/controller" + #define CONTROLLER_path_socket_init_s_length 19 + #endif // defined(_override_controller_path_socket_init_) && defined(_override_controller_path_socket_init_length_) + + // The socket prefix path is a system-specific path part and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_socket_prefix_) && defined(_override_controller_path_socket_prefix_length_) + #define CONTROLLER_path_socket_prefix_s _override_controller_path_socket_prefix_ + #define CONTROLLER_path_socket_prefix_s_length _override_controller_path_socket_prefix_length_ + #elif defined(_controller_as_init_) + #define CONTROLLER_path_socket_prefix_s "init-" + #define CONTROLLER_path_socket_prefix_s_length 5 + #else + #define CONTROLLER_path_socket_prefix_s "" + #define CONTROLLER_path_socket_prefix_s_length 0 + #endif // defined(_override_controller_path_socket_prefix_) && defined(_override_controller_path_socket_prefix_length_) + + // The socket suffix path is a system-specific path part and needs to be more easily controlled at compile time. + #if defined(_override_controller_path_socket_suffix_) && defined(_override_controller_path_socket_suffix_length_) + #define CONTROLLER_path_socket_suffix_s _override_controller_path_socket_suffix_ + #define CONTROLLER_path_socket_suffix_s_length _override_controller_path_socket_suffix_length_ + #else + #define CONTROLLER_path_socket_suffix_s ".socket" + #define CONTROLLER_path_socket_suffix_s_length 7 + #endif // defined(_override_controller_path_socket_suffix_) && defined(_override_controller_path_socket_suffix_length_) + + #if defined(_override_controller_default_program_script_) && defined(_override_controller_default_program_script_length_) + #define CONTROLLER_default_program_script_s _override_controller_default_program_script_ + #define CONTROLLER_default_program_script_s_length _override_controller_default_program_script_length_ + #else + #define CONTROLLER_default_program_script_s "bash" + #define CONTROLLER_default_program_script_s_length 4 + #endif // defined(_override_controller_default_program_script_) && defined(_override_controller_default_program_script_length_) + + extern const f_string_static_t controller_default_program_script_s; + extern const f_string_static_t controller_path_pid_s; + extern const f_string_static_t controller_path_pid_init_s; + extern const f_string_static_t controller_path_pid_prefix_s; + extern const f_string_static_t controller_path_pid_suffix_s; + extern const f_string_static_t controller_path_settings_s; + extern const f_string_static_t controller_path_settings_init_s; + extern const f_string_static_t controller_path_socket_s; + extern const f_string_static_t controller_path_socket_init_s; + extern const f_string_static_t controller_path_socket_prefix_s; + extern const f_string_static_t controller_path_socket_suffix_s; +#endif // _di_controller_defines_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_h diff --git a/level_3/controller/c/main.c b/level_3/controller/c/main.c index 4c31e5a..c8698bf 100644 --- a/level_3/controller/c/main.c +++ b/level_3/controller/c/main.c @@ -1,4 +1,5 @@ #include "controller.h" +#include "main-common.h" int main(const int argc, const f_string_t *argv, const f_string_t *envp) { @@ -19,21 +20,25 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { f_file_umask_get(&data.umask); + data.default_path_setting = &controller_path_settings_s; + data.default_path_setting_init = &controller_path_settings_init_s; + data.default_path_pid = &controller_path_pid_s; + data.default_path_pid_init = &controller_path_pid_init_s; + data.default_path_pid_prefix = &controller_path_pid_prefix_s; + data.default_path_pid_suffix = &controller_path_pid_suffix_s; + data.default_path_socket = &controller_path_socket_s; + data.default_path_socket_init = &controller_path_socket_init_s; + data.default_path_socket_prefix = &controller_path_socket_prefix_s; + data.default_path_socket_suffix = &controller_path_socket_suffix_s; + data.default_program_script = &controller_default_program_script_s; + data.program_name = &controller_program_name_s; + data.program_name_long = &controller_program_name_long_s; + // When run as "init" by default, provide the default system-level init path. - // This change must only exist within this main file so that the change only exists within the program rather than the library. #ifdef _controller_as_init_ - data.program_name = &controller_program_name_init_s; - data.program_name_long = &controller_program_name_init_long_s; - data.default_path_setting = &controller_path_settings_init_s; - data.default_path_pid = &controller_path_pid_init_s; - data.default_path_socket = &controller_path_socket_init_s; data.as_init = F_true; #else - data.program_name = &controller_program_name_s; - data.program_name_long = &controller_program_name_long_s; - data.default_path_setting = &controller_path_settings_s; - data.default_path_pid = &controller_path_pid_s; - data.default_path_socket = &controller_path_socket_s; + data.as_init = F_false; #endif // _controller_as_init_ const f_status_t status = controller_main(&data, &arguments); diff --git a/level_3/controller/c/rule/private-rule.c b/level_3/controller/c/rule/private-rule.c index 8ee39d8..c24c330 100644 --- a/level_3/controller/c/rule/private-rule.c +++ b/level_3/controller/c/rule/private-rule.c @@ -1131,7 +1131,7 @@ extern "C" { status = controller_rule_execute_foreground(process->rule.items.array[i].type, process->rule.script, arguments_none, options, &execute_set, process); } else { - status = controller_rule_execute_foreground(process->rule.items.array[i].type, controller_default_program_script_s, arguments_none, options, &execute_set, process); + status = controller_rule_execute_foreground(process->rule.items.array[i].type, *global.main->default_program_script, arguments_none, options, &execute_set, process); } if (status == F_child || F_status_set_fine(status) == F_lock) break; @@ -1207,7 +1207,7 @@ extern "C" { } do { - status = controller_rule_execute_pid_with(process->rule.items.array[i].pid_file, process->rule.items.array[i].type, process->rule.script.used ? process->rule.script : controller_default_program_script_s, arguments_none, options, process->rule.items.array[i].with, &execute_set, process); + status = controller_rule_execute_pid_with(process->rule.items.array[i].pid_file, process->rule.items.array[i].type, process->rule.script.used ? process->rule.script : *global.main->default_program_script, arguments_none, options, process->rule.items.array[i].with, &execute_set, process); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; if (F_status_is_error(status) && F_status_set_fine(status) != F_failure) break; @@ -1368,7 +1368,7 @@ extern "C" { const f_string_statics_t simulated_arguments = f_string_statics_t_initialize; fl_execute_parameter_t simulated_parameter = macro_fl_execute_parameter_t_initialize(execute_set->parameter.option, execute_set->parameter.wait, process->rule.has & controller_rule_has_environment_d ? execute_set->parameter.environment : 0, execute_set->parameter.signals, &f_string_empty_s); - status = fll_execute_program(controller_default_program_script_s, simulated_arguments, &simulated_parameter, &execute_set->as, (void *) &result); + status = fll_execute_program(*main->default_program_script, simulated_arguments, &simulated_parameter, &execute_set->as, (void *) &result); } } else { @@ -1625,7 +1625,7 @@ extern "C" { const f_string_statics_t simulated_arguments = f_string_statics_t_initialize; fl_execute_parameter_t simulated_parameter = macro_fl_execute_parameter_t_initialize(execute_set->parameter.option, execute_set->parameter.wait, process->rule.has & controller_rule_has_environment_d ? execute_set->parameter.environment : 0, execute_set->parameter.signals, &f_string_empty_s); - status = fll_execute_program(controller_default_program_script_s, simulated_arguments, &simulated_parameter, &execute_set->as, (void *) &result); + status = fll_execute_program(*main->default_program_script, simulated_arguments, &simulated_parameter, &execute_set->as, (void *) &result); } } else { diff --git a/level_3/controller/data/build/settings b/level_3/controller/data/build/settings index 0a34c39..4c1e22a 100644 --- a/level_3/controller/data/build/settings +++ b/level_3/controller/data/build/settings @@ -35,7 +35,7 @@ build_sources_library task/private-task.c task/private-task_print.c build_sources_library lock/private-lock.c lock/private-lock_print.c build_sources_library thread/private-thread.c thread/private-thread_control.c thread/private-thread_entry.c thread/private-thread_process.c thread/private-thread_rule.c thread/private-thread_signal.c -build_sources_program main.c +build_sources_program main.c main-common.c build_sources_headers controller.h common.h