There are way too many changes needed.
Start doing some initial structure updates and directly relating code.
Move a lot of the structures to common.h, temporarily.
This will eventually be moved out.
const f_string_static_t controller_long_validate_s = macro_f_string_static_t_initialize_1(CONTROLLER_long_validate_s, 0, CONTROLLER_long_validate_s_length);
#endif // _di_controller_parameter_d_
+#ifndef _di_controller_main_delete_
+ f_status_t controller_main_delete(controller_main_t * const main) {
+
+ if (!main) return F_status_set_error(F_parameter);
+
+ fll_program_data_delete(&main->program);
+ controller_setting_delete(&main->setting);
+
+ if (main->process) {
+ controller_process_delete(main->process);
+ }
+
+ return F_okay;
+ }
+#endif // _di_controller_main_delete_
+
+#ifndef _di_controller_control_delete_
+ f_status_t controller_control_delete(controller_control_t * const control) {
+
+ if (!main) return F_status_set_error(F_parameter);
+
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_1.string, &control->cache_1.used, &control->cache_1.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_2.string, &control->cache_2.used, &control->cache_2.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_3.string, &control->cache_3.used, &control->cache_3.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->input.string, &control->input.used, &control->input.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->output.string, &control->output.used, &control->output.size);
+
+ return F_okay;
+ }
+#endif // _di_controller_control_delete_
+
#ifndef _di_controller_control_payload_type_identify_
uint8_t controller_control_payload_type_identify(const f_string_static_t payload) {
}
#endif // _di_controller_entry_action_type_name_
-#ifndef _di_controller_main_delete_
- f_status_t controller_main_delete(controller_main_t * const main) {
+#ifndef _di_controller_process_delete_
+ f_status_t controller_process_delete(controller_process_t * const process) {
+
+ if (!process) return F_status_set_error(F_parameter);
+
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->name_entry.string, &process->name_entry.used, &process->name_entry.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_cgroup.string, &process->path_cgroup.used, &process->path_cgroup.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_control.string, &process->path_control.used, &process->path_control.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_current.string, &process->path_current.used, &process->path_current.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_pid.string, &process->path_pid.used, &process->path_pid.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &process->path_setting.string, &process->path_setting.used, &process->path_setting.size);
- f_console_parameters_delete(&main->program.parameters);
+ controller_control_delete(&process->control);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.reset.string, &main->program.reset.used, &main->program.reset.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.error.string, &main->program.error.used, &main->program.error.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.important.string, &main->program.important.used, &main->program.important.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.normal.string, &main->program.normal.used, &main->program.normal.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.normal_reset.string, &main->program.normal_reset.used, &main->program.normal_reset.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.notable.string, &main->program.notable.used, &main->program.notable.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.standout.string, &main->program.standout.used, &main->program.standout.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.success.string, &main->program.success.used, &main->program.success.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.title.string, &main->program.title.used, &main->program.title.size);
- f_memory_array_resize(, sizeof(f_char_t), (void **) &main->program.warning.string, &main->program.warning.used, &main->program.warning.size0);
+ status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->entry.define.array, &process->entry.define.used, &process->entry.define.size, &f_string_maps_delete_callback);
+ status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->entry.parameter.array, &process->entry.parameter.used, &process->entry.parameter.size, &f_string_maps_delete_callback);
+ status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->exit.define.array, &process->exit.define.used, &process->exit.define.size, &f_string_maps_delete_callback);
+ status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &process->exit.parameter.array, &process->exit.parameter.used, &process->exit.parameter.size, &f_string_maps_delete_callback);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.path_pid.string, &main->program.path_pid.used, &main->program.path_pid.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &main->program.path_setting.string, &main->program.path_setting.used, &main->program.path_setting.size);
+ controller_entry_items_delete(&process->entry.items);
+ controller_entry_items_delete(&process->exit.items);
+
+ controller_rules_delete_simple(&process->rules);
return F_okay;
}
-#endif // _di_controller_main_delete_
+#endif // _di_controller_process_delete_
#ifndef _di_controller_rule_action_type_identify_
uint8_t controller_rule_action_type_identify(const f_string_static_t action) {
if (!setting) return F_status_set_error(F_parameter);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->path_pid.string, &setting->path_pid.used, &setting->path_pid.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->path_setting.string, &setting->path_setting.used, &setting->path_setting.size);
+
return F_okay;
}
#endif // _di_controller_setting_delete_
#ifndef _di_controller_setting_load_
- void controller_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, controller_setting_t * const setting) {
+ f_status_t controller_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main) {
- if (!main) return;
+ if (!main) return F_status_set_error(F_parameter);
main->setting.state.step_small = controller_allocation_console_d;
if (main->program.parameters.array[controller_parameter_strip_invalid_e].result & f_console_result_found_e) {
main->setting.flag |= controller_main_flag_strip_invalid_e;
}
+
+ return F_okay;
}
#endif // _di_controller_setting_load_
-#ifndef _di_controller_setting_unload_
- f_status_t controller_setting_unload(controller_main_t * const main) {
+#ifndef _di_controller_entry_action_delete_
+ f_status_t controller_entry_action_delete(controller_entry_action_t * const action) {
- if (!main) return F_status_set_error(F_parameter);
+ if (!action) return F_status_set_error(F_parameter);
- controller_setting_delete(&main->setting);
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &action->parameters.array, &action->parameters.used, &action->parameters.size, &f_string_dynamics_delete_callback);
+
+ return F_okay;
+ }
+#endif // _di_controller_entry_action_delete_
+
+#ifndef _di_controller_entry_actions_delete_
+ f_status_t controller_entry_actions_delete(controller_entry_actions_t * const actions) {
+
+ if (!actions) return F_status_set_error(F_parameter);
+
+ // @todo Determine if this should be replaced with a resize callback strategy.
+ actions->used = actions->size;
+
+ while (actions->used) {
+ controller_entry_action_delete(&actions->array[--actions->used]);
+ } // while
+
+ f_memory_array_resize(0, sizeof(controller_entry_action_t), (void **) &actions->array, &actions->used, &actions->size);
+
+ return F_okay;
+ }
+#endif // _di_controller_entry_actions_delete_
+
+#ifndef _di_controller_entry_actions_increase_by_
+ f_status_t controller_entry_actions_increase_by(const f_number_unsigned_t amount, controller_entry_actions_t * const actions) {
+
+ if (!actions) return F_status_set_error(F_parameter);
+
+ if (amount) {
+ if (actions->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
+
+ const f_number_unsigned_t length = actions->used + amount;
+
+ if (length > actions->size) {
+ const f_status_t status = f_memory_resize(actions->size, length, sizeof(controller_entry_action_t), (void **) & actions->array);
+
+ if (F_status_is_error_not(status)) {
+ actions->size = actions->used + amount;
+ }
+
+ return status;
+ }
+ }
+
+ return F_data_not;
+ }
+#endif // _di_controller_entry_actions_increase_by_
+
+#ifndef _di_controller_entry_item_delete_
+ f_status_t controller_entry_item_delete(controller_entry_item_t * const item) {
+
+ if (!item) return F_status_set_error(F_parameter);
+
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &item->name.string, &item->name.used, &item->name.size);
+
+ controller_entry_actions_delete(&item->actions);
+
+ return F_okay;
+ }
+#endif // _di_controller_entry_item_delete_
+
+#ifndef _di_controller_entry_items_delete_
+ f_status_t controller_entry_items_delete(controller_entry_items_t * const items) {
+
+ if (!items) return F_status_set_error(F_parameter);
+
+ // @todo Determine if this should be replaced with a resize callback strategy.
+ items->used = items->size;
+
+ while (items->used) {
+ controller_entry_item_delete(&items->array[--items->used]);
+ } // while
+
+ f_memory_array_resize(0, sizeof(controller_entry_item_t), (void **) &items->array, &items->used, &items->size);
+
+ return F_okay;
+ }
+#endif // _di_controller_entry_items_delete_
+
+#ifndef _di_controller_entry_items_increase_by_
+ f_status_t controller_entry_items_increase_by(const f_number_unsigned_t amount, controller_entry_items_t * const items) {
+
+ if (!items) return F_status_set_error(F_parameter);
+
+ if (amount) {
+ if (items->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
+
+ const f_number_unsigned_t length = items->used + amount;
+
+ if (length > items->size) {
+ const f_status_t status = f_memory_resize(items->size, length, sizeof(controller_entry_item_t), (void **) & items->array);
+
+ if (F_status_is_error_not(status)) {
+ items->size = items->used + amount;
+ }
+
+ return status;
+ }
+ }
+
+ return F_data_not;
+ }
+#endif // _di_controller_entry_items_increase_by_
+
+#ifndef _di_controller_rule_action_t_
+ const f_string_static_t controller_rule_action_method_string_extended_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_string_extended_s, 0, CONTROLLER_rule_action_method_string_extended_s_length);
+ const f_string_static_t controller_rule_action_method_string_extended_list_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_string_extended_list_s, 0, CONTROLLER_rule_action_method_string_extended_list_s_length);
+#endif // _di_controller_rule_action_t_
+
+#ifndef _di_controller_rule_action_delete_simple_
+ f_status_t controller_rule_action_delete_simple(controller_rule_action_t * const action) {
+
+ if (!action) return F_status_set_error(F_parameter);
+
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &action->parameters.array, &action->parameters.used, &action->parameters.size, &f_string_dynamics_delete_callback);
+
+ f_memory_array_resize(0, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size);
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_action_delete_simple_
+
+#ifndef _di_controller_rule_actions_delete_simple_
+ f_status_t controller_rule_actions_delete_simple(controller_rule_actions_t * const actions) {
+
+ if (!actions) return F_status_set_error(F_parameter);
+
+ actions->used = actions->size;
+
+ while (actions->used) {
+ controller_rule_action_delete_simple(&actions->array[--actions->used]);
+ } // while
+
+ f_memory_delete(actions->size, sizeof(controller_rule_action_t), (void **) & actions->array);
+ actions->size = 0;
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_actions_delete_simple_
+
+#ifndef _di_controller_rule_actions_increase_by_
+ f_status_t controller_rule_actions_increase_by(const f_number_unsigned_t amount, controller_rule_actions_t * const actions) {
+
+ if (!actions) return F_status_set_error(F_parameter);
+
+ if (amount) {
+ if (actions->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
+
+ const f_number_unsigned_t length = actions->used + amount;
+
+ if (length > actions->size) {
+ const f_status_t status = f_memory_resize(actions->size, length, sizeof(controller_rule_action_t), (void **) & actions->array);
+
+ if (F_status_is_error_not(status)) {
+ actions->size = actions->used + amount;
+ }
+
+ return status;
+ }
+ }
+
+ return F_data_not;
+ }
+#endif // _di_controller_rule_actions_increase_by_
+
+#ifndef _di_controller_rule_delete_
+ f_status_t controller_rule_delete(controller_rule_t * const rule) {
+
+ if (!rule) return F_status_set_error(F_parameter);
+
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->engine.string, &rule->engine.used, &rule->engine.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->name.string, &rule->name.used, &rule->name.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->path.string, &rule->path.used, &rule->path.size);
+
+ f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &rule->define.array, &rule->define.used, &rule->define.size, &f_string_maps_delete_callback);
+ f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &rule->parameter.array, &rule->parameter.used, &rule->parameter.size, &f_string_maps_delete_callback);
+
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->engine_arguments.array, &rule->engine_arguments.used, &rule->engine_arguments.size, &f_string_dynamics_delete_callback);
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->environment.array, &rule->environment.used, &rule->environment.size, &f_string_dynamics_delete_callback);
+
+ f_memory_array_resize(0, sizeof(int32_t), (void **) &rule->affinity.array, &rule->affinity.used, &rule->affinity.size);
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->cgroup.path.string, &rule->cgroup.path.used, &rule->cgroup.path.size);
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->cgroup.groups.array, &rule->cgroup.groups.used, &rule->cgroup.groups.size, &f_string_dynamics_delete_callback);
+ f_memory_array_resize(0, sizeof(int32_t), (void **) &rule->groups.array, &rule->groups.used, &rule->groups.size);
+ f_memory_array_resize(0, sizeof(f_limit_set_t), (void **) &rule->limits.array, &rule->limits.used, &rule->limits.size);
+
+ if (rule->capability) {
+ f_capability_delete(&rule->capability);
+ }
+
+ controller_rule_ons_delete(&rule->ons);
+ controller_rule_items_delete(&rule->items);
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_delete_
+
+#ifndef _di_controller_rule_item_delete_
+ f_status_t controller_rule_item_delete(controller_rule_item_t * const item) {
+
+ if (!item) return F_status_set_error(F_parameter);
+
+ f_memory_array_resize(0, sizeof(f_char_t), (void **) &item->pid_file.string, &item->pid_file.used, &item->pid_file.size);
+
+ controller_rule_actions_delete(&item->actions);
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_item_delete_
+
+#ifndef _di_controller_rule_items_delete_
+ f_status_t controller_rule_items_delete(controller_rule_items_t * const items) {
+
+ if (!items) return F_status_set_error(F_parameter);
+
+ items->used = items->size;
+
+ while (items->used) {
+ controller_rule_item_delete(&items->array[--items->used]);
+ } // while
+
+ f_memory_delete(items->size, sizeof(controller_rule_item_t), (void **) & items->array);
+ items->size = 0;
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_items_delete_
+
+#ifndef _di_controller_rule_on_delete_
+ f_status_t controller_rule_on_delete(controller_rule_on_t * const on) {
+
+ if (!on) return F_status_set_error(F_parameter);
+
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->need.array, &on->need.used, &on->need.size, &f_string_dynamics_delete_callback);
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->want.array, &on->want.used, &on->want.size, &f_string_dynamics_delete_callback);
+ f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->wish.array, &on->wish.used, &on->wish.size, &f_string_dynamics_delete_callback);
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_on_delete_
+
+#ifndef _di_controller_rule_ons_delete_
+ f_status_t controller_rule_ons_delete(controller_rule_ons_t * const ons) {
+
+ if (!ons) return F_status_set_error(F_parameter);
+
+ ons->used = ons->size;
+
+ while (ons->used) {
+ controller_rule_on_delete(&ons->array[--ons->used]);
+ } // while
+
+ f_memory_delete(ons->size, sizeof(controller_rule_on_t), (void **) & ons->array);
+ ons->size = 0;
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_ons_delete_
+
+#ifndef _di_controller_rule_ons_increase_
+ f_status_t controller_rule_ons_increase(controller_rule_ons_t * const ons) {
+
+ if (!ons) return F_status_set_error(F_parameter);
+
+ if (ons->used + 1 > ons->size) {
+ f_number_unsigned_t length = ons->used + controller_common_allocation_small_d;
+
+ if (length > F_number_t_size_unsigned_d) {
+ if (ons->used + 1 > F_number_t_size_unsigned_d) {
+ return F_status_set_error(F_array_too_large);
+ }
+
+ length = F_number_t_size_unsigned_d;
+ }
+
+ return controller_rule_ons_resize(length, ons);
+ }
+
+ return F_data_not;
+ }
+#endif // _di_controller_rule_ons_increase_
+
+#ifndef _di_controller_rule_ons_resize_
+ f_status_t controller_rule_ons_resize(const f_number_unsigned_t length, controller_rule_ons_t * const ons) {
+
+ if (!ons) return F_status_set_error(F_parameter);
+
+ for (f_number_unsigned_t i = length; i < ons->size; ++i) {
+ controller_rule_on_delete(&ons->array[i]);
+ } // for
+
+ const f_status_t status = f_memory_resize(ons->size, length, sizeof(controller_rule_on_t), (void **) & ons->array);
+ if (F_status_is_error(status)) return status;
+
+ ons->size = length;
+
+ if (ons->used > ons->size) {
+ ons->used = length;
+ }
+
+ return F_okay;
+ }
+#endif // _di_controller_rule_ons_resize_
+
+#ifndef _di_controller_rules_delete_
+ f_status_t controller_rules_delete(controller_rules_t * const rules) {
+
+ if (!rules) return F_status_set_error(F_parameter);
+
+ controller_rules_resize(0, rules);
+
+ return F_okay;
+ }
+#endif // _di_controller_rules_delete_
+
+#ifndef _di_controller_rules_increase_
+ f_status_t controller_rules_increase(controller_rules_t * const rules) {
+
+ if (!rules) return F_status_set_error(F_parameter);
+
+ if (rules->used + 1 > rules->size) {
+ f_number_unsigned_t length = rules->used + controller_common_allocation_small_d;
+
+ if (length > F_number_t_size_unsigned_d) {
+ if (rules->used + 1 > F_number_t_size_unsigned_d) {
+ return F_status_set_error(F_array_too_large);
+ }
+
+ length = F_number_t_size_unsigned_d;
+ }
+
+ return controller_rules_resize(length, rules);
+ }
+
+ return F_data_not;
+ }
+#endif // _di_controller_rules_increase_
+
+#ifndef _di_controller_rules_resize_
+ f_status_t controller_rules_resize(const f_number_unsigned_t length, controller_rules_t * const rules) {
+
+ if (!rules) return F_status_set_error(F_parameter);
+
+ for (f_number_unsigned_t i = length; i < rules->size; ++i) {
+ controller_rule_delete(&rules->array[i]);
+ } // for
+
+ const f_status_t status = f_memory_resize(rules->size, length, sizeof(controller_rule_t), (void **) & rules->array);
+ if (F_status_is_error(status)) return status;
+
+ rules->size = length;
+
+ if (rules->used > rules->size) {
+ rules->used = length;
+ }
return F_okay;
}
-#endif // _di_controller_setting_unload_
+#endif // _di_controller_rules_resize_
#ifdef __cplusplus
} // extern "C"
#endif // _di_controller_parameter_d_
/**
- * The main program data.
- *
- * child: Reserved for a child process, often representing the child return status or the child process ID.
- * context: The color context.
- * default_engine: The default scripting engine.
- * default_path_pid: The default PID file path.
- * default_path_pid_init: The default PID file path, when run as init.
- * default_path_pid_prefix: The default PID file path prefix.
- * default_path_pid_suffix: The default PID file path suffix.
- * default_path_setting: The default setting path.
- * default_path_setting_init: The default setting path, when run as init.
- * default_path_socket: The default socket file path.
- * default_path_socket_init: The default socket file path, when run as init.
- * default_path_socket_prefix: The default socket file path prefix.
- * default_path_socket_suffix: The default socket file path suffix.
- * error: The output file for error printing.
- * as_init: Designate whether or not this is running as an init program.
- * output: The output file for general printing.
- * parameters: The state of pre-defined parameters passed to the program.
- * pid: The PID of the program.
- * program_name: The name of the program.
- * program_name_long: The long name of the program.
- * signal: The process signal management structure.
- * umask: The umask settings, needed for avoiding calls to umask() to read the current umask.
- * warning: The output file for warning printing.
- */
-#ifndef _di_controller_main_t_
- typedef struct {
- f_console_parameters_t parameters;
-
- bool as_init;
-
- fl_print_t output;
- fl_print_t error;
- fl_print_t warning;
-
- f_signal_t signal;
-
- pid_t pid;
- mode_t umask;
- int child;
-
- const f_string_static_t *default_engine;
- 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 *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; // @todo refactor this name, and create a controller_main_t that holds the program data, settings, and possibly this.
-
- #define controller_main_t_initialize \
- { \
- f_console_parameters_t_initialize, \
- F_false, \
- fl_print_t_initialize, \
- macro_fl_print_t_initialize_error(), \
- macro_fl_print_t_initialize_warning(), \
- f_signal_t_initialize, \
- 0, \
- 0, \
- 0, \
- 0, \
- 0, \
- 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_
-
-/**
* Codes representing control payload types.
*
* controller_control_payload_type_*:
* - file_to: Using a specified destination file.
* - header: Enable printing of headers.
* - help: Print help.
+ * - init: Operate as an "init" program.
* - print_first: When set, print new line to message output on program begin after loading settings.
* - print_last: When set, print new line to message output on program end.
* - separate: Enable printing of separators.
controller_main_flag_file_to_e = 0x4,
controller_main_flag_header_e = 0x8,
controller_main_flag_help_e = 0x10,
- controller_main_flag_print_first_e = 0x20,
- controller_main_flag_print_last_e = 0x40,
- controller_main_flag_separate_e = 0x80,
- controller_main_flag_strip_invalid_e = 0x100,
- controller_main_flag_verify_e = 0x200,
- controller_main_flag_version_e = 0x400,
+ controller_main_flag_init_e = 0x20,
+ controller_main_flag_print_first_e = 0x40,
+ controller_main_flag_print_last_e = 0x80,
+ controller_main_flag_separate_e = 0x100,
+ controller_main_flag_strip_invalid_e = 0x200,
+ controller_main_flag_verify_e = 0x400,
+ controller_main_flag_version_e = 0x800,
}; // enum
#endif // _di_controller_main_flag_e_
* This is passed to the program-specific main entry point to designate program settings.
* These program settings are often processed from the program arguments (often called the command line arguments).
*
- * flag: Flags passed to the main function.
+ * flag: Flags passed to the main function.
+ * as_init: Designate whether or not this is running as an init program.
*
* state: The state information.
+ *
+ * default_engine: The default scripting engine.
+ * default_path_pid: The default PID file path.
+ * default_path_pid_init: The default PID file path, when run as init.
+ * default_path_pid_prefix: The default PID file path prefix.
+ * default_path_pid_suffix: The default PID file path suffix.
+ * default_path_setting: The default setting path.
+ * default_path_setting_init: The default setting path, when run as init.
+ * default_path_socket: The default socket file path.
+ * default_path_socket_init: The default socket file path, when run as init.
+ * default_path_socket_prefix: The default socket file path prefix.
+ * default_path_socket_suffix: The default socket file path suffix.
+ *
+ * program_name: The short program name.
+ * program_name_long: The long program name.
+ *
+ * path_pid: The name of the program.
+ * path_setting: The long name of the program.
*/
#ifndef _di_controller_setting_t_
typedef struct {
uint16_t flag;
f_state_t state;
+
+ const f_string_static_t *default_engine;
+ 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;
+
+ f_string_static_t program_name;
+ f_string_static_t program_name_long;
+
+ f_string_dynamic_t path_pid;
+ f_string_dynamic_t path_setting;
} controller_setting_t;
#define controller_setting_t_initialize \
{ \
controller_main_flag_none_e, \
f_state_t_initialize, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ f_string_static_t_initialize, \
+ f_string_static_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
}
#endif // _di_controller_setting_t_
/**
+ * Provide default control settings.
+ *
+ * controller_control_default:
+ * - socket_backlog: The amount of waiting client connections to support while handling a socket connection.
+ * - socket_buffer: The preferred max size of the buffer such that if the buffer exceeds this then it is reallocated to this size at the end of processing.
+ * - socket_buffer_max: The max size allowed in the buffer (this value must not be set smaller than the packet headers).
+ * - socket_cache: The preferred max size of the control cache such that if the cache exceeds this then it is reallocated to this size at the end of processing.
+ * - socket_header: The minimum size in bytes of the packet header to read to be able to process the size information.
+ * - socket_linger: The number of seconds to linger the connection before closing.
+ * - socket_timeout: The number of microseconds to wait.
+ * - socket_payload_max: The max size allowed for the "payload" part of a packet and must be smaller than socket_buffer_max (this is smaller than socket_buffer_max to allow for enough room to afford a header).
+ */
+#ifndef _di_controller_control_defaults_
+ #define controller_control_default_socket_backlog_d 64
+ #define controller_control_default_socket_buffer_d 2048
+ #define controller_control_default_socket_buffer_max_d 4294967296
+ #define controller_control_default_socket_cache_d 128
+ #define controller_control_default_socket_header_d 5
+ #define controller_control_default_socket_linger_d 2
+ #define controller_control_default_socket_timeout_d 10000 // 0.01 seconds.
+ #define controller_control_default_socket_payload_max_d 4294965248
+#endif // _di_controller_defaults_
+
+/**
+ * The control data.
+ *
+ * controller_control_flag_*:
+ * - readonly: Control is set to read-only mode.
+ * - has_user: A user is manually specified.
+ * - has_group: A group is manually specified.
+ * - has_mode: A file mode is manually specified.
+ *
+ * flag: Flags from controller_control_flag_*.
+ * user: The user ID, if specified.
+ * group: The group ID, if specified.
+ * mode: The file mode, if specified.
+ * server: The server socket connection.
+ * client: The client socket connection.
+ * cache_1: A generic buffer used for caching control related data.
+ * cache_2: A generic buffer used for caching control related data.
+ * cache_3: A generic buffer used for caching control related data.
+ * input: A buffer used for receiving data from the client.
+ * output: A buffer used for transmitting data to the client.
+ * address: The socket address structure.
+ */
+#ifndef _di_controller_control_t_
+ enum {
+ controller_control_flag_readonly_e = 0x1,
+ controller_control_flag_has_user_e = 0x2,
+ controller_control_flag_has_group_e = 0x4,
+ controller_control_flag_has_mode_e = 0x8,
+ };
+
+ typedef struct {
+ uint8_t flag;
+
+ uid_t user;
+ gid_t group;
+ mode_t mode;
+
+ f_socket_t server;
+ f_socket_t client;
+
+ f_string_dynamic_t cache_1;
+ f_string_dynamic_t cache_2;
+ f_string_dynamic_t cache_3;
+
+ f_string_dynamic_t input;
+ f_string_dynamic_t output;
+
+ struct sockaddr_un address;
+ } controller_control_t;
+
+ #define controller_control_t_initialize { \
+ 0, \
+ -1, \
+ -1, \
+ 0, \
+ f_socket_t_initialize, \
+ f_socket_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ { }, \
+ }
+#endif // _di_controller_control_t_
+
+/**
+ * A codes repesent different flags associated with a packet.
+ *
+ * controller_control_packet_flag_*:
+ * - binary: Designate that the packet is in binary mode (when not set then packet is in string mode).
+ * - endian_big: Designate that the packet is in big endian order (when not set then packet is in little endian order).
+ */
+#ifndef _di_controller_control_packet_flag_
+ #define controller_control_packet_flag_binary_d 0x10000000
+ #define controller_control_packet_flag_endian_big_d 0x01000000
+#endif // _di_controller_control_packet_flag_
+
+/**
+ * An Entry Item Action.
+ *
+ * controller_entry_action_flag_*:
+ * - undefined: The given type and code are designated as undefined.
+ *
+ * controller_entry_action_type_*:
+ * - consider: Designate a rule to be pre-loaded.
+ * - execute: Execute into another program.
+ * - failsafe: Designate a failsafe "item".
+ * - freeze: A Rule Action for freezing.
+ * - item: A named set of Rules.
+ * - kill: A Rule Action for killing.
+ * - pause: A Rule Action for pausing.
+ * - ready: Designate readiness for special processing for Entry or Exit.
+ * - reload: A Rule Action for reloading.
+ * - restart: A Rule Action for restarting.
+ * - resume: A Rule Action for resuming.
+ * - start: A Rule Action for starting.
+ * - stop: A Rule Action for stopping.
+ * - timeout: Inline timeout settings.
+ * - thaw: A Rule Action for unfreezing.
+ *
+ * controller_entry_rule_code_*:
+ * - asynchronous: Process Rule asynchronously.
+ * - require: Require Rule operations to succeed or the Entry/Exit will fail.
+ * - wait: Wait for all existing asynchronous processes to finish before operating Rule.
+ *
+ * controller_entry_timeout_code_*:
+ * - exit: The timeout Action represents an exit timeout.
+ * - kill: The timeout Action represents a kill timeout.
+ * - start: The timeout Action represents a start timeout.
+ * - stop: The timeout Action represents a stop timeout.
+ *
+ * type: The type of Action.
+ * code: A single code or sub-type associated with the Action.
+ * flag: A set of flags to describe special behavior for the given type and code (flags may be different per type and code).
+ * line: The line number where the Entry Item begins.
+ * number: The unsigned number that some types use instead of the "parameters".
+ * status: The overall status.
+ * parameters: The values associated with the Action.
+ */
+#ifndef _di_controller_entry_action_t_
+ #define controller_entry_rule_code_asynchronous_d 0x1
+ #define controller_entry_rule_code_require_d 0x2
+ #define controller_entry_rule_code_wait_d 0x4
+
+ #define controller_entry_timeout_code_exit_d 0x1
+ #define controller_entry_timeout_code_kill_d 0x2
+ #define controller_entry_timeout_code_start_d 0x4
+ #define controller_entry_timeout_code_stop_d 0x8
+
+ enum {
+ controller_entry_action_flag_none_e = 0x0,
+ controller_entry_action_flag_undefined_e = 0x1,
+ };
+
+ typedef struct {
+ uint8_t type;
+ uint8_t code;
+ uint8_t flag;
+
+ f_number_unsigned_t line;
+ f_number_unsigned_t number;
+
+ f_status_t status;
+
+ f_string_dynamics_t parameters;
+ } controller_entry_action_t;
+
+ #define controller_entry_action_t_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ controller_entry_action_flag_none_e, \
+ 0, \
+ F_known_not, \
+ f_string_dynamics_t_initialize, \
+ }
+#endif // _di_controller_entry_action_t_
+
+/**
+ * The Entry Item Actions.
+ *
+ * array: An array of Entry Item Actions.
+ * size: Total amount of allocated space.
+ * used: Total number of allocated spaces used.
+ */
+#ifndef _di_controller_entry_actions_t_
+ typedef struct {
+ controller_entry_action_t *array;
+
+ f_number_unsigned_t size;
+ f_number_unsigned_t used;
+ } controller_entry_actions_t;
+
+ #define controller_entry_actions_t_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ }
+#endif // _di_controller_entry_actions_t_
+
+/**
+ * An Entry Item.
+ *
+ * line: The line number where the Entry Item begins.
+ * name: The name of the Entry Item.
+ * actions: The Actions associated with the Entry Item.
+ */
+#ifndef _di_controller_entry_item_t_
+ typedef struct {
+ f_number_unsigned_t line;
+ f_string_dynamic_t name;
+
+ controller_entry_actions_t actions;
+ } controller_entry_item_t;
+
+ #define controller_entry_item_t_initialize \
+ { \
+ 0, \
+ f_string_dynamic_t_initialize, \
+ controller_entry_actions_t_initialize, \
+ }
+#endif // _di_controller_entry_item_t_
+
+/**
+ * An Entry Items.
+ *
+ * array: An array of Entry Items.
+ * size: Total amount of allocated space.
+ * used: Total number of allocated spaces used.
+ */
+#ifndef _di_controller_entry_items_t_
+ typedef struct {
+ controller_entry_item_t *array;
+
+ f_number_unsigned_t size;
+ f_number_unsigned_t used;
+ } controller_entry_items_t;
+
+ #define controller_entry_items_t_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ }
+
+ #define macro_controller_entry_items_t_clear(items) \
+ items.array = 0; \
+ items.size = 0; \
+ items.used = 0;
+#endif // _di_controller_entry_items_t_
+
+/**
+ * The Entry or Exit.
+ *
+ * Entry and Exit files are essentially the same structure with minor differences in settings and behavior.
+ * The structure is identical and due to lacking any particularly good name to represent both "entry" or "exit", the name "entry" is being used for both.
+ *
+ * controller_entry_flag_*:
+ * - none_e: No flags are set.
+ * - timeout_exit_no_e: The exit timeout is disabled.
+ * - timeout_kill_no_e: The kill timeout is disabled for Rules by default.
+ * - timeout_start_no_e: The start timeout is disabled for Rules by default.
+ * - timeout_stop_no_e: The stop timeout is disabled for Rules by default.
+ *
+ * controller_entry_session_*:
+ * - none: No special session configuration specified, use built in defaults.
+ * - new: Designate the default to use a new session, ignoring built in defaults (passing FL_execute_parameter_option_session_d to the execute functions).
+ * - same: Designate the default to use a same session, ignoring built in defaults.
+ *
+ * controller_entry_pid_*:
+ * - disable: Do not check for or create a PID file to represent the entry execution.
+ * - require: Check to see if the PID file exists for an entry at startup and then when "ready" create a pid file, display error on pid file already exists or on failure and then fail.
+ * - ready: When "ready" create a pid file, display error on failure and then fail (does not check if PID file exists).
+ *
+ * controller_entry_show_*:
+ * - normal: Do not print anything other than warnings and errors, but allow executed programs and scripts to output however they like.
+ * - init: Print like an init program, printing status of entry and rules as they are being started, stopped, etc...
+ *
+ * define: Any defines (environment variables) made available to all Rules in this entry for IKI substitution or just as environment variables.
+ * flag: A set of flags, primarily used to designate that timeouts are disabled.
+ * items: The array of entry items.
+ * parameter: Any parameters made available to all Rules in this entry for IKI substitution.
+ * pid: The PID file generation setting.
+ * session: The default session settings (when NULL, no default is specified).
+ * show: The show setting for controlling what to show when executing entry items and rules.
+ * status: The overall status.
+ * timeout_exit: The timeout to wait when exiting the Controller program after sending the terminate signal to send the kill signal.
+ * timeout_kill: The timeout to wait relating to using a kill signal.
+ * timeout_start: The timeout to wait relating to starting a process.
+ * timeout_stop: The timeout to wait relating to stopping a process.
+ */
+#ifndef _di_controller_entry_t_
+ enum {
+ controller_entry_pid_disable_e = 0,
+ controller_entry_pid_require_e,
+ controller_entry_pid_ready_e,
+ };
+
+ enum {
+ controller_entry_show_normal_e = 0,
+ controller_entry_show_init_e,
+ };
+
+ enum {
+ controller_entry_session_none_e = 0,
+ controller_entry_session_new_e,
+ controller_entry_session_same_e,
+ };
+
+ enum {
+ controller_entry_flag_none_e = 0x0,
+ controller_entry_flag_timeout_exit_no_e = 0x1,
+ controller_entry_flag_timeout_kill_no_e = 0x2,
+ controller_entry_flag_timeout_start_no_e = 0x4,
+ controller_entry_flag_timeout_stop_no_e = 0x8,
+ };
+
+ typedef struct {
+ f_status_t status;
+
+ uint8_t pid;
+ uint8_t session;
+ uint8_t show;
+ uint8_t flag;
+
+ f_number_unsigned_t timeout_exit;
+ f_number_unsigned_t timeout_kill;
+ f_number_unsigned_t timeout_start;
+ f_number_unsigned_t timeout_stop;
+
+ f_string_maps_t define;
+ f_string_maps_t parameter;
+
+ controller_entry_items_t items;
+ } controller_entry_t;
+
+ #define controller_entry_t_initialize { \
+ F_known_not, \
+ controller_entry_pid_require_e, \
+ controller_entry_session_none_e, \
+ controller_entry_show_normal_e, \
+ 0, \
+ controller_thread_exit_timeout_d, \
+ 0, \
+ 0, \
+ 0, \
+ f_string_maps_t_initialize, \
+ f_string_maps_t_initialize, \
+ controller_entry_items_t_initialize, \
+ }
+#endif // _di_controller_entry_t_
+
+/**
+ * The Rule "rerun" item for controlling re-execution.
+ *
+ * count: A count of the number of executions.
+ * delay: The time to wait before attempting to re-run.
+ * max: The maximum number of times to re-run (with 0 representing re-run infinitely) for executions.
+ */
+#ifndef _di_controller_rule_rerun_item_t_
+ typedef struct {
+ bool reset;
+
+ f_number_unsigned_t count;
+ f_number_unsigned_t delay;
+ f_number_unsigned_t max;
+ } controller_rule_rerun_item_t;
+
+ #define controller_rule_rerun_item_initialize { \
+ F_false, \
+ 0, \
+ 5000, \
+ 0, \
+
+ #define macro_controller_rule_rerun_item_initialize(item) { \
+ item.reset = F_false; \
+ item.count = 0; \
+ item.delay = 5000; \
+ item.max = 0; \
+ }
+#endif // _di_controller_rule_rerun_item_t_
+
+/**
+ * The Rule "rerun" values for controlling re-execution.
+ *
+ * controller_rule_rerun_is_*:
+ * - failure: The success re-run is enabled.
+ * - failure_reset: Reset success counter when failure is returned.
+ * - success: The success re-run is enabled.
+ * - success_reset: Reset failure counter when success is returned.
+ *
+ * is: A bitwise set of options to designate whether rerun is enabled or not and other options.
+ * count_failure: A count of the number of failed executions.
+ * count_success: A count of the number of successful executions.
+ * delay_failure: The time to wait before attempting to "rerun" for failed executions.
+ * delay_success: The time to wait before attempting to "rerun" for successful executions.
+ * max_failure: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for failed executions.
+ * max_success: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for successful executions.
+ */
+#ifndef _di_controller_rule_rerun_t_
+ #define controller_rule_rerun_is_failure_d 0x1
+ #define controller_rule_rerun_is_failure_reset_d 0x2
+ #define controller_rule_rerun_is_success_d 0x4
+ #define controller_rule_rerun_is_success_reset_d 0x8
+
+ typedef struct {
+ uint8_t is;
+
+ controller_rule_rerun_item_t failure;
+ controller_rule_rerun_item_t success;
+ } controller_rule_rerun_t;
+
+ #define controller_rule_rerun_initialize { \
+ 0, \
+ controller_rule_rerun_item_initialize, \
+ controller_rule_rerun_item_initialize, \
+ }
+#endif // _di_controller_rule_rerun_t_
+
+/**
+ * A Rule Action.
+ *
+ * controller_rule_action_method_*:
+ * - extended: Designate that this Action is represented using FSS Extended.
+ * - extended_list: Designate that this Action is represented using FSS Extended List.
+ *
+ * type: The Rule Action type.
+ * line: The line number where the Rule Action begins.
+ * status: The last execution status of the Rule Action.
+ * parameters: All parameters associated with the Rule Action.
+ */
+#ifndef _di_controller_rule_action_t_
+ #define CONTROLLER_rule_action_method_string_extended_s "FSS-0001 (Extended)"
+ #define CONTROLLER_rule_action_method_string_extended_list_s "FSS-0003 (Extended List)"
+
+ #define CONTROLLER_rule_action_method_string_extended_s_length 19
+ #define CONTROLLER_rule_action_method_string_extended_list_s_length 24
+
+ extern const f_string_static_t controller_rule_action_method_string_extended_s;
+ extern const f_string_static_t controller_rule_action_method_string_extended_list_s;
+
+ enum {
+ controller_rule_action_method_extended_e = 1,
+ controller_rule_action_method_extended_list_e,
+ };
+
+ typedef struct {
+ uint8_t type;
+ f_number_unsigned_t line;
+ f_status_t status;
+
+ f_string_dynamics_t parameters;
+ f_iki_datas_t ikis;
+ } controller_rule_action_t;
+
+ #define controller_rule_action_t_initialize { \
+ 0, \
+ 0, \
+ F_known_not, \
+ f_string_dynamics_t_initialize, \
+ f_iki_datas_t_initialize, \
+ }
+#endif // _di_controller_rule_action_t_
+
+/**
+ * The Rule Actions.
+ *
+ * array: An array of Rule Actions.
+ * size: Total amount of allocated space.
+ * used: Total number of allocated spaces used.
+ */
+#ifndef _di_controller_rule_actions_t_
+ typedef struct {
+ controller_rule_action_t *array;
+
+ f_number_unsigned_t size;
+ f_number_unsigned_t used;
+ } controller_rule_actions_t;
+
+ #define controller_rule_actions_t_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ }
+#endif // _di_controller_rule_actions_t_
+
+/**
+ * A Rule Item.
+ *
+ * controller_rule_item_type_*:
+ * - command: A Command to execute.
+ * - script: A Script to execute.
+ * - service: A Service to execute.
+ * - setting: Settings associated with the Rule Item.
+ * - utility: A Utility to execute.
+ *
+ * type: The type of the Rule Item.
+ * with: A bitwise number representing execute "with" options.
+ * line: The line number where the Rule Item begins.
+ * reruns: An array designating rerun settings for each execution type available.
+ * actions: The actions associated with the Rule Item.
+ */
+#ifndef _di_controller_rule_item_t_
+ typedef struct {
+ uint8_t type;
+ uint8_t with;
+ f_number_unsigned_t line;
+
+ f_string_dynamic_t pid_file;
+ controller_rule_rerun_t reruns[controller_rule_action_execute_type__enum_size_e];
+ controller_rule_actions_t actions;
+ } controller_rule_item_t;
+
+ #define controller_rule_item_t_initialize \
+ { \
+ 0, \
+ 0, \
+ 0, \
+ f_string_dynamic_t_initialize, \
+ { \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ controller_rule_rerun_t_initialize, \
+ }, \
+ controller_rule_actions_t_initialize, \
+ }
+#endif // _di_controller_rule_item_t_
+
+/**
+ * The Rule Items.
+ *
+ * array: An array of Rule Items.
+ * size: Total amount of allocated space.
+ * used: Total number of allocated spaces used.
+ */
+#ifndef _di_controller_rule_items_t_
+ typedef struct {
+ controller_rule_item_t *array;
+
+ f_number_unsigned_t size;
+ f_number_unsigned_t used;
+ } controller_rule_items_t;
+
+ #define controller_rule_items_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ }
+#endif // _di_controller_rule_items_t_
+
+/**
+ * The Rule "on" values for designating dependencies.
+ *
+ * action: The Rule Action type this "on" dependencies are associated with.
+ * need: The Rule Alias for a required Rule.
+ * want: The Rule Alias for an optional Rule that is required to succeed if found.
+ * wish: The Rule Alias for an optional Rule that is not required.
+ */
+#ifndef _di_controller_rule_on_t_
+ typedef struct {
+ uint8_t action;
+
+ f_string_dynamics_t need;
+ f_string_dynamics_t want;
+ f_string_dynamics_t wish;
+ } controller_rule_on_t;
+
+ #define controller_rule_on_initialize { \
+ 0, \
+ f_string_dynamics_t_initialize, \
+ f_string_dynamics_t_initialize, \
+ f_string_dynamics_t_initialize, \
+ }
+#endif // _di_controller_rule_on_t_
+
+/**
+ * The Rule "on" array.
+ *
+ * array: An array of Rule "on" values.
+ * size: Total amount of allocated space.
+ * used: Total number of allocated spaces used.
+ */
+#ifndef _di_controller_rule_ons_t_
+ typedef struct {
+ controller_rule_on_t *array;
+
+ f_number_unsigned_t size;
+ f_number_unsigned_t used;
+ } controller_rule_ons_t;
+
+ #define controller_rule_ons_t_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ }
+#endif // _di_controller_rule_ons_t_
+
+/**
+ * A Rule.
+ *
+ * controller_rule_setting_type_*:
+ * - affinity: Setting type representing a affinity.
+ * - capability: Setting type representing a capability.
+ * - cgroup: Setting type representing a control group.
+ * - define: Setting type representing a define.
+ * - engine: Setting type representing a engine.
+ * - engine_arguments: Setting type representing a engine.
+ * - environment: Setting type representing a environment.
+ * - group: Setting type representing a group.
+ * - limit: Setting type representing a limit.
+ * - name: Setting type representing a name.
+ * - nice: Setting type representing a nice.
+ * - on: Setting type representing a on.
+ * - parameter: Setting type representing a parameter.
+ * - path: Setting type representing a path.
+ * - scheduler: Setting type representing a scheduler.
+ * - user: Setting type representing a user.
+ *
+ * controller_rule_has_*:
+ * - cgroup: Has type representing a control group.
+ * - group: Has type representing a group.
+ * - nice: Has type representing a nice.
+ * - scheduler: Has type representing a scheduler.
+ * - user: Has type representing a user.
+ *
+ * affinity: The cpu affinity to be used when executing the Rule.
+ * alias: The distinct ID (machine name) of the Rule, such as "service/ssh".
+ * capability: The capability setting if the Rule "has" a capability.
+ * cgroup: The control group setting if the Rule "has" a control group.
+ * define: Any defines (environment variables) made available to the Rule for IKI substitution or just as environment variables.
+ * engine: The program or path to the program of the scripting engine to use when processing scripts in this Rule.
+ * engine_arguments: Any arguments to pass to the engine program.
+ * environment: All environment variables allowed to be exposed to the Rule when processing.
+ * group: The group ID if the Rule "has" a group.
+ * groups: A set of group IDs to run the process with (first specified group is the primary group).
+ * has: Bitwise set of "has" codes representing what the Rule has.
+ * items: All items associated with the Rule.
+ * limits: The cpu/resource limits to use when executing the Rule.
+ * name: A human name for the Rule (does not have to be distinct), such as "Bash Script".
+ * nice: The niceness value if the Rule "has" nice.
+ * on: A set of parameters for defining dependencies and how they are needed, wanted, or wished for.
+ * parameter: Any parameters made available to the Rule for IKI substitution.
+ * path: The path to the Rule file.
+ * scheduler: The scheduler setting if the Rule "has" a scheduler.
+ * status: A set of action-specific success/failure status of the Rule. Each index represents a controller_rule_action_type_* enum value. Index 0 represents a global status.
+ * timeout_exit: The timeout to wait when exiting the Controller program after sending the terminate signal to send the kill signal.
+ * timeout_kill: The timeout to wait relating to using a kill signal.
+ * timeout_start: The timeout to wait relating to starting a process.
+ * timeout_stop: The timeout to wait relating to stopping a process.
+ * timestamp: The timestamp when the Rule was loaded.
+ * user: The User ID if the Rule "has" a user.
+ */
+#ifndef _di_controller_rule_t_
+ enum {
+ controller_rule_setting_type_affinity_e = 1,
+ controller_rule_setting_type_capability_e,
+ controller_rule_setting_type_cgroup_e,
+ controller_rule_setting_type_define_e,
+ controller_rule_setting_type_engine_e,
+ controller_rule_setting_type_environment_e,
+ controller_rule_setting_type_group_e,
+ controller_rule_setting_type_limit_e,
+ controller_rule_setting_type_name_e,
+ controller_rule_setting_type_nice_e,
+ controller_rule_setting_type_on_e,
+ controller_rule_setting_type_parameter_e,
+ controller_rule_setting_type_path_e,
+ controller_rule_setting_type_scheduler_e,
+ controller_rule_setting_type_timeout_e,
+ controller_rule_setting_type_user_e,
+ };
+
+ // bitwise codes representing properties on controller_rule_t that have been found in the Rule file.
+ #define controller_rule_has_cgroup_d 0x1
+ #define controller_rule_has_environment_d 0x2
+ #define controller_rule_has_group_d 0x4
+ #define controller_rule_has_nice_d 0x8
+ #define controller_rule_has_scheduler_d 0x10
+ #define controller_rule_has_user_d 0x20
+
+ // Designate codes for timeout settings to be used during the loading of the Rule timeout settings.
+ #define controller_rule_timeout_code_kill_d 1
+ #define controller_rule_timeout_code_start_d 2
+ #define controller_rule_timeout_code_stop_d 3
+
+ typedef struct {
+ f_status_t status[controller_rule_action_type__enum_size_e];
+
+ f_number_unsigned_t timeout_kill;
+ f_number_unsigned_t timeout_start;
+ f_number_unsigned_t timeout_stop;
+
+ uint8_t has;
+ int nice;
+ uid_t user;
+ gid_t group;
+
+ f_time_spec_t timestamp;
+
+ f_string_dynamic_t alias;
+ f_string_dynamic_t engine;
+ f_string_dynamic_t name;
+ f_string_dynamic_t path;
+
+ f_string_maps_t define;
+ f_string_maps_t parameter;
+
+ f_string_dynamics_t engine_arguments;
+ f_string_dynamics_t environment;
+
+ f_int32s_t affinity;
+ f_capability_t capability;
+ f_control_group_t cgroup;
+ f_int32s_t groups;
+ f_limit_sets_t limits;
+ f_execute_scheduler_t scheduler;
+
+ controller_rule_ons_t ons;
+ controller_rule_items_t items;
+ } controller_rule_t;
+
+ #define controller_rule_t_initialize { \
+ { \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ F_known_not, \
+ }, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ f_time_spec_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_maps_t_initialize, \
+ f_string_maps_t_initialize, \
+ f_string_dynamics_t_initialize, \
+ f_string_dynamics_t_initialize, \
+ f_int32s_t_initialize, \
+ f_capability_t_initialize, \
+ f_control_group_t_initialize, \
+ f_int32s_t_initialize, \
+ f_limit_sets_t_initialize, \
+ f_execute_scheduler_t_initialize, \
+ controller_rule_ons_initialize, \
+ controller_rule_items_initialize, \
+ }
+#endif // _di_controller_rule_t_
+
+/**
+ * The Rules.
+ *
+ * array: An array of Rules.
+ * size: Total amount of allocated space.
+ * used: Total number of allocated spaces used.
+ */
+#ifndef _di_controller_rules_t_
+ typedef struct {
+ controller_rule_t *array;
+
+ f_number_unsigned_t size;
+ f_number_unsigned_t used;
+ } controller_rules_t;
+
+ #define controller_rules_t_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ }
+#endif // _di_controller_rules_t_
+
+/**
+ * The process specific settings.
+ *
+ * controller_setting_ready_*:
+ * - no: Entry/Exit is not ready.
+ * - wait: Entry/Exit has "ready" somewhere in the file but is not yet ready.
+ * - yes: Entry/Exit is now ready (Entry/Exit is still being processed).
+ * - done: Entry/Exit is ready and processing is complete.
+ * - fail: Entry/Exit processing failed.
+ * - abort: Abort received before finished processing Entry/Exit.
+ *
+ * controller_setting_mode_*:
+ * - helper: Run as a helper, exiting when finished prrocess entry (and any respective exit).
+ * - program: Run as a program, exiting when finished prrocess entry (and any respective exit).
+ * - service: Run as a service, listening for requests after processing entry.
+ *
+ * controller_setting_flag_*:
+ * - interruptible: When specified, program responds to interrupt signals, otherwise block/ignore interrupt signals.
+ * - pid_created: When specified, the program responds to interrupt signals, otherwise block/ignore interrupt signals.
+ * - failsafe: When specified, failsafe mode is enabled, otherwise failsafe mode is disabled.
+ *
+ * flag: Flags from controller_setting_flag_*.
+ * ready: State representing if the settings are all loaded and is ready to run program operations.
+ * mode: Controller setting mode based on the setting mode enumerator.
+ * control: The control socket data.
+ * failsafe_item_id: The Entry Item ID to execute when failsafe execution is enabled.
+ * path_cgroup: Directory path to the cgroup directory.
+ * path_control: File path to the control socket (used for printing the path).
+ * path_pid: File path to the PID file.
+ * path_setting: File path to the setting directory.
+ * entry: The Entry settings.
+ * rules: All rules and their respective settings.
+ */
+#ifndef _di_controller_process_t_
+ enum {
+ controller_setting_ready_no_e = 0,
+ controller_setting_ready_wait_e,
+ controller_setting_ready_yes_e,
+ controller_setting_ready_done_e,
+ controller_setting_ready_fail_e,
+ controller_setting_ready_abort_e,
+ }; // enum
+
+ enum {
+ controller_setting_mode_service_e = 0,
+ controller_setting_mode_helper_e,
+ controller_setting_mode_program_e,
+ }; // enum
+
+ enum {
+ controller_setting_flag_interruptible_e = 0x1,
+ controller_setting_flag_pid_created_e = 0x2,
+ controller_setting_flag_failsafe_e = 0x4,
+ }; // enum
+
+ typedef struct {
+ uint8_t flag;
+ uint8_t ready;
+ uint8_t mode;
+
+ f_number_unsigned_t failsafe_item_id;
+
+ controller_control_t control;
+
+ f_string_dynamic_t path_cgroup;
+ f_string_dynamic_t path_control;
+ f_string_dynamic_t path_current;
+ f_string_dynamic_t path_pid;
+ f_string_dynamic_t path_setting;
+
+ f_string_dynamic_t name_entry;
+
+ controller_entry_t entry;
+ controller_entry_t exit;
+ controller_rules_t rules;
+ } controller_process_t;
+
+ #define controller_process_t_initialize { \
+ 0, \
+ 0, \
+ 0, \
+ 0, \
+ controller_control_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ f_string_dynamic_t_initialize, \
+ controller_entry_t_initialize, \
+ controller_entry_t_initialize, \
+ controller_rules_t_initialize, \
+ }
+#endif // _di_controller_process_t_
+
+/**
+ * The main program data as a single structure.
+ *
+ * program: The main program data.
+ * setting: The settings data.
+ *
+ * process: The active process information.
+ */
+#ifndef _di_controller_main_t_
+ typedef struct {
+ fll_program_data_t program;
+ controller_setting_t setting;
+
+ controller_process_t *process;
+ } controller_main_t;
+
+ #define controller_main_t_initialize \
+ { \
+ fll_program_data_t_initialize, \
+ controller_setting_t_initialize, \
+ controller_process_t_initialize, \
+ }
+#endif // _di_controller_main_t_
+
+/**
+ * Deallocate main program data.
+ *
+ * @param main
+ * The main program data.
+ *
+ * This does not alter main.setting.state.status.
+ *
+ * @return
+ * F_okay on success.
+ *
+ * F_parameter (with error bit) if a parameter is invalid.
+ */
+#ifndef _di_controller_main_delete_
+ extern f_status_t controller_main_delete(controller_main_t * const main);
+#endif // _di_controller_main_delete_
+
+/**
+ * Delete the controller control data.
+ *
+ * @param control
+ * The controller control data.
+ *
+ * @return
+ * F_okay on success.
+ *
+ * F_parameter (with error bit) if a parameter is invalid.
+ */
+#ifndef _di_controller_control_delete_
+ extern f_status_t controller_control_delete(controller_control_t * const control);
+#endif // _di_controller_control_delete_
+
+/**
* Identify the payload code the given name represents.
*
* @param payload
#endif // _di_controller_entry_action_type_name_
/**
- * Deallocate main.
- *
- * If main.signal is non-zero, then this blocks and handles the following signals:
- * - F_signal_abort
- * - F_signal_broken_pipe
- * - F_signal_hangup
- * - F_signal_interrupt
- * - F_signal_quit
- * - F_signal_termination
+ * Delete the controller process data.
*
- * @param main
- * The main program data.
+ * @param process
+ * The controller process data.
*
* @return
* F_okay on success.
*
- * Status codes (with error bit) are returned on any problem.
+ * F_parameter (with error bit) if a parameter is invalid.
*/
-#ifndef _di_controller_main_delete_
- extern f_status_t controller_main_delete(controller_main_t * const main);
-#endif // _di_controller_main_delete_
+#ifndef _di_controller_process_delete_
+ extern f_status_t controller_process_delete(controller_process_t * const process);
+#endif // _di_controller_process_delete_
/**
* Identify the rule action code the given name represents.
* The parameters passed to the process (often referred to as command line arguments).
* @param main
* The main program data.
- * @param setting
- * The main program settings.
*
- * This alters setting.state.status:
+ * This alters main.setting.state.status:
* F_okay on success.
*
* Errors (with error bit) from: f_console_parameter_process().
* @see fll_program_parameter_process_context()
*/
#ifndef _di_controller_setting_load_
- extern void controller_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main, controller_setting_t * const setting);
+ extern f_status_t controller_setting_load(const f_console_arguments_t arguments, fll_program_data_t * const main);
#endif // _di_controller_setting_load_
/**
- * Perform the standard program setting unload process.
+ * Fully deallocate all memory for the given entry action without caring about return status.
*
- * @param main
- * The main program and setting data.
- * All buffers are deallocated.
+ * @param action
+ * The action to deallocate.
*
- * This does not alter main.setting.state.status.
+ * @see f_memory_arrays_resize()
+ *
+ * @return
+ * F_okay on success.
+ *
+ * F_parameter (with error bit) if a parameter is invalid.
+ */
+#ifndef _di_controller_entry_action_delete_
+ extern f_status_t controller_entry_action_delete(controller_entry_action_t * const action);
+#endif // _di_controller_entry_action_delete_
+
+/**
+ * Fully deallocate all memory for the given entry actions without caring about return status.
+ *
+ * @param actions
+ * The entry_actions to deallocate.
+ *
+ * @return
+ * F_okay on success.
+ *
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see controller_entry_action_delete()
+ * @see f_memory_delete()
+ */
+#ifndef _di_controller_entry_actions_delete_
+ extern f_status_t controller_entry_actions_delete(controller_entry_actions_t * const actions);
+#endif // _di_controller_entry_actions_delete_
+
+/**
+ * Increase the size of the entry item actions array by the specified amount, but only if necessary.
+ *
+ * This only increases size if the current used plus amount is greater than the currently allocated size.
+ *
+ * @param amount
+ * A positive number representing how much to increase the size by.
+ * @param actions
+ * The entry item actions to resize.
+ *
+ * @return
+ * F_okay on success.
+ * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
+ *
+ * Errors (with error bit) from: f_memory_resize().
+ *
+ * @see f_memory_resize()
+ */
+#ifndef _di_controller_entry_actions_increase_by_
+ extern f_status_t controller_entry_actions_increase_by(const f_number_unsigned_t amount, controller_entry_actions_t * const actions);
+#endif // _di_controller_entry_actions_increase_by_
+
+/**
+ * Fully deallocate all memory for the given entry item without caring about return status.
+ *
+ * @param item
+ * The item to deallocate.
+ *
+ * @return
+ * F_okay on success.
+ *
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see f_memory_array_resize()
+ */
+#ifndef _di_controller_entry_item_delete_
+ extern f_status_t controller_entry_item_delete(controller_entry_item_t * const item);
+#endif // _di_controller_entry_item_delete_
+
+/**
+ * Fully deallocate all memory for the given entry items without caring about return status.
+ *
+ * @param items
+ * The entry_items to deallocate.
*
* @return
* F_okay on success.
*
* F_parameter (with error bit) if a parameter is invalid.
*
- * Errors (with error bit) from: controller_setting_delete().
+ * @see controller_entry_item_delete()
+ * @see f_memory_delete()
+ */
+#ifndef _di_controller_entry_items_delete_
+ extern f_status_t controller_entry_items_delete(controller_entry_items_t * const items);
+#endif // _di_controller_entry_items_delete_
+
+/**
+ * Increase the size of the entry items array by the specified amount, but only if necessary.
+ *
+ * This only increases size if the current used plus amount is greater than the currently allocated size.
+ *
+ * @param amount
+ * A positive number representing how much to increase the size by.
+ * @param items
+ * The entry items to resize.
+ *
+ * @return
+ * F_okay on success.
+ * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
+ *
+ * Errors (with error bit) from: f_memory_resize().
+ *
+ * @see f_memory_resize()
+ */
+#ifndef _di_controller_entry_items_increase_by_
+ extern f_status_t controller_entry_items_increase_by(const f_number_unsigned_t amount, controller_entry_items_t * const items);
+#endif // _di_controller_entry_items_increase_by_
+
+/**
+ * Fully deallocate all memory for the given Rule Action without caring about return status.
+ *
+ * @param action
+ * The action to deallocate.
+ *
+ * @see f_memory_arrays_resize()
+ */
+#ifndef _di_controller_rule_action_delete_
+ extern void controller_rule_action_delete(controller_rule_action_t * const action);
+#endif // _di_controller_rule_action_delete_
+
+/**
+ * Fully deallocate all memory for the given Rule Actions without caring about return status.
+ *
+ * @param actions
+ * The rule_actions to deallocate.
+ *
+ * @see controller_rule_action_delete()
+ * @see f_memory_delete()
+ */
+#ifndef _di_controller_rule_actions_delete_
+ extern void controller_rule_actions_delete(controller_rule_actions_t * const actions);
+#endif // _di_controller_rule_actions_delete_
+
+/**
+ * Increase the size of the Rule Actions array by the specified amount, but only if necessary.
+ *
+ * This only increases size if the current used plus amount is greater than the currently allocated size.
+ *
+ * @param amount
+ * A positive number representing how much to increase the size by.
+ * @param actions
+ * The actions to resize.
+ *
+ * @return
+ * F_okay on success.
+ * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
+ *
+ * Errors (with error bit) from: f_memory_resize().
+ */
+#ifndef _di_controller_rule_actions_increase_by_
+ extern f_status_t controller_rule_actions_increase_by(const f_number_unsigned_t amount, controller_rule_actions_t * const actions);
+#endif // _di_controller_rule_actions_increase_by_
+
+/**
+ * Fully deallocate all memory for the given Rule without caring about return status.
+ *
+ * @param rule
+ * The rule to deallocate.
+ *
+ * @see controller_rule_items_delete()
+ * @see f_capability_delete()
+ * @see f_memory_array_resize()
+ * @see f_memory_arrays_resize()
+ */
+#ifndef _di_controller_rule_delete_
+ extern void controller_rule_delete(controller_rule_t * const rule);
+#endif // _di_controller_rule_delete_
+
+/**
+ * Fully deallocate all memory for the given Rule Item without caring about return status.
+ *
+ * @param item
+ * The item to deallocate.
+ *
+ * @see f_memory_array_resize()
+ */
+#ifndef _di_controller_rule_item_delete_
+ extern void controller_rule_item_delete(controller_rule_item_t * const item);
+#endif // _di_controller_rule_item_delete_
+
+/**
+ * Fully deallocate all memory for the given Rule Items without caring about return status.
+ *
+ * @param items
+ * The rule_items to deallocate.
+ *
+ * @see controller_rule_item_delete()
+ * @see f_memory_delete()
+ */
+#ifndef _di_controller_rule_items_delete_
+ extern void controller_rule_items_delete(controller_rule_items_t * const items);
+#endif // _di_controller_rule_items_delete_
+
+/**
+ * Fully deallocate all memory for the given Rule Item without caring about return status.
+ *
+ * @param on
+ * The on to deallocate.
+ *
+ * @see f_memory_array_resize()
+ */
+#ifndef _di_controller_rule_on_delete_
+ extern void controller_rule_on_delete(controller_rule_on_t * const on);
+#endif // _di_controller_rule_on_delete_
+
+/**
+ * Fully deallocate all memory for the given Rule Items without caring about return status.
+ *
+ * @param ons
+ * The rule_ons to deallocate.
+ *
+ * @see controller_rule_on_delete()
+ * @see f_memory_delete()
+ */
+#ifndef _di_controller_rule_ons_delete_
+ extern void controller_rule_ons_delete(controller_rule_ons_t * const ons);
+#endif // _di_controller_rule_ons_delete_
+
+/**
+ * Increase the size of the Rule array, but only if necessary.
+ *
+ * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param ons
+ * The on array to resize.
+ *
+ * @return
+ * F_okay on success.
+ * F_data_not on success, but there is no reason to increase size (used + controller_common_allocation_small_d <= size).
+ *
+ * F_array_too_large (with error bit) if the new array length is too large.
+ * F_memory_not (with error bit) on out of memory.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see controller_rule_ons_resize()
+ */
+#ifndef _di_controller_rule_ons_increase_
+ extern f_status_t controller_rule_ons_increase(controller_rule_ons_t * const ons);
+#endif // _di_controller_rule_increase_
+
+/**
+ * Resize the Rule array.
+ *
+ * @param length
+ * The new size to use.
+ * @param ons
+ * The on array to resize.
+ *
+ * @return
+ * F_okay on success.
+ *
+ * F_memory_not (with error bit) on out of memory.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see f_memory_resize()
+ */
+#ifndef _di_controller_rule_ons_resize_
+ extern f_status_t controller_rule_ons_resize(const f_number_unsigned_t length, controller_rule_ons_t * const ons);
+#endif // _di_controller_rule_ons_resize_
+
+/**
+ * Fully deallocate all memory for the given Rules without caring about return status.
+ *
+ * @param rules
+ * The rules to deallocate.
+ *
+ * @see controller_rules_resize()
+ */
+#ifndef _di_controller_rules_delete_
+ extern void controller_rules_delete(controller_rules_t * const rules);
+#endif // _di_controller_rules_delete_
+
+/**
+ * Increase the size of the Rule array, but only if necessary.
+ *
+ * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d).
+ * If already set to the maximum buffer size, then the resize will fail.
+ *
+ * @param rules
+ * The rule array to resize.
+ *
+ * @return
+ * F_okay on success.
+ * F_data_not on success, but there is no reason to increase size (used + controller_common_allocation_small_d <= size).
+ *
+ * F_array_too_large (with error bit) if the new array length is too large.
+ * F_memory_not (with error bit) on out of memory.
+ * F_parameter (with error bit) if a parameter is invalid.
+ *
+ * @see controller_rules_resize()
+ */
+#ifndef _di_controller_rules_increase_
+ extern f_status_t controller_rules_increase(controller_rules_t * const rules);
+#endif // _di_controller_rule_increase_
+
+/**
+ * Resize the Rule array.
+ *
+ * @param length
+ * The new size to use.
+ * @param rules
+ * The rule array to resize.
+ *
+ * @return
+ * F_okay on success.
+ *
+ * F_memory_not (with error bit) on out of memory.
+ * F_parameter (with error bit) if a parameter is invalid.
*
- * @see controller_setting_delete()
+ * @see f_memory_resize()
*/
-#ifndef _di_controller_setting_unload_
- extern f_status_t controller_setting_unload(controller_main_t * const main);
-#endif // _di_controller_setting_unload_
+#ifndef _di_controller_rules_resize_
+ extern f_status_t controller_rules_resize(const f_number_unsigned_t length, controller_rules_t * const rules);
+#endif // _di_controller_rules_resize_
#ifdef __cplusplus
} // extern "C"
* setting: All loaded settings.
* thread: All thread related data.
*/
-#ifndef _di_controller_main_t_
+#ifndef _di_controller_main_old_t_
typedef struct {
controller_main_t *main;
- controller_setting_t *setting;
+ controller_process_t *setting;
controller_thread_t *thread;
} controller_global_t;
setting, \
thread, \
}
-#endif // _di_controller_main_t_
+#endif // _di_controller_main_old_t_
/**
* A wrapper used for passing a set of entry processing and execution related data.
#ifndef _di_controller_main_entry_t_
typedef struct {
controller_global_t *global;
- controller_setting_t *setting;
+ controller_process_t *setting;
} controller_main_entry_t;
#define controller_main_entry_t_initialize { 0, 0 }
extern "C" {
#endif
-#ifndef _di_controller_control_delete_simple_
- void controller_control_delete_simple(controller_control_t * const control) {
-
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_1.string, &control->cache_1.used, &control->cache_1.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_2.string, &control->cache_2.used, &control->cache_2.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->cache_3.string, &control->cache_3.used, &control->cache_3.size);
-
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->input.string, &control->input.used, &control->input.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &control->output.string, &control->output.used, &control->output.size);
- }
-#endif // _di_controller_control_delete_simple_
-
#ifdef __cplusplus
} // extern "C"
#endif
extern "C" {
#endif
-/**
- * Provide default control settings.
- *
- * controller_control_default:
- * - socket_backlog: The amount of waiting client connections to support while handling a socket connection.
- * - socket_buffer: The preferred max size of the buffer such that if the buffer exceeds this then it is reallocated to this size at the end of processing.
- * - socket_buffer_max: The max size allowed in the buffer (this value must not be set smaller than the packet headers).
- * - socket_cache: The preferred max size of the control cache such that if the cache exceeds this then it is reallocated to this size at the end of processing.
- * - socket_header: The minimum size in bytes of the packet header to read to be able to process the size information.
- * - socket_linger: The number of seconds to linger the connection before closing.
- * - socket_timeout: The number of microseconds to wait.
- * - socket_payload_max: The max size allowed for the "payload" part of a packet and must be smaller than socket_buffer_max (this is smaller than socket_buffer_max to allow for enough room to afford a header).
- */
-#ifndef _di_controller_control_defaults_
- #define controller_control_default_socket_backlog_d 64
- #define controller_control_default_socket_buffer_d 2048
- #define controller_control_default_socket_buffer_max_d 4294967296
- #define controller_control_default_socket_cache_d 128
- #define controller_control_default_socket_header_d 5
- #define controller_control_default_socket_linger_d 2
- #define controller_control_default_socket_timeout_d 10000 // 0.01 seconds.
- #define controller_control_default_socket_payload_max_d 4294965248
-#endif // _di_controller_defaults_
-
-
-/**
- * The control data.
- *
- * controller_control_flag_*:
- * - readonly: Control is set to read-only mode.
- * - has_user: A user is manually specified.
- * - has_group: A group is manually specified.
- * - has_mode: A file mode is manually specified.
- *
- * flag: Flags from controller_control_flag_*.
- * user: The user ID, if specified.
- * group: The group ID, if specified.
- * mode: The file mode, if specified.
- * server: The server socket connection.
- * client: The client socket connection.
- * cache_1: A generic buffer used for caching control related data.
- * cache_2: A generic buffer used for caching control related data.
- * cache_3: A generic buffer used for caching control related data.
- * input: A buffer used for receiving data from the client.
- * output: A buffer used for transmitting data to the client.
- * address: The socket address structure.
- */
-#ifndef _di_controller_control_t_
- enum {
- controller_control_flag_readonly_e = 0x1,
- controller_control_flag_has_user_e = 0x2,
- controller_control_flag_has_group_e = 0x4,
- controller_control_flag_has_mode_e = 0x8,
- };
-
- typedef struct {
- uint8_t flag;
-
- uid_t user;
- gid_t group;
- mode_t mode;
-
- f_socket_t server;
- f_socket_t client;
-
- f_string_dynamic_t cache_1;
- f_string_dynamic_t cache_2;
- f_string_dynamic_t cache_3;
-
- f_string_dynamic_t input;
- f_string_dynamic_t output;
-
- struct sockaddr_un address;
- } controller_control_t;
-
- #define controller_control_t_initialize { \
- 0, \
- -1, \
- -1, \
- 0, \
- f_socket_t_initialize, \
- f_socket_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- { }, \
- }
-#endif // _di_controller_control_t_
-
-/**
- * A codes repesent different flags associated with a packet.
- *
- * controller_control_packet_flag_*:
- * - binary: Designate that the packet is in binary mode (when not set then packet is in string mode).
- * - endian_big: Designate that the packet is in big endian order (when not set then packet is in little endian order).
- */
-#ifndef _di_controller_control_packet_flag_
- #define controller_control_packet_flag_binary_d 0x10000000
- #define controller_control_packet_flag_endian_big_d 0x01000000
-#endif // _di_controller_control_packet_flag_
-
-/**
- * Fully deallocate all memory for the given control data without caring about return status.
- *
- * @param control
- * The structure to deallocate.
- */
-#ifndef _di_controller_control_delete_simple_
- extern void controller_control_delete_simple(controller_control_t * const control) F_attribute_visibility_internal_d;
-#endif // _di_controller_control_delete_simple_
-
#ifdef __cplusplus
} // extern "C"
#endif
extern "C" {
#endif
-#ifndef _di_controller_entry_action_delete_simple_
- void controller_entry_action_delete_simple(controller_entry_action_t * const action) {
-
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &action->parameters.array, &action->parameters.used, &action->parameters.size, &f_string_dynamics_delete_callback);
- }
-#endif // _di_controller_entry_action_delete_simple_
-
-#ifndef _di_controller_entry_actions_delete_simple_
- void controller_entry_actions_delete_simple(controller_entry_actions_t * const actions) {
-
- // @todo Determine if this should be replaced with a resize callback strategy.
- actions->used = actions->size;
-
- while (actions->used) {
- controller_entry_action_delete_simple(&actions->array[--actions->used]);
- } // while
-
- f_memory_array_resize(0, sizeof(controller_entry_action_t), (void **) &actions->array, &actions->used, &actions->size);
- }
-#endif // _di_controller_entry_actions_delete_simple_
-
-#ifndef _di_controller_entry_actions_increase_by_
- f_status_t controller_entry_actions_increase_by(const f_number_unsigned_t amount, controller_entry_actions_t * const actions) {
-
- if (amount) {
- if (actions->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
-
- const f_number_unsigned_t length = actions->used + amount;
-
- if (length > actions->size) {
- const f_status_t status = f_memory_resize(actions->size, length, sizeof(controller_entry_action_t), (void **) & actions->array);
-
- if (F_status_is_error_not(status)) {
- actions->size = actions->used + amount;
- }
-
- return status;
- }
- }
-
- return F_data_not;
- }
-#endif // _di_controller_entry_actions_increase_by_
-
-#ifndef _di_controller_entry_item_delete_simple_
- void controller_entry_item_delete_simple(controller_entry_item_t * const item) {
-
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &item->name.string, &item->name.used, &item->name.size);
-
- controller_entry_actions_delete_simple(&item->actions);
- }
-#endif // _di_controller_entry_item_delete_simple_
-
-#ifndef _di_controller_entry_items_delete_simple_
- void controller_entry_items_delete_simple(controller_entry_items_t * const items) {
-
- // @todo Determine if this should be replaced with a resize callback strategy.
- items->used = items->size;
-
- while (items->used) {
- controller_entry_item_delete_simple(&items->array[--items->used]);
- } // while
-
- f_memory_array_resize(0, sizeof(controller_entry_item_t), (void **) &items->array, &items->used, &items->size);
- }
-#endif // _di_controller_entry_items_delete_simple_
-
-#ifndef _di_controller_entry_items_increase_by_
- f_status_t controller_entry_items_increase_by(const f_number_unsigned_t amount, controller_entry_items_t * const items) {
-
- if (amount) {
- if (items->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
-
- const f_number_unsigned_t length = items->used + amount;
-
- if (length > items->size) {
- const f_status_t status = f_memory_resize(items->size, length, sizeof(controller_entry_item_t), (void **) & items->array);
-
- if (F_status_is_error_not(status)) {
- items->size = items->used + amount;
- }
-
- return status;
- }
- }
-
- return F_data_not;
- }
-#endif // _di_controller_entry_items_increase_by_
-
#ifdef __cplusplus
} // extern "C"
#endif
extern "C" {
#endif
-/**
- * An Entry Item Action.
- *
- * controller_entry_action_flag_*:
- * - undefined: The given type and code are designated as undefined.
- *
- * controller_entry_action_type_*:
- * - consider: Designate a rule to be pre-loaded.
- * - execute: Execute into another program.
- * - failsafe: Designate a failsafe "item".
- * - freeze: A Rule Action for freezing.
- * - item: A named set of Rules.
- * - kill: A Rule Action for killing.
- * - pause: A Rule Action for pausing.
- * - ready: Designate readiness for special processing for Entry or Exit.
- * - reload: A Rule Action for reloading.
- * - restart: A Rule Action for restarting.
- * - resume: A Rule Action for resuming.
- * - start: A Rule Action for starting.
- * - stop: A Rule Action for stopping.
- * - timeout: Inline timeout settings.
- * - thaw: A Rule Action for unfreezing.
- *
- * controller_entry_rule_code_*:
- * - asynchronous: Process Rule asynchronously.
- * - require: Require Rule operations to succeed or the Entry/Exit will fail.
- * - wait: Wait for all existing asynchronous processes to finish before operating Rule.
- *
- * controller_entry_timeout_code_*:
- * - exit: The timeout Action represents an exit timeout.
- * - kill: The timeout Action represents a kill timeout.
- * - start: The timeout Action represents a start timeout.
- * - stop: The timeout Action represents a stop timeout.
- *
- * type: The type of Action.
- * code: A single code or sub-type associated with the Action.
- * flag: A set of flags to describe special behavior for the given type and code (flags may be different per type and code).
- * line: The line number where the Entry Item begins.
- * number: The unsigned number that some types use instead of the "parameters".
- * status: The overall status.
- * parameters: The values associated with the Action.
- */
-#ifndef _di_controller_entry_action_t_
- #define controller_entry_rule_code_asynchronous_d 0x1
- #define controller_entry_rule_code_require_d 0x2
- #define controller_entry_rule_code_wait_d 0x4
-
- #define controller_entry_timeout_code_exit_d 0x1
- #define controller_entry_timeout_code_kill_d 0x2
- #define controller_entry_timeout_code_start_d 0x4
- #define controller_entry_timeout_code_stop_d 0x8
-
- enum {
- controller_entry_action_flag_none_e = 0x0,
- controller_entry_action_flag_undefined_e = 0x1,
- };
-
- typedef struct {
- uint8_t type;
- uint8_t code;
- uint8_t flag;
-
- f_number_unsigned_t line;
- f_number_unsigned_t number;
-
- f_status_t status;
-
- f_string_dynamics_t parameters;
- } controller_entry_action_t;
-
- #define controller_entry_action_t_initialize { \
- 0, \
- 0, \
- 0, \
- controller_entry_action_flag_none_e, \
- 0, \
- F_known_not, \
- f_string_dynamics_t_initialize, \
- }
-#endif // _di_controller_entry_action_t_
-
-/**
- * The Entry Item Actions.
- *
- * array: An array of Entry Item Actions.
- * size: Total amount of allocated space.
- * used: Total number of allocated spaces used.
- */
-#ifndef _di_controller_entry_actions_t_
- typedef struct {
- controller_entry_action_t *array;
-
- f_number_unsigned_t size;
- f_number_unsigned_t used;
- } controller_entry_actions_t;
-
- #define controller_entry_actions_t_initialize { \
- 0, \
- 0, \
- 0, \
- }
-#endif // _di_controller_entry_actions_t_
-
-/**
- * An Entry Item.
- *
- * line: The line number where the Entry Item begins.
- * name: The name of the Entry Item.
- * actions: The Actions associated with the Entry Item.
- */
-#ifndef _di_controller_entry_item_t_
- typedef struct {
- f_number_unsigned_t line;
- f_string_dynamic_t name;
-
- controller_entry_actions_t actions;
- } controller_entry_item_t;
-
- #define controller_entry_item_t_initialize \
- { \
- 0, \
- f_string_dynamic_t_initialize, \
- controller_entry_actions_t_initialize, \
- }
-#endif // _di_controller_entry_item_t_
-
-/**
- * An Entry Items.
- *
- * array: An array of Entry Items.
- * size: Total amount of allocated space.
- * used: Total number of allocated spaces used.
- */
-#ifndef _di_controller_entry_items_t_
- typedef struct {
- controller_entry_item_t *array;
-
- f_number_unsigned_t size;
- f_number_unsigned_t used;
- } controller_entry_items_t;
-
- #define controller_entry_items_t_initialize { \
- 0, \
- 0, \
- 0, \
- }
-
- #define macro_controller_entry_items_t_clear(items) \
- items.array = 0; \
- items.size = 0; \
- items.used = 0;
-#endif // _di_controller_entry_items_t_
-
-/**
- * The Entry or Exit.
- *
- * Entry and Exit files are essentially the same structure with minor differences in settings and behavior.
- * The structure is identical and due to lacking any particularly good name to represent both "entry" or "exit", the name "entry" is being used for both.
- *
- * controller_entry_flag_*:
- * - none_e: No flags are set.
- * - timeout_exit_no_e: The exit timeout is disabled.
- * - timeout_kill_no_e: The kill timeout is disabled for Rules by default.
- * - timeout_start_no_e: The start timeout is disabled for Rules by default.
- * - timeout_stop_no_e: The stop timeout is disabled for Rules by default.
- *
- * controller_entry_session_*:
- * - none: No special session configuration specified, use built in defaults.
- * - new: Designate the default to use a new session, ignoring built in defaults (passing FL_execute_parameter_option_session_d to the execute functions).
- * - same: Designate the default to use a same session, ignoring built in defaults.
- *
- * controller_entry_pid_*:
- * - disable: Do not check for or create a PID file to represent the entry execution.
- * - require: Check to see if the PID file exists for an entry at startup and then when "ready" create a pid file, display error on pid file already exists or on failure and then fail.
- * - ready: When "ready" create a pid file, display error on failure and then fail (does not check if PID file exists).
- *
- * controller_entry_show_*:
- * - normal: Do not print anything other than warnings and errors, but allow executed programs and scripts to output however they like.
- * - init: Print like an init program, printing status of entry and rules as they are being started, stopped, etc...
- *
- * define: Any defines (environment variables) made available to all Rules in this entry for IKI substitution or just as environment variables.
- * flag: A set of flags, primarily used to designate that timeouts are disabled.
- * items: The array of entry items.
- * parameter: Any parameters made available to all Rules in this entry for IKI substitution.
- * pid: The PID file generation setting.
- * session: The default session settings (when NULL, no default is specified).
- * show: The show setting for controlling what to show when executing entry items and rules.
- * status: The overall status.
- * timeout_exit: The timeout to wait when exiting the Controller program after sending the terminate signal to send the kill signal.
- * timeout_kill: The timeout to wait relating to using a kill signal.
- * timeout_start: The timeout to wait relating to starting a process.
- * timeout_stop: The timeout to wait relating to stopping a process.
- */
-#ifndef _di_controller_entry_t_
- enum {
- controller_entry_pid_disable_e = 0,
- controller_entry_pid_require_e,
- controller_entry_pid_ready_e,
- };
-
- enum {
- controller_entry_show_normal_e = 0,
- controller_entry_show_init_e,
- };
-
- enum {
- controller_entry_session_none_e = 0,
- controller_entry_session_new_e,
- controller_entry_session_same_e,
- };
-
- enum {
- controller_entry_flag_none_e = 0x0,
- controller_entry_flag_timeout_exit_no_e = 0x1,
- controller_entry_flag_timeout_kill_no_e = 0x2,
- controller_entry_flag_timeout_start_no_e = 0x4,
- controller_entry_flag_timeout_stop_no_e = 0x8,
- };
-
- typedef struct {
- f_status_t status;
-
- uint8_t pid;
- uint8_t session;
- uint8_t show;
- uint8_t flag;
-
- f_number_unsigned_t timeout_exit;
- f_number_unsigned_t timeout_kill;
- f_number_unsigned_t timeout_start;
- f_number_unsigned_t timeout_stop;
-
- f_string_maps_t define;
- f_string_maps_t parameter;
-
- controller_entry_items_t items;
- } controller_entry_t;
-
- #define controller_entry_t_initialize { \
- F_known_not, \
- controller_entry_pid_require_e, \
- controller_entry_session_none_e, \
- controller_entry_show_normal_e, \
- 0, \
- controller_thread_exit_timeout_d, \
- 0, \
- 0, \
- 0, \
- f_string_maps_t_initialize, \
- f_string_maps_t_initialize, \
- controller_entry_items_t_initialize, \
- }
-#endif // _di_controller_entry_t_
-
-/**
- * Fully deallocate all memory for the given entry action without caring about return status.
- *
- * @param action
- * The action to deallocate.
- *
- * @see f_memory_arrays_resize()
- */
-#ifndef _di_controller_entry_action_delete_simple_
- extern void controller_entry_action_delete_simple(controller_entry_action_t * const action) F_attribute_visibility_internal_d;
-#endif // _di_controller_entry_action_delete_simple_
-
-/**
- * Fully deallocate all memory for the given entry actions without caring about return status.
- *
- * @param actions
- * The entry_actions to deallocate.
- *
- * @see controller_entry_action_delete_simple()
- * @see f_memory_delete()
- */
-#ifndef _di_controller_entry_actions_delete_simple_
- extern void controller_entry_actions_delete_simple(controller_entry_actions_t * const actions) F_attribute_visibility_internal_d;
-#endif // _di_controller_entry_actions_delete_simple_
-
-/**
- * Increase the size of the entry item actions array by the specified amount, but only if necessary.
- *
- * This only increases size if the current used plus amount is greater than the currently allocated size.
- *
- * @param amount
- * A positive number representing how much to increase the size by.
- * @param actions
- * The entry item actions to resize.
- *
- * @return
- * F_okay on success.
- * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
- *
- * Errors (with error bit) from: f_memory_resize().
- *
- * @see f_memory_resize()
- */
-#ifndef _di_controller_entry_actions_increase_by_
- extern f_status_t controller_entry_actions_increase_by(const f_number_unsigned_t amount, controller_entry_actions_t * const actions) F_attribute_visibility_internal_d;
-#endif // _di_controller_entry_actions_increase_by_
-
-/**
- * Fully deallocate all memory for the given entry item without caring about return status.
- *
- * @param item
- * The item to deallocate.
- *
- * @see f_memory_array_resize()
- */
-#ifndef _di_controller_entry_item_delete_simple_
- extern void controller_entry_item_delete_simple(controller_entry_item_t * const item) F_attribute_visibility_internal_d;
-#endif // _di_controller_entry_item_delete_simple_
-
-/**
- * Fully deallocate all memory for the given entry items without caring about return status.
- *
- * @param items
- * The entry_items to deallocate.
- *
- * @see controller_entry_item_delete_simple()
- * @see f_memory_delete()
- */
-#ifndef _di_controller_entry_items_delete_simple_
- extern void controller_entry_items_delete_simple(controller_entry_items_t * const items) F_attribute_visibility_internal_d;
-#endif // _di_controller_entry_items_delete_simple_
-
-/**
- * Increase the size of the entry items array by the specified amount, but only if necessary.
- *
- * This only increases size if the current used plus amount is greater than the currently allocated size.
- *
- * @param amount
- * A positive number representing how much to increase the size by.
- * @param items
- * The entry items to resize.
- *
- * @return
- * F_okay on success.
- * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
- *
- * Errors (with error bit) from: f_memory_resize().
- *
- * @see f_memory_resize()
- */
-#ifndef _di_controller_entry_items_increase_by_
- extern f_status_t controller_entry_items_increase_by(const f_number_unsigned_t amount, controller_entry_items_t * const items) F_attribute_visibility_internal_d;
-#endif // _di_controller_entry_items_increase_by_
-
#ifdef __cplusplus
} // extern "C"
#endif
#endif // _di_controller_pids_resize_
#ifndef _di_controller_process_delete_simple_
- void controller_process_delete_simple(controller_process_t * const process) {
+ void controller_process_delete_simple(controller_data_t * const process) {
if (process->id_thread) {
f_thread_signal_write(process->id_thread, F_signal_kill);
}
} // for
- status = f_memory_resize(processs->size, length, sizeof(controller_process_t), (void **) & processs->array);
+ status = f_memory_resize(processs->size, length, sizeof(controller_data_t), (void **) & processs->array);
if (F_status_is_error(status)) return status;
if (length) {
- controller_process_t *process = 0;
+ controller_data_t *process = 0;
// The lock must be initialized, but only once, so initialize immediately upon allocation.
for (; processs->size < length; ++processs->size) {
- status = f_memory_new(1, sizeof(controller_process_t), (void **) &processs->array[processs->size]);
+ status = f_memory_new(1, sizeof(controller_data_t), (void **) &processs->array[processs->size]);
if (F_status_is_error_not(status)) {
process = processs->array[processs->size];
* stack: A stack used to represent dependencies as Rule ID's to avoid circular rule dependencies (If Rule A waits on Rule B, then Rule B must not wait on Rule A).
* state: The state of the process.
* status: The last execution status of the process.
- * type: The currently active process type (from the controller_process_type_*_e).
+ * type: The currently active process type (from the controller_data_type_*_e).
* wait: A thread condition to tell a process waiting process that the rule has is done being processed.
* wait_lock: A mutex lock for working with "wait".
*
* main_data: Used for passing the controller_main_t data to the process thread (to populate controller_global_t).
- * main_setting: Used for passing the controller_setting_t data to the process thread (to populate controller_global_t).
+ * main_setting: Used for passing the controller_process_t data to the process thread (to populate controller_global_t).
* main_thread: Used for passing the controller_thread_t data to the process thread (to populate controller_global_t).
*/
-#ifndef _di_controller_process_t_
+#ifndef _di_controller_data_t_
#define controller_process_option_asynchronous_d 0x1
#define controller_process_option_require_d 0x2
#define controller_process_option_simulate_d 0x4
};
enum {
- controller_process_type_entry_e = 1,
- controller_process_type_exit_e,
- controller_process_type_control_e,
+ controller_data_type_entry_e = 1,
+ controller_data_type_exit_e,
+ controller_data_type_control_e,
};
typedef struct {
void *main_data;
void *main_setting;
void *main_thread;
- } controller_process_t;
+ } controller_data_t;
- #define controller_process_t_initialize { \
+ #define controller_data_t_initialize { \
0, \
0, \
0, \
0, \
0, \
}
-#endif // _di_controller_process_t_
+#endif // _di_controller_data_t_
/**
* The Rule Processes.
*/
#ifndef _di_controller_processs_t_
typedef struct {
- controller_process_t **array;
+ controller_data_t **array;
f_number_unsigned_t size;
f_number_unsigned_t used;
* @see f_thread_mutex_delete()
*/
#ifndef _di_controller_process_delete_simple_
- extern void controller_process_delete_simple(controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern void controller_process_delete_simple(controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_process_delete_simple_
/**
extern "C" {
#endif
-#ifndef _di_controller_rule_action_t_
- const f_string_static_t controller_rule_action_method_string_extended_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_string_extended_s, 0, CONTROLLER_rule_action_method_string_extended_s_length);
- const f_string_static_t controller_rule_action_method_string_extended_list_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_string_extended_list_s, 0, CONTROLLER_rule_action_method_string_extended_list_s_length);
-#endif // _di_controller_rule_action_t_
-
-#ifndef _di_controller_rule_action_delete_simple_
- void controller_rule_action_delete_simple(controller_rule_action_t * const action) {
-
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &action->parameters.array, &action->parameters.used, &action->parameters.size, &f_string_dynamics_delete_callback);
-
- f_memory_array_resize(0, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size);
- }
-#endif // _di_controller_rule_action_delete_simple_
-
-#ifndef _di_controller_rule_actions_delete_simple_
- void controller_rule_actions_delete_simple(controller_rule_actions_t * const actions) {
-
- actions->used = actions->size;
-
- while (actions->used) {
- controller_rule_action_delete_simple(&actions->array[--actions->used]);
- } // while
-
- f_memory_delete(actions->size, sizeof(controller_rule_action_t), (void **) & actions->array);
- actions->size = 0;
- }
-#endif // _di_controller_rule_actions_delete_simple_
-
-#ifndef _di_controller_rule_actions_increase_by_
- f_status_t controller_rule_actions_increase_by(const f_number_unsigned_t amount, controller_rule_actions_t * const actions) {
-
- if (amount) {
- if (actions->used >= F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large);
-
- const f_number_unsigned_t length = actions->used + amount;
-
- if (length > actions->size) {
- const f_status_t status = f_memory_resize(actions->size, length, sizeof(controller_rule_action_t), (void **) & actions->array);
-
- if (F_status_is_error_not(status)) {
- actions->size = actions->used + amount;
- }
-
- return status;
- }
- }
-
- return F_data_not;
- }
-#endif // _di_controller_rule_actions_increase_by_
-
-#ifndef _di_controller_rule_delete_simple_
- void controller_rule_delete_simple(controller_rule_t * const rule) {
-
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->engine.string, &rule->engine.used, &rule->engine.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->name.string, &rule->name.used, &rule->name.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->path.string, &rule->path.used, &rule->path.size);
-
- f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &rule->define.array, &rule->define.used, &rule->define.size, &f_string_maps_delete_callback);
- f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &rule->parameter.array, &rule->parameter.used, &rule->parameter.size, &f_string_maps_delete_callback);
-
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->engine_arguments.array, &rule->engine_arguments.used, &rule->engine_arguments.size, &f_string_dynamics_delete_callback);
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->environment.array, &rule->environment.used, &rule->environment.size, &f_string_dynamics_delete_callback);
-
- f_memory_array_resize(0, sizeof(int32_t), (void **) &rule->affinity.array, &rule->affinity.used, &rule->affinity.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &rule->cgroup.path.string, &rule->cgroup.path.used, &rule->cgroup.path.size);
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &rule->cgroup.groups.array, &rule->cgroup.groups.used, &rule->cgroup.groups.size, &f_string_dynamics_delete_callback);
- f_memory_array_resize(0, sizeof(int32_t), (void **) &rule->groups.array, &rule->groups.used, &rule->groups.size);
- f_memory_array_resize(0, sizeof(f_limit_set_t), (void **) &rule->limits.array, &rule->limits.used, &rule->limits.size);
-
- if (rule->capability) {
- f_capability_delete(&rule->capability);
- }
-
- controller_rule_ons_delete_simple(&rule->ons);
- controller_rule_items_delete_simple(&rule->items);
- }
-#endif // _di_controller_rule_delete_simple_
-
-#ifndef _di_controller_rule_item_delete_simple_
- void controller_rule_item_delete_simple(controller_rule_item_t * const item) {
-
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &item->pid_file.string, &item->pid_file.used, &item->pid_file.size);
-
- controller_rule_actions_delete_simple(&item->actions);
- }
-#endif // _di_controller_rule_item_delete_simple_
-
-#ifndef _di_controller_rule_items_delete_simple_
- void controller_rule_items_delete_simple(controller_rule_items_t * const items) {
-
- items->used = items->size;
-
- while (items->used) {
- controller_rule_item_delete_simple(&items->array[--items->used]);
- } // while
-
- f_memory_delete(items->size, sizeof(controller_rule_item_t), (void **) & items->array);
- items->size = 0;
- }
-#endif // _di_controller_rule_items_delete_simple_
-
-#ifndef _di_controller_rule_on_delete_simple_
- void controller_rule_on_delete_simple(controller_rule_on_t * const on) {
-
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->need.array, &on->need.used, &on->need.size, &f_string_dynamics_delete_callback);
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->want.array, &on->want.used, &on->want.size, &f_string_dynamics_delete_callback);
- f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &on->wish.array, &on->wish.used, &on->wish.size, &f_string_dynamics_delete_callback);
- }
-#endif // _di_controller_rule_on_delete_simple_
-
-#ifndef _di_controller_rule_ons_delete_simple_
- void controller_rule_ons_delete_simple(controller_rule_ons_t * const ons) {
-
- ons->used = ons->size;
-
- while (ons->used) {
- controller_rule_on_delete_simple(&ons->array[--ons->used]);
- } // while
-
- f_memory_delete(ons->size, sizeof(controller_rule_on_t), (void **) & ons->array);
- ons->size = 0;
- }
-#endif // _di_controller_rule_ons_delete_simple_
-
-#ifndef _di_controller_rule_ons_increase_
- f_status_t controller_rule_ons_increase(controller_rule_ons_t * const ons) {
-
- if (ons->used + 1 > ons->size) {
- f_number_unsigned_t length = ons->used + controller_common_allocation_small_d;
-
- if (length > F_number_t_size_unsigned_d) {
- if (ons->used + 1 > F_number_t_size_unsigned_d) {
- return F_status_set_error(F_array_too_large);
- }
-
- length = F_number_t_size_unsigned_d;
- }
-
- return controller_rule_ons_resize(length, ons);
- }
-
- return F_data_not;
- }
-#endif // _di_controller_rule_ons_increase_
-
-#ifndef _di_controller_rule_ons_resize_
- f_status_t controller_rule_ons_resize(const f_number_unsigned_t length, controller_rule_ons_t * const ons) {
-
- for (f_number_unsigned_t i = length; i < ons->size; ++i) {
- controller_rule_on_delete_simple(&ons->array[i]);
- } // for
-
- const f_status_t status = f_memory_resize(ons->size, length, sizeof(controller_rule_on_t), (void **) & ons->array);
- if (F_status_is_error(status)) return status;
-
- ons->size = length;
-
- if (ons->used > ons->size) {
- ons->used = length;
- }
-
- return F_okay;
- }
-#endif // _di_controller_rule_ons_resize_
-
-#ifndef _di_controller_rules_delete_simple_
- void controller_rules_delete_simple(controller_rules_t * const rules) {
-
- controller_rules_resize(0, rules);
- }
-#endif // _di_controller_rules_delete_simple_
-
-#ifndef _di_controller_rules_increase_
- f_status_t controller_rules_increase(controller_rules_t * const rules) {
-
- if (rules->used + 1 > rules->size) {
- f_number_unsigned_t length = rules->used + controller_common_allocation_small_d;
-
- if (length > F_number_t_size_unsigned_d) {
- if (rules->used + 1 > F_number_t_size_unsigned_d) {
- return F_status_set_error(F_array_too_large);
- }
-
- length = F_number_t_size_unsigned_d;
- }
-
- return controller_rules_resize(length, rules);
- }
-
- return F_data_not;
- }
-#endif // _di_controller_rules_increase_
-
-#ifndef _di_controller_rules_resize_
- f_status_t controller_rules_resize(const f_number_unsigned_t length, controller_rules_t * const rules) {
-
- for (f_number_unsigned_t i = length; i < rules->size; ++i) {
- controller_rule_delete_simple(&rules->array[i]);
- } // for
-
- const f_status_t status = f_memory_resize(rules->size, length, sizeof(controller_rule_t), (void **) & rules->array);
- if (F_status_is_error(status)) return status;
-
- rules->size = length;
-
- if (rules->used > rules->size) {
- rules->used = length;
- }
-
- return F_okay;
- }
-#endif // _di_controller_rules_resize_
-
#ifdef __cplusplus
} // extern "C"
#endif
extern "C" {
#endif
-/**
- * The Rule "rerun" item for controlling re-execution.
- *
- * count: A count of the number of executions.
- * delay: The time to wait before attempting to re-run.
- * max: The maximum number of times to re-run (with 0 representing re-run infinitely) for executions.
- */
-#ifndef _di_controller_rule_rerun_item_t_
- typedef struct {
- bool reset;
-
- f_number_unsigned_t count;
- f_number_unsigned_t delay;
- f_number_unsigned_t max;
- } controller_rule_rerun_item_t;
-
- #define controller_rule_rerun_item_initialize { \
- F_false, \
- 0, \
- 5000, \
- 0, \
-
- #define macro_controller_rule_rerun_item_initialize(item) { \
- item.reset = F_false; \
- item.count = 0; \
- item.delay = 5000; \
- item.max = 0; \
- }
-#endif // _di_controller_rule_rerun_item_t_
-
-/**
- * The Rule "rerun" values for controlling re-execution.
- *
- * controller_rule_rerun_is_*:
- * - failure: The success re-run is enabled.
- * - failure_reset: Reset success counter when failure is returned.
- * - success: The success re-run is enabled.
- * - success_reset: Reset failure counter when success is returned.
- *
- * is: A bitwise set of options to designate whether rerun is enabled or not and other options.
- * count_failure: A count of the number of failed executions.
- * count_success: A count of the number of successful executions.
- * delay_failure: The time to wait before attempting to "rerun" for failed executions.
- * delay_success: The time to wait before attempting to "rerun" for successful executions.
- * max_failure: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for failed executions.
- * max_success: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for successful executions.
- */
-#ifndef _di_controller_rule_rerun_t_
- #define controller_rule_rerun_is_failure_d 0x1
- #define controller_rule_rerun_is_failure_reset_d 0x2
- #define controller_rule_rerun_is_success_d 0x4
- #define controller_rule_rerun_is_success_reset_d 0x8
-
- typedef struct {
- uint8_t is;
-
- controller_rule_rerun_item_t failure;
- controller_rule_rerun_item_t success;
- } controller_rule_rerun_t;
-
- #define controller_rule_rerun_initialize { \
- 0, \
- controller_rule_rerun_item_initialize, \
- controller_rule_rerun_item_initialize, \
- }
-#endif // _di_controller_rule_rerun_t_
-
-/**
- * A Rule Action.
- *
- * controller_rule_action_method_*:
- * - extended: Designate that this Action is represented using FSS Extended.
- * - extended_list: Designate that this Action is represented using FSS Extended List.
- *
- * type: The Rule Action type.
- * line: The line number where the Rule Action begins.
- * status: The last execution status of the Rule Action.
- * parameters: All parameters associated with the Rule Action.
- */
-#ifndef _di_controller_rule_action_t_
- #define CONTROLLER_rule_action_method_string_extended_s "FSS-0001 (Extended)"
- #define CONTROLLER_rule_action_method_string_extended_list_s "FSS-0003 (Extended List)"
-
- #define CONTROLLER_rule_action_method_string_extended_s_length 19
- #define CONTROLLER_rule_action_method_string_extended_list_s_length 24
-
- extern const f_string_static_t controller_rule_action_method_string_extended_s;
- extern const f_string_static_t controller_rule_action_method_string_extended_list_s;
-
- enum {
- controller_rule_action_method_extended_e = 1,
- controller_rule_action_method_extended_list_e,
- };
-
- typedef struct {
- uint8_t type;
- f_number_unsigned_t line;
- f_status_t status;
-
- f_string_dynamics_t parameters;
- f_iki_datas_t ikis;
- } controller_rule_action_t;
-
- #define controller_rule_action_t_initialize { \
- 0, \
- 0, \
- F_known_not, \
- f_string_dynamics_t_initialize, \
- f_iki_datas_t_initialize, \
- }
-#endif // _di_controller_rule_action_t_
-
-/**
- * The Rule Actions.
- *
- * array: An array of Rule Actions.
- * size: Total amount of allocated space.
- * used: Total number of allocated spaces used.
- */
-#ifndef _di_controller_rule_actions_t_
- typedef struct {
- controller_rule_action_t *array;
-
- f_number_unsigned_t size;
- f_number_unsigned_t used;
- } controller_rule_actions_t;
-
- #define controller_rule_actions_t_initialize { \
- 0, \
- 0, \
- 0, \
- }
-#endif // _di_controller_rule_actions_t_
-
-/**
- * A Rule Item.
- *
- * controller_rule_item_type_*:
- * - command: A Command to execute.
- * - script: A Script to execute.
- * - service: A Service to execute.
- * - setting: Settings associated with the Rule Item.
- * - utility: A Utility to execute.
- *
- * type: The type of the Rule Item.
- * with: A bitwise number representing execute "with" options.
- * line: The line number where the Rule Item begins.
- * reruns: An array designating rerun settings for each execution type available.
- * actions: The actions associated with the Rule Item.
- */
-#ifndef _di_controller_rule_item_t_
- typedef struct {
- uint8_t type;
- uint8_t with;
- f_number_unsigned_t line;
-
- f_string_dynamic_t pid_file;
- controller_rule_rerun_t reruns[controller_rule_action_execute_type__enum_size_e];
- controller_rule_actions_t actions;
- } controller_rule_item_t;
-
- #define controller_rule_item_t_initialize \
- { \
- 0, \
- 0, \
- 0, \
- f_string_dynamic_t_initialize, \
- { \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- controller_rule_rerun_t_initialize, \
- }, \
- controller_rule_actions_t_initialize, \
- }
-#endif // _di_controller_rule_item_t_
-
-/**
- * The Rule Items.
- *
- * array: An array of Rule Items.
- * size: Total amount of allocated space.
- * used: Total number of allocated spaces used.
- */
-#ifndef _di_controller_rule_items_t_
- typedef struct {
- controller_rule_item_t *array;
-
- f_number_unsigned_t size;
- f_number_unsigned_t used;
- } controller_rule_items_t;
-
- #define controller_rule_items_initialize { \
- 0, \
- 0, \
- 0, \
- }
-#endif // _di_controller_rule_items_t_
-
-/**
- * The Rule "on" values for designating dependencies.
- *
- * action: The Rule Action type this "on" dependencies are associated with.
- * need: The Rule Alias for a required Rule.
- * want: The Rule Alias for an optional Rule that is required to succeed if found.
- * wish: The Rule Alias for an optional Rule that is not required.
- */
-#ifndef _di_controller_rule_on_t_
- typedef struct {
- uint8_t action;
-
- f_string_dynamics_t need;
- f_string_dynamics_t want;
- f_string_dynamics_t wish;
- } controller_rule_on_t;
-
- #define controller_rule_on_initialize { \
- 0, \
- f_string_dynamics_t_initialize, \
- f_string_dynamics_t_initialize, \
- f_string_dynamics_t_initialize, \
- }
-#endif // _di_controller_rule_on_t_
-
-/**
- * The Rule "on" array.
- *
- * array: An array of Rule "on" values.
- * size: Total amount of allocated space.
- * used: Total number of allocated spaces used.
- */
-#ifndef _di_controller_rule_ons_t_
- typedef struct {
- controller_rule_on_t *array;
-
- f_number_unsigned_t size;
- f_number_unsigned_t used;
- } controller_rule_ons_t;
-
- #define controller_rule_ons_t_initialize { \
- 0, \
- 0, \
- 0, \
- }
-#endif // _di_controller_rule_ons_t_
-
-/**
- * A Rule.
- *
- * controller_rule_setting_type_*:
- * - affinity: Setting type representing a affinity.
- * - capability: Setting type representing a capability.
- * - cgroup: Setting type representing a control group.
- * - define: Setting type representing a define.
- * - engine: Setting type representing a engine.
- * - engine_arguments: Setting type representing a engine.
- * - environment: Setting type representing a environment.
- * - group: Setting type representing a group.
- * - limit: Setting type representing a limit.
- * - name: Setting type representing a name.
- * - nice: Setting type representing a nice.
- * - on: Setting type representing a on.
- * - parameter: Setting type representing a parameter.
- * - path: Setting type representing a path.
- * - scheduler: Setting type representing a scheduler.
- * - user: Setting type representing a user.
- *
- * controller_rule_has_*:
- * - cgroup: Has type representing a control group.
- * - group: Has type representing a group.
- * - nice: Has type representing a nice.
- * - scheduler: Has type representing a scheduler.
- * - user: Has type representing a user.
- *
- * affinity: The cpu affinity to be used when executing the Rule.
- * alias: The distinct ID (machine name) of the Rule, such as "service/ssh".
- * capability: The capability setting if the Rule "has" a capability.
- * cgroup: The control group setting if the Rule "has" a control group.
- * define: Any defines (environment variables) made available to the Rule for IKI substitution or just as environment variables.
- * engine: The program or path to the program of the scripting engine to use when processing scripts in this Rule.
- * engine_arguments: Any arguments to pass to the engine program.
- * environment: All environment variables allowed to be exposed to the Rule when processing.
- * group: The group ID if the Rule "has" a group.
- * groups: A set of group IDs to run the process with (first specified group is the primary group).
- * has: Bitwise set of "has" codes representing what the Rule has.
- * items: All items associated with the Rule.
- * limits: The cpu/resource limits to use when executing the Rule.
- * name: A human name for the Rule (does not have to be distinct), such as "Bash Script".
- * nice: The niceness value if the Rule "has" nice.
- * on: A set of parameters for defining dependencies and how they are needed, wanted, or wished for.
- * parameter: Any parameters made available to the Rule for IKI substitution.
- * path: The path to the Rule file.
- * scheduler: The scheduler setting if the Rule "has" a scheduler.
- * status: A set of action-specific success/failure status of the Rule. Each index represents a controller_rule_action_type_* enum value. Index 0 represents a global status.
- * timeout_exit: The timeout to wait when exiting the Controller program after sending the terminate signal to send the kill signal.
- * timeout_kill: The timeout to wait relating to using a kill signal.
- * timeout_start: The timeout to wait relating to starting a process.
- * timeout_stop: The timeout to wait relating to stopping a process.
- * timestamp: The timestamp when the Rule was loaded.
- * user: The User ID if the Rule "has" a user.
- */
-#ifndef _di_controller_rule_t_
- enum {
- controller_rule_setting_type_affinity_e = 1,
- controller_rule_setting_type_capability_e,
- controller_rule_setting_type_cgroup_e,
- controller_rule_setting_type_define_e,
- controller_rule_setting_type_engine_e,
- controller_rule_setting_type_environment_e,
- controller_rule_setting_type_group_e,
- controller_rule_setting_type_limit_e,
- controller_rule_setting_type_name_e,
- controller_rule_setting_type_nice_e,
- controller_rule_setting_type_on_e,
- controller_rule_setting_type_parameter_e,
- controller_rule_setting_type_path_e,
- controller_rule_setting_type_scheduler_e,
- controller_rule_setting_type_timeout_e,
- controller_rule_setting_type_user_e,
- };
-
- // bitwise codes representing properties on controller_rule_t that have been found in the Rule file.
- #define controller_rule_has_cgroup_d 0x1
- #define controller_rule_has_environment_d 0x2
- #define controller_rule_has_group_d 0x4
- #define controller_rule_has_nice_d 0x8
- #define controller_rule_has_scheduler_d 0x10
- #define controller_rule_has_user_d 0x20
-
- // Designate codes for timeout settings to be used during the loading of the Rule timeout settings.
- #define controller_rule_timeout_code_kill_d 1
- #define controller_rule_timeout_code_start_d 2
- #define controller_rule_timeout_code_stop_d 3
-
- typedef struct {
- f_status_t status[controller_rule_action_type__enum_size_e];
-
- f_number_unsigned_t timeout_kill;
- f_number_unsigned_t timeout_start;
- f_number_unsigned_t timeout_stop;
-
- uint8_t has;
- int nice;
- uid_t user;
- gid_t group;
-
- f_time_spec_t timestamp;
-
- f_string_dynamic_t alias;
- f_string_dynamic_t engine;
- f_string_dynamic_t name;
- f_string_dynamic_t path;
-
- f_string_maps_t define;
- f_string_maps_t parameter;
-
- f_string_dynamics_t engine_arguments;
- f_string_dynamics_t environment;
-
- f_int32s_t affinity;
- f_capability_t capability;
- f_control_group_t cgroup;
- f_int32s_t groups;
- f_limit_sets_t limits;
- f_execute_scheduler_t scheduler;
-
- controller_rule_ons_t ons;
- controller_rule_items_t items;
- } controller_rule_t;
-
- #define controller_rule_t_initialize { \
- { \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- F_known_not, \
- }, \
- 0, \
- 0, \
- 0, \
- 0, \
- 0, \
- 0, \
- 0, \
- f_time_spec_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_maps_t_initialize, \
- f_string_maps_t_initialize, \
- f_string_dynamics_t_initialize, \
- f_string_dynamics_t_initialize, \
- f_int32s_t_initialize, \
- f_capability_t_initialize, \
- f_control_group_t_initialize, \
- f_int32s_t_initialize, \
- f_limit_sets_t_initialize, \
- f_execute_scheduler_t_initialize, \
- controller_rule_ons_initialize, \
- controller_rule_items_initialize, \
- }
-#endif // _di_controller_rule_t_
-
-/**
- * The Rules.
- *
- * array: An array of Rules.
- * size: Total amount of allocated space.
- * used: Total number of allocated spaces used.
- */
-#ifndef _di_controller_rules_t_
- typedef struct {
- controller_rule_t *array;
-
- f_number_unsigned_t size;
- f_number_unsigned_t used;
- } controller_rules_t;
-
- #define controller_rules_t_initialize { \
- 0, \
- 0, \
- 0, \
- }
-#endif // _di_controller_rules_t_
-
-/**
- * Fully deallocate all memory for the given Rule Action without caring about return status.
- *
- * @param action
- * The action to deallocate.
- *
- * @see f_memory_arrays_resize()
- */
-#ifndef _di_controller_rule_action_delete_simple_
- extern void controller_rule_action_delete_simple(controller_rule_action_t * const action) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_action_delete_simple_
-
-/**
- * Fully deallocate all memory for the given Rule Actions without caring about return status.
- *
- * @param actions
- * The rule_actions to deallocate.
- *
- * @see controller_rule_action_delete_simple()
- * @see f_memory_delete()
- */
-#ifndef _di_controller_rule_actions_delete_simple_
- extern void controller_rule_actions_delete_simple(controller_rule_actions_t * const actions) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_actions_delete_simple_
-
-/**
- * Increase the size of the Rule Actions array by the specified amount, but only if necessary.
- *
- * This only increases size if the current used plus amount is greater than the currently allocated size.
- *
- * @param amount
- * A positive number representing how much to increase the size by.
- * @param actions
- * The actions to resize.
- *
- * @return
- * F_okay on success.
- * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
- *
- * Errors (with error bit) from: f_memory_resize().
- */
-#ifndef _di_controller_rule_actions_increase_by_
- extern f_status_t controller_rule_actions_increase_by(const f_number_unsigned_t amount, controller_rule_actions_t * const actions) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_actions_increase_by_
-
-/**
- * Fully deallocate all memory for the given Rule without caring about return status.
- *
- * @param rule
- * The rule to deallocate.
- *
- * @see controller_rule_items_delete_simple()
- * @see f_capability_delete()
- * @see f_memory_array_resize()
- * @see f_memory_arrays_resize()
- */
-#ifndef _di_controller_rule_delete_simple_
- extern void controller_rule_delete_simple(controller_rule_t * const rule) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_delete_simple_
-
-/**
- * Fully deallocate all memory for the given Rule Item without caring about return status.
- *
- * @param item
- * The item to deallocate.
- *
- * @see f_memory_array_resize()
- */
-#ifndef _di_controller_rule_item_delete_simple_
- extern void controller_rule_item_delete_simple(controller_rule_item_t * const item) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_item_delete_simple_
-
-/**
- * Fully deallocate all memory for the given Rule Items without caring about return status.
- *
- * @param items
- * The rule_items to deallocate.
- *
- * @see controller_rule_item_delete_simple()
- * @see f_memory_delete()
- */
-#ifndef _di_controller_rule_items_delete_simple_
- extern void controller_rule_items_delete_simple(controller_rule_items_t * const items) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_items_delete_simple_
-
-/**
- * Fully deallocate all memory for the given Rule Item without caring about return status.
- *
- * @param on
- * The on to deallocate.
- *
- * @see f_memory_array_resize()
- */
-#ifndef _di_controller_rule_on_delete_simple_
- extern void controller_rule_on_delete_simple(controller_rule_on_t * const on) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_on_delete_simple_
-
-/**
- * Fully deallocate all memory for the given Rule Items without caring about return status.
- *
- * @param ons
- * The rule_ons to deallocate.
- *
- * @see controller_rule_on_delete_simple()
- * @see f_memory_delete()
- */
-#ifndef _di_controller_rule_ons_delete_simple_
- extern void controller_rule_ons_delete_simple(controller_rule_ons_t * const ons) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_ons_delete_simple_
-
-/**
- * Increase the size of the Rule array, but only if necessary.
- *
- * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d).
- * If already set to the maximum buffer size, then the resize will fail.
- *
- * @param ons
- * The on array to resize.
- *
- * @return
- * F_okay on success.
- * F_data_not on success, but there is no reason to increase size (used + controller_common_allocation_small_d <= size).
- *
- * F_array_too_large (with error bit) if the new array length is too large.
- * F_memory_not (with error bit) on out of memory.
- * F_parameter (with error bit) if a parameter is invalid.
- *
- * @see controller_rule_ons_resize()
- */
-#ifndef _di_controller_rule_ons_increase_
- extern f_status_t controller_rule_ons_increase(controller_rule_ons_t * const ons) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_increase_
-
-/**
- * Resize the Rule array.
- *
- * @param length
- * The new size to use.
- * @param ons
- * The on array to resize.
- *
- * @return
- * F_okay on success.
- *
- * F_memory_not (with error bit) on out of memory.
- * F_parameter (with error bit) if a parameter is invalid.
- *
- * @see f_memory_resize()
- */
-#ifndef _di_controller_rule_ons_resize_
- extern f_status_t controller_rule_ons_resize(const f_number_unsigned_t length, controller_rule_ons_t * const ons) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_ons_resize_
-
-/**
- * Fully deallocate all memory for the given Rules without caring about return status.
- *
- * @param rules
- * The rules to deallocate.
- *
- * @see controller_rules_resize()
- */
-#ifndef _di_controller_rules_delete_simple_
- extern void controller_rules_delete_simple(controller_rules_t * const rules) F_attribute_visibility_internal_d;
-#endif // _di_controller_rules_delete_simple_
-
-/**
- * Increase the size of the Rule array, but only if necessary.
- *
- * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d).
- * If already set to the maximum buffer size, then the resize will fail.
- *
- * @param rules
- * The rule array to resize.
- *
- * @return
- * F_okay on success.
- * F_data_not on success, but there is no reason to increase size (used + controller_common_allocation_small_d <= size).
- *
- * F_array_too_large (with error bit) if the new array length is too large.
- * F_memory_not (with error bit) on out of memory.
- * F_parameter (with error bit) if a parameter is invalid.
- *
- * @see controller_rules_resize()
- */
-#ifndef _di_controller_rules_increase_
- extern f_status_t controller_rules_increase(controller_rules_t * const rules) F_attribute_visibility_internal_d;
-#endif // _di_controller_rule_increase_
-
-/**
- * Resize the Rule array.
- *
- * @param length
- * The new size to use.
- * @param rules
- * The rule array to resize.
- *
- * @return
- * F_okay on success.
- *
- * F_memory_not (with error bit) on out of memory.
- * F_parameter (with error bit) if a parameter is invalid.
- *
- * @see f_memory_resize()
- */
-#ifndef _di_controller_rules_resize_
- extern f_status_t controller_rules_resize(const f_number_unsigned_t length, controller_rules_t * const rules) F_attribute_visibility_internal_d;
-#endif // _di_controller_rules_resize_
-
#ifdef __cplusplus
} // extern "C"
#endif
extern "C" {
#endif
-#ifndef _di_controller_setting_delete_simple_
- void controller_setting_delete_simple(controller_setting_t * const setting) {
-
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->name_entry.string, &setting->name_entry.used, &setting->name_entry.size);
-
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->path_cgroup.string, &setting->path_cgroup.used, &setting->path_cgroup.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->path_control.string, &setting->path_control.used, &setting->path_control.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->path_current.string, &setting->path_current.used, &setting->path_current.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->path_pid.string, &setting->path_pid.used, &setting->path_pid.size);
- f_memory_array_resize(0, sizeof(f_char_t), (void **) &setting->path_setting.string, &setting->path_setting.used, &setting->path_setting.size);
-
- controller_control_delete_simple(&setting->control);
-
- status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &setting->entry.define.array, &setting->entry.define.used, &setting->entry.define.size, &f_string_maps_delete_callback);
- status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &setting->entry.parameter.array, &setting->entry.parameter.used, &setting->entry.parameter.size, &f_string_maps_delete_callback);
-
- status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &setting->exit.define.array, &setting->exit.define.used, &setting->exit.define.size, &f_string_maps_delete_callback);
- status = f_memory_arrays_resize(0, sizeof(f_string_map_t), (void **) &setting->exit.parameter.array, &setting->exit.parameter.used, &setting->exit.parameter.size, &f_string_maps_delete_callback);
-
- controller_entry_items_delete_simple(&setting->entry.items);
- controller_entry_items_delete_simple(&setting->exit.items);
-
- controller_rules_delete_simple(&setting->rules);
- }
-#endif // _di_controller_setting_delete_simple_
-
#ifdef __cplusplus
} // extern "C"
#endif
extern "C" {
#endif
-/**
- * All setting data.
- *
- * controller_setting_ready_*:
- * - no: Entry/Exit is not ready.
- * - wait: Entry/Exit has "ready" somewhere in the file but is not yet ready.
- * - yes: Entry/Exit is now ready (Entry/Exit is still being processed).
- * - done: Entry/Exit is ready and processing is complete.
- * - fail: Entry/Exit processing failed.
- * - abort: Abort received before finished processing Entry/Exit.
- *
- * controller_setting_mode_*:
- * - helper: Run as a helper, exiting when finished prrocess entry (and any respective exit).
- * - program: Run as a program, exiting when finished prrocess entry (and any respective exit).
- * - service: Run as a service, listening for requests after processing entry.
- *
- * controller_setting_flag_*:
- * - interruptible: When specified, program responds to interrupt signals, otherwise block/ignore interrupt signals.
- * - pid_created: When specified, the program responds to interrupt signals, otherwise block/ignore interrupt signals.
- * - failsafe: When specified, failsafe mode is enabled, otherwise failsafe mode is disabled.
- *
- * flag: Flags from controller_setting_flag_*.
- * ready: State representing if the settings are all loaded and is ready to run program operations.
- * mode: Controller setting mode based on the setting mode enumerator.
- * control: The control socket data.
- * failsafe_item_id: The Entry Item ID to execute when failsafe execution is enabled.
- * path_cgroup: Directory path to the cgroup directory.
- * path_control: File path to the control socket (used for printing the path).
- * path_pid: File path to the PID file.
- * path_setting: File path to the setting directory.
- * entry: The Entry settings.
- * rules: All rules and their respective settings.
- */
-#ifndef _di_controller_setting_t_
- enum {
- controller_setting_ready_no_e = 0,
- controller_setting_ready_wait_e,
- controller_setting_ready_yes_e,
- controller_setting_ready_done_e,
- controller_setting_ready_fail_e,
- controller_setting_ready_abort_e,
- }; // enum
-
- enum {
- controller_setting_mode_service_e = 0,
- controller_setting_mode_helper_e,
- controller_setting_mode_program_e,
- }; // enum
-
- enum {
- controller_setting_flag_interruptible_e = 0x1,
- controller_setting_flag_pid_created_e = 0x2,
- controller_setting_flag_failsafe_e = 0x4,
- }; // enum
-
- typedef struct {
- uint8_t flag;
- uint8_t ready;
- uint8_t mode;
-
- f_number_unsigned_t failsafe_item_id;
-
- controller_control_t control;
-
- f_string_dynamic_t path_cgroup;
- f_string_dynamic_t path_control;
- f_string_dynamic_t path_current;
- f_string_dynamic_t path_pid;
- f_string_dynamic_t path_setting;
-
- f_string_dynamic_t name_entry;
-
- controller_entry_t entry;
- controller_entry_t exit;
- controller_rules_t rules;
- } controller_setting_t;
-
- #define controller_setting_t_initialize { \
- 0, \
- 0, \
- 0, \
- 0, \
- controller_control_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- f_string_dynamic_t_initialize, \
- controller_entry_t_initialize, \
- controller_entry_t_initialize, \
- controller_rules_t_initialize, \
- }
-#endif // _di_controller_setting_t_
-
-/**
- * Fully deallocate all memory for the given setting without caring about return status.
- *
- * @param setting
- * The setting to deallocate.
- *
- * @see controller_entry_delete_simple()
- * @see controller_rules_delete_simple()
- *
- * @see f_memory_array_resize()
- */
-#ifndef _di_controller_setting_delete_simple_
- extern void controller_setting_delete_simple(controller_setting_t * const setting) F_attribute_visibility_internal_d;
-#endif // _di_controller_setting_delete_simple_
-
#ifdef __cplusplus
} // extern "C"
#endif
#endif
#ifndef _di_controller_main_
- f_status_t controller_main(controller_main_t * const main, const f_console_arguments_t arguments) {
-
- f_status_t status = F_okay;
-
- setting->state.step_small = controller_allocation_console_d;
-
- status = f_console_parameter_process(arguments, &main->parameters, &setting->state, 0);
-
- setting->state.step_small = controller_allocation_small_d;
+ void controller_main(controller_main_t * const main) {
if (F_status_is_error(status)) return;
- status = fll_program_parameter_process_context_standard(F_true, &main->program);
-
- if (F_status_is_error(status)) {
- fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process_context_standard", fll_error_file_flag_fallback_e);
-
- if (main->error.verbosity > f_console_verbosity_quiet_e) {
- fll_print_dynamic_raw(f_string_eol_s, main->error);
- }
-
- return;
+ if ((main->setting.flag & controller_main_flag_print_first_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+ fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
}
- status = fll_program_parameter_process_verbosity_standard(F_true, &main->program);
+ main->setting.state.status = F_okay;
- if (F_status_is_error(status)) {
- fll_error_print(main->error, F_status_set_fine(status), "fll_program_parameter_process_verbosity_standard", fll_error_file_flag_fallback_e);
+ if (main->setting.flag & controller_main_flag_version_copyright_help_e) {
+ if (main->setting.flag & controller_main_flag_help_e) {
+ controller_print_message_help(&main->program.message);
+ }
+ else if (main->setting.flag & controller_main_flag_version_e) {
+ fll_program_print_version(&main->program.message, controller_program_version_s);
+ }
+ else if (main->setting.flag & controller_main_flag_copyright_e) {
+ fll_program_print_copyright(&main->program.message);
+ }
- if (main->error.verbosity > f_console_verbosity_quiet_e) {
- fll_print_dynamic_raw(f_string_eol_s, main->error);
+ if ((main->setting.flag & controller_main_flag_print_last_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+ fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
}
return;
}
- if (main->parameters.array[f_console_standard_parameter_help_e].result & f_console_result_found_e) {
- controller_print_help(main);
-
- return F_okay;
- }
-
- if (main->parameters.array[f_console_standard_parameter_version_e].result & f_console_result_found_e) {
- fll_program_print_version(main->message, controller_program_version_s);
+ if ((main->setting.flag & controller_main_flag_operation_build_e) && (main->setting.flag & controller_main_flag_operation_make_e)) {
+ main->setting.state.status = F_status_set_error(F_parameter);
- return F_okay;
- }
+ controller_print_error_parameter_operation_not_with(&main->program.error, controller_other_operation_build_s, controller_other_operation_make_s);
- if (main->parameters.array[f_console_standard_parameter_copyright_e].result & f_console_result_found_e) {
- fll_program_print_copyright(main->message);
+ if ((main->setting.flag & controller_main_flag_print_last_e) && main->program.message.verbosity > f_console_verbosity_error_e) {
+ fll_print_dynamic_raw(f_string_eol_s, main->program.message.to);
+ }
- return F_okay;
+ return;
}
- status = F_okay;
-
f_string_static_t * const argv = main->parameters.arguments.array;
- controller_setting_t setting = controller_setting_t_initialize;
+ controller_process_t process = controller_process_t_initialize;
- setting.control.server.address = (struct sockaddr *) &setting.control.address;
- setting.control.server.domain = f_socket_protocol_family_local_e;
- setting.control.server.type = f_socket_type_stream_d;
- setting.control.server.length = sizeof(struct sockaddr_un);
+ process.control.server.address = (struct sockaddr *) &process.control.address;
+ process.control.server.domain = f_socket_protocol_family_local_e;
+ process.control.server.type = f_socket_type_stream_d;
+ process.control.server.length = sizeof(struct sockaddr_un);
- memset(setting.control.server.address, 0, setting.control.server.length);
+ memset(process.control.server.address, 0, process.control.server.length);
if (main->parameters.remaining.used) {
- status = f_string_dynamic_append(argv[main->parameters.remaining.array[0]], &setting.name_entry);
+ status = f_string_dynamic_append(argv[main->parameters.remaining.array[0]], &process.name_entry);
}
else {
- status = f_string_dynamic_append(controller_default_s, &setting.name_entry);
+ status = f_string_dynamic_append(controller_default_s, &process.name_entry);
}
if (F_status_is_error(status)) {
}
if (main->as_init) {
- setting.mode = controller_setting_mode_service_e;
+ process.mode = controller_setting_mode_service_e;
}
- status = f_path_current(F_false, &setting.path_current);
+ status = f_path_current(F_false, &process.path_current);
if (F_status_is_error(status)) {
fll_error_print(main->error, F_status_set_fine(status), "f_path_current", fll_error_file_flag_fallback_e);
else if (main->parameters.array[controller_parameter_settings_e].locations.used) {
const f_number_unsigned_t index = main->parameters.array[controller_parameter_settings_e].values.array[main->parameters.array[controller_parameter_settings_e].values.used - 1];
- status = controller_path_canonical_relative(&setting, argv[index], &setting.path_setting);
+ status = controller_path_canonical_relative(&process, argv[index], &process.path_setting);
if (F_status_is_error(status)) {
fll_error_file_print(main->error, F_status_set_fine(status), "controller_path_canonical_relative", fll_error_file_flag_fallback_e, argv[index], f_file_operation_verify_s, fll_error_file_type_path_e);
}
}
else {
- setting.path_setting.used = 0;
+ process.path_setting.used = 0;
if (main->as_init) {
- status = f_string_dynamic_append(*main->default_path_setting_init, &setting.path_setting);
+ status = f_string_dynamic_append(*main->default_path_setting_init, &process.path_setting);
}
else {
- status = f_string_dynamic_append(*main->default_path_setting, &setting.path_setting);
+ status = f_string_dynamic_append(*main->default_path_setting, &process.path_setting);
}
if (F_status_is_error(status)) {
status = F_status_set_error(F_parameter);
}
else if (main->parameters.array[controller_parameter_pid_e].locations.used) {
- setting.path_pid.used = 0;
+ process.path_pid.used = 0;
const f_number_unsigned_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) {
- status = controller_path_canonical_relative(&setting, argv[index], &setting.path_pid);
+ status = controller_path_canonical_relative(&process, argv[index], &process.path_pid);
if (F_status_is_error(status)) {
fll_error_file_print(main->error, F_status_set_fine(status), "controller_path_canonical_relative", fll_error_file_flag_fallback_e, argv[index], f_file_operation_verify_s, fll_error_file_type_path_e);
}
}
- if (F_status_is_error_not(status) && !setting.path_pid.used && !main->parameters.array[controller_parameter_pid_e].locations.used) {
+ if (F_status_is_error_not(status) && !process.path_pid.used && !main->parameters.array[controller_parameter_pid_e].locations.used) {
if (main->as_init) {
- status = f_string_dynamic_append(*main->default_path_pid_init, &setting.path_pid);
+ status = f_string_dynamic_append(*main->default_path_pid_init, &process.path_pid);
}
else {
- status = f_string_dynamic_append(*main->default_path_pid, &setting.path_pid);
+ status = f_string_dynamic_append(*main->default_path_pid, &process.path_pid);
}
if (F_status_is_error_not(status)) {
- status = f_string_dynamic_append(f_path_separator_s, &setting.path_pid);
+ status = f_string_dynamic_append(f_path_separator_s, &process.path_pid);
}
if (F_status_is_error_not(status)) {
- status = f_string_dynamic_append(*main->default_path_pid_prefix, &setting.path_pid);
+ status = f_string_dynamic_append(*main->default_path_pid_prefix, &process.path_pid);
}
if (F_status_is_error_not(status)) {
- status = f_string_dynamic_append(setting.name_entry, &setting.path_pid);
+ status = f_string_dynamic_append(process.name_entry, &process.path_pid);
}
if (F_status_is_error_not(status)) {
- status = f_string_dynamic_append(*main->default_path_pid_suffix, &setting.path_pid);
+ status = f_string_dynamic_append(*main->default_path_pid_suffix, &process.path_pid);
}
if (F_status_is_error(status)) {
const f_number_unsigned_t index = main->parameters.array[controller_parameter_cgroup_e].values.array[main->parameters.array[controller_parameter_cgroup_e].values.used - 1];
if (argv[index].used) {
- status = controller_path_canonical_relative(&setting, argv[index], &setting.path_cgroup);
+ status = controller_path_canonical_relative(&process, argv[index], &process.path_cgroup);
if (F_status_is_error(status)) {
fll_error_file_print(main->error, F_status_set_fine(status), "controller_path_canonical_relative", fll_error_file_flag_fallback_e, argv[index], f_file_operation_verify_s, fll_error_file_type_path_e);
}
else {
- status = f_string_append_assure(F_path_separator_s, 1, &setting.path_cgroup);
+ status = f_string_append_assure(F_path_separator_s, 1, &process.path_cgroup);
if (F_status_is_error(status)) {
fll_error_print(main->error, F_status_set_fine(status), "f_string_append_assure", fll_error_file_flag_fallback_e);
// Handle defaults dependent on the "as init" execution state.
if (main->as_init) {
- setting.entry.pid = controller_entry_pid_disable_e;
- setting.entry.show = controller_entry_show_init_e;
+ process.entry.pid = controller_entry_pid_disable_e;
+ process.entry.show = controller_entry_show_init_e;
if (main->parameters.array[controller_parameter_interruptible_e].result & f_console_result_found_e) {
- setting.flag |= controller_setting_flag_interruptible_e;
+ process.flag |= controller_setting_flag_interruptible_e;
}
else {
- setting.flag &= ~controller_setting_flag_interruptible_e;
+ process.flag &= ~controller_setting_flag_interruptible_e;
}
}
else {
if (main->parameters.array[controller_parameter_uninterruptible_e].result & f_console_result_found_e) {
- setting.flag &= ~controller_setting_flag_interruptible_e;
+ process.flag &= ~controller_setting_flag_interruptible_e;
}
else {
- setting.flag |= controller_setting_flag_interruptible_e;
+ process.flag |= controller_setting_flag_interruptible_e;
}
}
}
// A control file path is required.
- if (!setting.path_cgroup.used) {
- status = f_string_append_nulless(F_control_group_path_system_prefix_s, F_control_group_path_system_prefix_s_length, &setting.path_cgroup);
+ if (!process.path_cgroup.used) {
+ status = f_string_append_nulless(F_control_group_path_system_prefix_s, F_control_group_path_system_prefix_s_length, &process.path_cgroup);
if (F_status_is_error_not(status)) {
- status = f_string_append_nulless(F_control_group_path_system_default_s, F_control_group_path_system_default_s_length, &setting.path_cgroup);
+ status = f_string_append_nulless(F_control_group_path_system_default_s, F_control_group_path_system_default_s_length, &process.path_cgroup);
}
if (F_status_is_error(status)) {
fll_error_print(main->error, F_status_set_fine(status), "f_string_append_nulless", fll_error_file_flag_fallback_e);
}
else {
- status = f_string_append_assure(F_path_separator_s, 1, &setting.path_cgroup);
+ status = f_string_append_assure(F_path_separator_s, 1, &process.path_cgroup);
if (F_status_is_error(status)) {
fll_error_print(main->error, F_status_set_fine(status), "f_string_append_assure", fll_error_file_flag_fallback_e);
}
if (F_status_is_error_not(status)) {
- status = controller_thread_main(main, &setting);
+ status = controller_thread_main(main, &process);
}
// Ensure a newline is always put at the end of the program execution, unless in quiet mode.
fll_print_dynamic_raw(f_string_eol_s, main->output.to);
}
- if (status != F_child && (setting.flag & controller_setting_flag_pid_created_e)) {
- const f_status_t status_delete = controller_file_pid_delete(main->pid, setting.path_pid);
+ if (status != F_child && (process.flag & controller_setting_flag_pid_created_e)) {
+ const f_status_t status_delete = controller_file_pid_delete(main->pid, process.path_pid);
if (F_status_is_error(status_delete) && main->warning.verbosity == f_console_verbosity_debug_e) {
if (F_status_set_fine(status_delete) == F_number_not) {
controller_lock_print(main->warning.to, 0);
fl_print_format("%r%[%QThe pid file '%]", main->warning.to, f_string_eol_s, main->warning.context, main->warning.prefix, main->warning.context);
- fl_print_format(f_string_format_Q_single_s.string, main->warning.to, main->warning.notable, setting.path_pid, main->warning.notable);
+ fl_print_format(f_string_format_Q_single_s.string, main->warning.to, main->warning.notable, process.path_pid, main->warning.notable);
fl_print_format("%[' must not be specified with the parameter '%]", main->warning.to, main->warning.context, main->warning.context);
fl_print_format("%[%i%]", main->warning.to, main->warning.notable, main->pid, main->warning.notable);
fl_print_format("%[' doesn't contain the expected number, not deleting file.%]%r", main->warning.to, main->warning.context, main->warning.context, f_string_eol_s);
controller_unlock_print_flush(main->warning.to, 0);
}
else if (F_status_set_fine(status_delete) != F_interrupt) {
- fll_error_file_print(main->warning, F_status_set_fine(status_delete), "controller_file_pid_delete", fll_error_file_flag_fallback_e, setting.path_pid, f_file_operation_delete_s, fll_error_file_type_file_e);
+ fll_error_file_print(main->warning, F_status_set_fine(status_delete), "controller_file_pid_delete", fll_error_file_flag_fallback_e, process.path_pid, f_file_operation_delete_s, fll_error_file_type_file_e);
}
}
}
- if (status != F_child && setting.path_control.used) {
- f_socket_disconnect(&setting.control.server, f_socket_close_read_write_e);
+ if (status != F_child && process.path_control.used) {
+ f_socket_disconnect(&process.control.server, f_socket_close_read_write_e);
- if (!(setting.control.flag & controller_control_flag_readonly_e)) {
- f_file_remove(setting.path_control);
+ if (!(process.control.flag & controller_control_flag_readonly_e)) {
+ f_file_remove(process.path_control);
}
}
- controller_setting_delete_simple(&setting);
-
- if (status == F_child) {
- return status;
- }
-
return status;
}
#endif // _di_controller_main_
/**
* Execute main program.
*
- * Be sure to call controller_main_delete() after executing this.
- *
- * If main.signal is non-zero, then this blocks and handles the following signals:
+ * If main.program.signal is non-zero, then this blocks and handles the following signals: @todo review and upadate this comment.
* - F_signal_abort
* - F_signal_broken_pipe
* - F_signal_hangup
* - F_signal_termination
*
* @param main
- * The main program data.
- * @param arguments
- * The parameters passed to the process.
- *
- * @return
- * F_okay on success.
- * F_child if this is a child process returning.
- *
- * F_interrupt (with error bit) on receiving a process signal, such as an interrupt signal.
+ * The main program and settings data.
*
- * Status codes (with error bit) are returned on any problem.
+ * This alters main.setting.state.status:
+ * F_okay on success.
+ * F_child if this is a child process returning.
*
- * @see controller_main_delete()
+ * F_interrupt (with error bit) on interrupt signal received.
*/
#ifndef _di_controller_main_
- extern f_status_t controller_main(controller_main_t * const main, const f_console_arguments_t arguments);
+ extern void controller_main(controller_main_t * const main);
#endif // _di_controller_main_
#ifdef __cplusplus
#endif // _di_controller_get_id_group_
#ifndef _di_controller_path_canonical_relative_
- f_status_t controller_path_canonical_relative(const controller_setting_t * const setting, const f_string_static_t source, f_string_dynamic_t * const destination) {
+ f_status_t controller_path_canonical_relative(const controller_process_t * const setting, const f_string_static_t source, f_string_dynamic_t * const destination) {
{
const f_status_t status = fl_path_canonical(source, destination);
#endif // _di_controller_time_seconds_
#ifndef _di_controller_time_sleep_nanoseconds_
- int controller_time_sleep_nanoseconds(controller_main_t * const main, controller_setting_t * const setting, struct timespec time) {
+ int controller_time_sleep_nanoseconds(controller_main_t * const main, controller_process_t * const setting, struct timespec time) {
// When sleep is a second or more, instead wait for terminating signals if interruptible.
if ((setting->flag & controller_setting_flag_interruptible_e) && time.tv_sec) {
* @see fl_path_canonical()
*/
#ifndef _di_controller_path_canonical_relative_
- extern f_status_t controller_path_canonical_relative(const controller_setting_t * const global, const f_string_static_t source, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
+ extern f_status_t controller_path_canonical_relative(const controller_process_t * const global, const f_string_static_t source, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
#endif // _di_controller_path_canonical_relative_
/**
* @see nanosleep()
*/
#ifndef _di_controller_time_sleep_nanoseconds_
- extern int controller_time_sleep_nanoseconds(controller_main_t * const main, controller_setting_t * const setting, struct timespec time) F_attribute_visibility_internal_d;
+ extern int controller_time_sleep_nanoseconds(controller_main_t * const main, controller_process_t * const setting, struct timespec time) F_attribute_visibility_internal_d;
#endif // _di_controller_time_sleep_nanoseconds_
/**
options_process |= controller_process_option_asynchronous_d;
}
- status = controller_rule_process_begin(*global, options_force, alias_rule, controller_entry_action_type_to_rule_action_type(entry_action->type), options_process, is_entry ? controller_process_type_entry_e : controller_process_type_exit_e, stack, *cache);
+ status = controller_rule_process_begin(*global, options_force, alias_rule, controller_entry_action_type_to_rule_action_type(entry_action->type), options_process, is_entry ? controller_data_type_entry_e : controller_data_type_exit_e, stack, *cache);
if (F_status_set_fine(status) == F_memory_not || status == F_child || F_status_set_fine(status) == F_interrupt) {
break;
#endif // _di_controller_lock_read_
#ifndef _di_controller_lock_read_process_
- f_status_t controller_lock_read_process(controller_process_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) {
+ f_status_t controller_lock_read_process(controller_data_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) {
return controller_lock_read_process_type(process->type, thread, lock);
}
#ifndef _di_controller_lock_read_process_type_
f_status_t controller_lock_read_process_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t *lock) {
- return controller_lock_read(type != controller_process_type_exit_e, thread, lock);
+ return controller_lock_read(type != controller_data_type_exit_e, thread, lock);
}
#endif // _di_controller_lock_read_process_type_
#endif // _di_controller_lock_write_
#ifndef _di_controller_lock_write_process_
- f_status_t controller_lock_write_process(controller_process_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) {
+ f_status_t controller_lock_write_process(controller_data_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) {
return controller_lock_write_process_type(process->type, thread, lock);
}
#ifndef _di_controller_lock_write_process_type_
f_status_t controller_lock_write_process_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t *lock) {
- return controller_lock_write(type != controller_process_type_exit_e, thread, lock);
+ return controller_lock_write(type != controller_data_type_exit_e, thread, lock);
}
#endif // _di_controller_lock_write_process_type_
* @see controller_lock_read()
*/
#ifndef _di_controller_lock_read_process_
- extern f_status_t controller_lock_read_process(controller_process_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) F_attribute_visibility_internal_d;
+ extern f_status_t controller_lock_read_process(controller_data_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) F_attribute_visibility_internal_d;
#endif // _di_controller_lock_read_process_
/**
* @see controller_lock_write_process_type()
*/
#ifndef _di_controller_lock_write_process_
- extern f_status_t controller_lock_write_process(controller_process_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) F_attribute_visibility_internal_d;
+ extern f_status_t controller_lock_write_process(controller_data_t * const process, controller_thread_t * const thread, f_thread_lock_t *lock) F_attribute_visibility_internal_d;
#endif // _di_controller_lock_write_process_
/**
data.program.debug.flag |= controller_print_flag_debug_e | controller_print_flag_out_e;
data.program.error.flag |= controller_print_flag_error_e | controller_print_flag_out_e;
- data.program.output.flag |= controller_print_flag_out_e;
data.program.message.flag |= controller_print_flag_message_e | controller_print_flag_out_e;
+ data.program.output.flag |= controller_print_flag_out_e;
data.program.warning.flag |= controller_print_flag_warning_e | controller_print_flag_out_e;
- data.program.error.custom = (void *) &data;
- data.program.debug.custom = (void *) &data;
+
data.program.message.custom = (void *) &data;
data.program.output.custom = (void *) &data;
+ data.program.error.custom = (void *) &data;
data.program.warning.custom = (void *) &data;
+ data.program.debug.custom = (void *) &data;
+
+ data.setting.state.data = (void *) &data;
+
+ data.setting.default_engine = &controller_default_engine_s;
+ data.setting.default_path_setting = &controller_path_settings_s;
+ data.setting.default_path_setting_init = &controller_path_settings_init_s;
+ data.setting.default_path_pid = &controller_path_pid_s;
+ data.setting.default_path_pid_init = &controller_path_pid_init_s;
+ data.setting.default_path_pid_prefix = &controller_path_pid_prefix_s;
+ data.setting.default_path_pid_suffix = &controller_path_pid_suffix_s;
+ data.setting.default_path_socket = &controller_path_socket_s;
+ data.setting.default_path_socket_init = &controller_path_socket_init_s;
+ data.setting.default_path_socket_prefix = &controller_path_socket_prefix_s;
+ data.setting.default_path_socket_suffix = &controller_path_socket_suffix_s;
+
+ data.setting.program_name = &controller_program_name_s;
+ data.setting.program_name_long = &controller_program_name_long_s;
+
+ // When run as "init" by default, provide the default system-level init path.
+ #ifdef _controller_as_init_
+ data.setting.as_init = F_true;
+ #else
+ data.setting.as_init = F_false;
+ #endif // _controller_as_init_
+
+ controller_process_t process = controller_process_t_initialize;
+ data.process = &process;
f_console_parameter_t parameters[] = controller_console_parameter_t_initialize;
data.program.parameters.array = parameters;
data.program.parameters.used = controller_parameter_total_d;
data.program.environment = envp;
+ data.program.pid = getpid();
+
if (f_pipe_input_exists()) {
data.program.pipe = fll_program_data_pipe_input_e;
}
- data.program.pid = getpid();
-
fll_program_standard_set_up(&data.program);
f_file_umask_get(&data.program.umask);
- data.program.default_engine = &controller_default_engine_s;
- data.program.default_path_setting = &controller_path_settings_s;
- data.program.default_path_setting_init = &controller_path_settings_init_s;
- data.program.default_path_pid = &controller_path_pid_s;
- data.program.default_path_pid_init = &controller_path_pid_init_s;
- data.program.default_path_pid_prefix = &controller_path_pid_prefix_s;
- data.program.default_path_pid_suffix = &controller_path_pid_suffix_s;
- data.program.default_path_socket = &controller_path_socket_s;
- data.program.default_path_socket_init = &controller_path_socket_init_s;
- data.program.default_path_socket_prefix = &controller_path_socket_prefix_s;
- data.program.default_path_socket_suffix = &controller_path_socket_suffix_s;
- data.program.program_name = &controller_program_name_s;
- data.program.program_name_long = &controller_program_name_long_s;
+ #ifdef _di_thread_support_
+ {
+ const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp);
- // When run as "init" by default, provide the default system-level init path.
- #ifdef _controller_as_init_
- data.program.as_init = F_true;
+ controller_setting_load(arguments, &data);
+ }
+
+ controller_main(&data);
#else
- data.program.as_init = F_false;
- #endif // _controller_as_init_
+ {
+ f_thread_id_t id_signal;
- {
- const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp);
+ memset(&id_signal, 0, sizeof(f_thread_id_t));
- controller_setting_load(arguments, &data);
- }
+ data.setting.state.status = f_thread_create(0, &id_signal, &controller_thread_signal, (void *) &data);
+
+ if (F_status_is_error(data.setting.state.status)) {
+ controller_print_error(&data.program.error, macro_controller_f(f_thread_create));
+ }
+ else {
+ {
+ const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp);
+
+ controller_setting_load(arguments, &data);
+ }
- controller_main(&data);
+ if (!controller_signal_check(&data)) {
+ controller_main(&data);
+ }
- controller_setting_unload(&data);
+ f_thread_cancel(id_signal);
+ f_thread_join(id_signal, 0);
+ }
+ }
+ #endif // _di_thread_support_
- controller_main_delete(&data.program);
+ controller_main_delete(&data);
fll_program_standard_set_down(&data.program);
#endif
#ifndef _di_controller_print_help_
- f_status_t controller_print_help(controller_setting_t * const setting, const fl_print_t print) {
+ f_status_t controller_print_help(fl_print_t * const print) {
- controller_lock_print(print.to, 0);
+ if (!print || !print->custom) return F_status_set_error(F_output_not);
- fll_program_print_help_header(print, *main->program_name_long, controller_program_version_s);
+ controller_main_t * const main = (controller_main_t *) print->custom;
- fll_program_print_help_option_standard(print.to, context);
+ f_file_stream_lock(print->to);
- f_print_dynamic_raw(f_string_eol_s, print.to);
+ fll_program_print_help_header(print, main->setting.program_name_long, controller_program_version_s);
+
+ fll_program_print_help_option_standard(print);
+
+ f_print_dynamic_raw(f_string_eol_s, print->to);
fll_program_print_help_option(print, controller_short_cgroup_s, controller_long_cgroup_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Specify a custom control group file path, such as '" F_control_group_path_system_prefix_s F_control_group_path_system_default_s "'.");
fll_program_print_help_option(print, controller_short_daemon_s, controller_long_daemon_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Run in daemon only mode (do not process the entry).");
fll_program_print_help_option(print, controller_short_uninterruptible_s, controller_long_uninterruptible_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "Designate that this program cannot be interrupted by a signal.");
fll_program_print_help_option(print, controller_short_validate_s, controller_long_validate_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Validate the settings (entry and rules) without running (does not simulate).");
- f_print_dynamic_raw(f_string_eol_s, print.to);
- f_print_dynamic_raw(f_string_eol_s, print.to);
-
- fll_program_print_help_usage(print, *main->program_name, controller_entry_s);
+ f_print_dynamic_raw(f_string_eol_s, print->to);
- fl_print_format("%r When both the %[%r%r%] parameter and the", print.to, f_string_eol_s, print.set->notable, f_console_symbol_long_normal_s, controller_long_simulate_s, print.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", print.to, print.set->notable, f_console_symbol_long_normal_s, controller_long_validate_s, print.set->notable, f_string_eol_s, f_string_eol_s);
+ fll_program_print_help_usage(print, main->setting.program_name, f_string_empty_s);
- const f_string_static_t interruptable = main->as_init ? controller_long_uninterruptible_s : controller_long_interruptible_s;
+ fl_print_format("%r When both the %[%r%r%] parameter and the", print->to, f_string_eol_s, print->set->notable, f_console_symbol_long_normal_s, controller_long_simulate_s, print->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", print->to, print->set->notable, f_console_symbol_long_normal_s, controller_long_validate_s, print->set->notable, f_string_eol_s, f_string_eol_s);
- fl_print_format(" The default interrupt behavior is to operate as if the %[%r%r%] parameter is passed.%r%r", print.to, print.set->notable, f_console_symbol_long_normal_s, interruptable, print.set->notable, f_string_eol_s, f_string_eol_s);
+ fl_print_format(" The default interrupt behavior is to operate as if the %[%r%r%] parameter is passed.%r%r", print->to, print->set->notable, f_console_symbol_long_normal_s, (main->setting.flag & controller_main_flag_init_e) ? controller_long_uninterruptible_s : controller_long_interruptible_s, print->set->notable, f_string_eol_s, f_string_eol_s);
- fl_print_format(" Specify an empty string for the %[%r%r%] parameter to disable pid file creation for this program.%r", print.to, print.set->notable, f_console_symbol_long_normal_s, controller_long_pid_s, print.set->notable, f_string_eol_s);
+ fl_print_format(" Specify an empty string for the %[%r%r%] parameter to disable pid file creation for this program.%r", print->to, print->set->notable, f_console_symbol_long_normal_s, controller_long_pid_s, print->set->notable, f_string_eol_s);
- controller_unlock_print_flush(print.to, 0);
+ f_file_stream_flush(print->to);
+ f_file_stream_unlock(print->to);
return F_okay;
}
* F_output_not on success, but no printing is performed.
*/
#ifndef _di_controller_print_help_
- extern f_status_t controller_print_help(controller_setting_t * const setting, const fl_print_t print);
+ extern f_status_t controller_print_help(controller_process_t * const setting, const fl_print_t print);
#endif // _di_controller_print_help_
#ifdef __cplusplus
} // extern "C"
if (F_status_is_error_not(status) && global.thread->processs.array[global.thread->processs.used]) {
- controller_process_t *process = global.thread->processs.array[global.thread->processs.used];
+ controller_data_t *process = global.thread->processs.array[global.thread->processs.used];
status = controller_lock_write(is_normal, global.thread, &process->lock);
#ifndef _di_controller_process_prepare_process_type_
f_status_t controller_process_prepare_process_type(const controller_global_t global, const uint8_t type, const uint8_t action, const f_string_static_t alias, f_number_unsigned_t *id) {
- return controller_process_prepare(global, type != controller_process_type_exit_e, action, alias, id);
+ return controller_process_prepare(global, type != controller_data_type_exit_e, action, alias, id);
}
#endif // _di_controller_process_prepare_process_type_
#ifndef _di_controller_process_wait_
- f_status_t controller_process_wait(const controller_global_t global, controller_process_t * const process) {
+ f_status_t controller_process_wait(const controller_global_t global, controller_data_t * const process) {
if (!controller_thread_is_enabled_process(process, global.thread)) {
return F_status_set_error(F_interrupt);
* @see f_thread_condition_wait_timed()
*/
#ifndef _di_controller_process_wait_
- extern f_status_t controller_process_wait(const controller_global_t global, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern f_status_t controller_process_wait(const controller_global_t global, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_process_wait_
#ifdef __cplusplus
#endif // _di_controller_rule_copy_
#ifndef _di_controller_rule_execute_
- f_status_t controller_rule_execute(const controller_global_t global, const uint8_t action, const uint8_t options, controller_process_t * const process) {
+ f_status_t controller_rule_execute(const controller_global_t global, const uint8_t action, const uint8_t options, controller_data_t * const process) {
f_status_t status = F_okay;
f_status_t success = F_false;
// When a "define" from the entry/exit is in the "environment", add it to the exported environments (and overwrite any existing environment variable of the same name).
controller_entry_t *entry = 0;
- if (process->type == controller_process_type_entry_e) {
+ if (process->type == controller_data_type_entry_e) {
entry = &global.setting->entry;
}
- else if (process->type == controller_process_type_exit_e) {
+ else if (process->type == controller_data_type_exit_e) {
entry = &global.setting->exit;
}
else {
controller_entry_t *entry = 0;
- if (process->type == controller_process_type_entry_e) {
+ if (process->type == controller_data_type_entry_e) {
entry = &global.setting->entry;
}
- else if (process->type == controller_process_type_exit_e) {
+ else if (process->type == controller_data_type_exit_e) {
entry = &global.setting->exit;
}
#endif // _di_controller_rule_execute_
#ifndef _di_controller_rule_execute_foreground_
- f_status_t controller_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_process_t * const process) {
+ f_status_t controller_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_data_t * const process) {
f_status_t status = F_okay;
f_status_t status_lock = F_okay;
{
const struct timespec delay = controller_time_milliseconds(controller_thread_simulation_timeout_d);
- if (controller_time_sleep_nanoseconds(main, (controller_setting_t *) process->main_setting, delay) == -1) {
+ if (controller_time_sleep_nanoseconds(main, (controller_process_t *) process->main_setting, delay) == -1) {
status = F_status_set_error(F_interrupt);
}
}
#endif // _di_controller_rule_execute_foreground_
#ifndef _di_controller_rule_execute_pid_with_
- f_status_t controller_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_process_t * const process) {
+ f_status_t controller_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_data_t * const process) {
f_status_t status = F_okay;
f_status_t status_lock = F_okay;
{
const struct timespec delay = controller_time_milliseconds(controller_thread_simulation_timeout_d);
- if (controller_time_sleep_nanoseconds(main, (controller_setting_t *) process->main_setting, delay) == -1) {
+ if (controller_time_sleep_nanoseconds(main, (controller_process_t *) process->main_setting, delay) == -1) {
status = F_status_set_error(F_interrupt);
}
}
#endif // _di_controller_rule_execute_pid_with_
#ifndef _di_controller_rule_execute_rerun_
- int8_t controller_rule_execute_rerun(const uint8_t action, controller_process_t * const process, controller_rule_item_t * const item) {
+ int8_t controller_rule_execute_rerun(const uint8_t action, controller_data_t * const process, controller_rule_item_t * const item) {
const int result = WIFEXITED(process->result) ? WEXITSTATUS(process->result) : 0;
if (rerun_item->delay) {
const struct timespec delay = controller_time_milliseconds(rerun_item->delay);
- if (controller_time_sleep_nanoseconds(main, (controller_setting_t *) process->main_setting, delay) == -1) {
+ if (controller_time_sleep_nanoseconds(main, (controller_process_t *) process->main_setting, delay) == -1) {
return -1;
}
#endif // _di_controller_rule_execute_rerun_
#ifndef _di_controller_rule_expand_
- f_status_t controller_rule_expand(const controller_global_t global, const controller_rule_action_t action, controller_process_t * const process) {
+ f_status_t controller_rule_expand(const controller_global_t global, const controller_rule_action_t action, controller_data_t * const process) {
process->cache.expanded.used = 0;
#endif // _di_controller_rule_expand_
#ifndef _di_controller_rule_expand_iki_
- f_status_t controller_rule_expand_iki(controller_process_t * const process, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination) {
+ f_status_t controller_rule_expand_iki(controller_data_t * const process, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination) {
if (vocabulary.start > vocabulary.stop) return F_okay;
if (content.start > content.stop) return F_okay;
} // for
if (i == process->rule.define.used) {
- controller_entry_t * const entry = process->type == controller_process_type_entry_e ? &((controller_setting_t *) process->main_setting)->entry : &((controller_setting_t *) process->main_setting)->exit;
+ controller_entry_t * const entry = process->type == controller_data_type_entry_e ? &((controller_process_t *) process->main_setting)->entry : &((controller_process_t *) process->main_setting)->exit;
for (i = 0; i < entry->define.used; ++i) {
} // for
if (i == process->rule.parameter.used) {
- controller_entry_t * const entry = process->type == controller_process_type_entry_e ? &((controller_setting_t *) process->main_setting)->entry : &((controller_setting_t *) process->main_setting)->exit;
+ controller_entry_t * const entry = process->type == controller_data_type_entry_e ? &((controller_process_t *) process->main_setting)->entry : &((controller_process_t *) process->main_setting)->exit;
for (i = 0; i < entry->parameter.used; ++i) {
#endif // _di_controller_rule_items_increase_by_
#ifndef _di_controller_rule_process_
- f_status_t controller_rule_process(const controller_global_t global, controller_process_t * const process) {
+ f_status_t controller_rule_process(const controller_global_t global, controller_data_t * const process) {
switch (process->action) {
case controller_rule_action_type_freeze_e:
bool found = F_false;
- controller_process_t *dependency = 0;
+ controller_data_t *dependency = 0;
uint8_t options_process = 0;
f_status_t status = F_okay;
f_status_t status_lock = F_okay;
- controller_process_t *process = 0;
+ controller_data_t *process = 0;
status = controller_lock_read_process_type(type, global.thread, &global.thread->lock.process);
{
f_number_unsigned_t at = 0;
- status = controller_process_prepare(global, type != controller_process_type_exit_e, action, alias_rule, &at);
+ status = controller_process_prepare(global, type != controller_data_type_exit_e, action, alias_rule, &at);
if (F_status_is_error(status)) {
f_thread_unlock(&global.thread->lock.process);
if (F_status_is_error_not(status)) {
if (process->action && (options_force & controller_process_option_asynchronous_d)) {
- if (process->type == controller_process_type_exit_e) {
+ if (process->type == controller_data_type_exit_e) {
status = f_thread_create(0, &process->id_thread, controller_thread_process_other, (void *) process);
}
else {
#endif // _di_controller_rule_process_begin_
#ifndef _di_controller_rule_process_do_
- f_status_t controller_rule_process_do(const uint8_t options_force, controller_process_t * const process) {
+ f_status_t controller_rule_process_do(const uint8_t options_force, controller_data_t * const process) {
f_status_t status_lock = F_okay;
- controller_global_t global = macro_controller_global_t_initialize_1((controller_main_t *) process->main_data, (controller_setting_t *) process->main_setting, (controller_thread_t *) process->main_thread);
+ controller_global_t global = macro_controller_global_t_initialize_1((controller_main_t *) process->main_data, (controller_process_t *) process->main_setting, (controller_thread_t *) process->main_thread);
// The process and active locks shall be held for the duration of this processing (aside from switching between read to/from write).
if (options_force & controller_process_option_asynchronous_d) {
#endif // _di_controller_rule_read_
#ifndef _di_controller_rule_setting_read_
- f_status_t controller_rule_setting_read(const controller_global_t global, const bool is_normal, const controller_setting_t setting, controller_cache_t * const cache, controller_rule_t * const rule) {
+ f_status_t controller_rule_setting_read(const controller_global_t global, const bool is_normal, const controller_process_t setting, controller_cache_t * const cache, controller_rule_t * const rule) {
f_status_t status = F_okay;
f_status_t status_return = F_okay;
// Vuild a list of what to wait for so that anything new after this point will not be waited for.
const f_number_unsigned_t process_total = global.thread->processs.used;
- controller_process_t *process_list[process_total];
+ controller_data_t *process_list[process_total];
for (; i < process_total; ++i) {
process_list[i] = global.thread->processs.array[i];
#ifndef _di_controller_rule_wait_all_process_type_
f_status_t controller_rule_wait_all_process_type(const controller_global_t global, const uint8_t type, const bool required) {
- return controller_rule_wait_all(global, type != controller_process_type_exit_e, required);
+ return controller_rule_wait_all(global, type != controller_data_type_exit_e, required);
}
#endif // _di_controller_rule_wait_all_process_type_
* On failure, the individual status for the rule is set to an appropriate error status.
*/
#ifndef _di_controller_rule_execute_
- extern f_status_t controller_rule_execute(const controller_global_t global, const uint8_t action, const uint8_t options, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_execute(const controller_global_t global, const uint8_t action, const uint8_t options, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_execute_
/**
* @see fll_execute_program()
*/
#ifndef _di_controller_rule_execute_foreground_
- extern f_status_t controller_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_execute_foreground_
/**
* @see fll_execute_program()
*/
#ifndef _di_controller_rule_execute_pid_with_
- extern f_status_t controller_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_execute_pid_with_
/**
* -2 to designate exit due to signal/disabled thread.
*/
#ifndef _di_controller_rule_execute_rerun_
- extern int8_t controller_rule_execute_rerun(const uint8_t action, controller_process_t * const process, controller_rule_item_t * const item) F_attribute_visibility_internal_d;
+ extern int8_t controller_rule_execute_rerun(const uint8_t action, controller_data_t * const process, controller_rule_item_t * const item) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_execute_rerun_
/**
* @see controller_rule_expand_iki()
*/
#ifndef _di_controller_rule_expand_
- extern f_status_t controller_rule_expand(const controller_global_t global, const controller_rule_action_t action, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_expand(const controller_global_t global, const controller_rule_action_t action, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_expand_
/**
* @see f_string_dynamic_append()
*/
#ifndef _di_controller_rule_expand_iki_
- extern f_status_t controller_rule_expand_iki(controller_process_t * const process, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_expand_iki(controller_data_t * const process, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_expand_iki_
/**
* Errors (with error bit) from: controller_lock_write().
*/
#ifndef _di_controller_rule_process_
- extern f_status_t controller_rule_process(const controller_global_t global, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_process(const controller_global_t global, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_process_
/**
* @param options
* The process options to pass to the process.
* @param type
- * The process type, such as controller_process_type_entry_e.
+ * The process type, such as controller_data_type_entry_e.
* @param stack
* A stack representing the processes already running in this rule process dependency tree.
* This is used to prevent circular dependencies.
* @see controller_rule_process_begin()
*/
#ifndef _di_controller_rule_process_do_
- extern f_status_t controller_rule_process_do(const uint8_t options_force, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_process_do(const uint8_t options_force, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_process_do_
/**
* @see controller_path_canonical_relative()
*/
#ifndef _di_controller_rule_setting_read_
- extern f_status_t controller_rule_setting_read(const controller_global_t global, const bool is_normal, const controller_setting_t setting, controller_cache_t * const cache, controller_rule_t * const rule) F_attribute_visibility_internal_d;
+ extern f_status_t controller_rule_setting_read(const controller_global_t global, const bool is_normal, const controller_process_t setting, controller_cache_t * const cache, controller_rule_t * const rule) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_setting_read_
/**
#endif // _di_controller_rule_item_print_error_
#ifndef _di_controller_rule_item_print_error_execute_
- void controller_rule_item_print_error_execute(const bool script_is, const f_string_static_t name, const f_status_t status, controller_process_t * const process) {
+ void controller_rule_item_print_error_execute(const bool script_is, const f_string_static_t name, const f_status_t status, controller_data_t * const process) {
if (((controller_main_t *) process->main_data)->error.verbosity != f_console_verbosity_quiet_e) {
fl_print_t * const print = &((controller_main_t *) process->main_data)->error;
* The process to use.
*/
#ifndef _di_controller_rule_item_print_error_execute_
- extern void controller_rule_item_print_error_execute(const bool script_is, const f_string_static_t name, const f_status_t status, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern void controller_rule_item_print_error_execute(const bool script_is, const f_string_static_t name, const f_status_t status, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_rule_item_print_error_execute_
/**
if (global->thread->enabled != controller_thread_enabled_e) break;
if (f_thread_lock_write_try(&global->thread->lock.process) == F_okay) {
- controller_process_t *process = 0;
+ controller_data_t *process = 0;
f_number_unsigned_t i = 0;
#endif // _di_controller_thread_is_enabled_
#ifndef _di_controller_thread_is_enabled_process_
- f_status_t controller_thread_is_enabled_process(controller_process_t * const process, controller_thread_t * const thread) {
+ f_status_t controller_thread_is_enabled_process(controller_data_t * const process, controller_thread_t * const thread) {
return controller_thread_is_enabled_process_type(process->type, thread);
}
#ifndef _di_controller_thread_is_enabled_process_type_
f_status_t controller_thread_is_enabled_process_type(const uint8_t type, controller_thread_t * const thread) {
- return controller_thread_is_enabled(type != controller_process_type_exit_e, thread);
+ return controller_thread_is_enabled(type != controller_data_type_exit_e, thread);
}
#endif // _di_controller_thread_is_enabled_process_type_
#ifndef _di_controller_thread_main_
- f_status_t controller_thread_main(controller_main_t * const main, controller_setting_t * const setting) {
+ f_status_t controller_thread_main(controller_main_t * const main, controller_process_t * const setting) {
f_status_t status = F_okay;
* @see controller_thread_is_enabled_process_type()
*/
#ifndef _di_controller_thread_is_enabled_process_
- extern f_status_t controller_thread_is_enabled_process(controller_process_t * const process, controller_thread_t * const thread) F_attribute_visibility_internal_d;
+ extern f_status_t controller_thread_is_enabled_process(controller_data_t * const process, controller_thread_t * const thread) F_attribute_visibility_internal_d;
#endif // _di_controller_thread_is_enabled_process_
/**
* F_interrupt (with error bit) on receiving a process signal, such as an interrupt signal.
*/
#ifndef _di_controller_thread_main_
- extern f_status_t controller_thread_main(controller_main_t * const main, controller_setting_t * const setting) F_attribute_visibility_internal_d;
+ extern f_status_t controller_thread_main(controller_main_t * const main, controller_process_t * const setting) F_attribute_visibility_internal_d;
#endif // _di_controller_thread_main_
/***
// It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below.
// Deallocate as much as possible.
controller_thread_delete_simple(global->thread);
- controller_setting_delete_simple(global->setting);
+ controller_process_delete(global->setting);
controller_main_delete(global->main);
}
// It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below.
// Deallocate as much as possible.
controller_thread_delete_simple(entry->global->thread);
- controller_setting_delete_simple(entry->global->setting);
+ controller_process_delete(entry->global->setting);
controller_main_delete(entry->global->main);
// According to the manpages, pthread_exit() calls exit(0), which is not good because a non-zero exit code may be returned.
// It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below.
// Deallocate as much as possible.
controller_thread_delete_simple(entry->global->thread);
- controller_setting_delete_simple(entry->global->setting);
+ controller_process_delete(entry->global->setting);
controller_main_delete(entry->global->main);
return 0;
#endif
#ifndef _di_controller_thread_process_
- void controller_thread_process(const bool is_normal, controller_process_t * const process) {
+ void controller_thread_process(const bool is_normal, controller_data_t * const process) {
{
controller_thread_t *thread = (controller_thread_t *) process->main_thread;
// It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below.
// Deallocate as much as possible.
controller_main_t *main = (controller_main_t *) process->main_data;
- controller_setting_t *setting = (controller_setting_t *) process->main_setting;
+ controller_process_t *setting = (controller_process_t *) process->main_setting;
controller_thread_t *thread = (controller_thread_t *) process->main_thread;
controller_thread_delete_simple(thread);
- controller_setting_delete_simple(setting);
+ controller_process_delete(setting);
controller_main_delete(main);
// According to the manpages, pthread_exit() calls exit(0), which is not good because a non-zero exit code may be returned.
struct timespec time;
controller_entry_t *entry = 0;
- controller_process_t *process = 0;
+ controller_data_t *process = 0;
f_status_t status = F_okay;
f_number_unsigned_t i = 0;
process = global.thread->processs.array[i];
// Do not cancel exit processes, when not performing "execute" during exit.
- if (process->type == controller_process_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) {
+ if (process->type == controller_data_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) {
continue;
}
process = global.thread->processs.array[i];
// Do not wait for processes, when not performing "execute" during exit.
- if (process->type == controller_process_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) {
+ if (process->type == controller_data_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) {
continue;
}
process = global.thread->processs.array[i];
// Do not kill exit processes, when not performing "execute" during exit.
- if (process->type == controller_process_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) continue;
+ if (process->type == controller_data_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) continue;
if (process->id_thread) {
if (process->childs.used) {
for (j = 0; j < process->childs.size; ++j) {
// Do not kill exit processes, when not performing "execute" during exit.
- if (process->type == controller_process_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) continue;
+ if (process->type == controller_data_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) continue;
if (process->childs.array[j]) {
for (j = 0; j < process->path_pids.used; ++j) {
// Do not kill exit processes, when not performing "execute" during exit.
- if (process->type == controller_process_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) continue;
+ if (process->type == controller_data_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) continue;
if (f_file_exists(process->path_pids.array[j], F_true) == F_true) {
status = controller_file_pid_read(process->path_pids.array[j], &pid);
while (process->childs.used) {
// Do not shrink below an exit processes, when not performing "execute" during exit.
- if (process->type == controller_process_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) break;
+ if (process->type == controller_data_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) break;
if (process->childs.array[j] > 0) break;
--process->childs.used;
while (process->path_pids.used) {
// Do not shrink below an exit processes, when not performing "execute" during exit.
- if (process->type == controller_process_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) break;
+ if (process->type == controller_data_type_exit_e && global.thread->enabled != controller_thread_enabled_exit_execute_e) break;
if (process->path_pids.array[j].used) break;
--process->path_pids.used;
f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0);
- controller_thread_process(F_true, (controller_process_t *) arguments);
+ controller_thread_process(F_true, (controller_data_t *) arguments);
return 0;
}
f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0);
- controller_thread_process(F_false, (controller_process_t *) arguments);
+ controller_thread_process(F_false, (controller_data_t *) arguments);
return 0;
}
* @see controller_rule_process_do()
*/
#ifndef _di_controller_thread_process_
- extern void controller_thread_process(const bool is_normal, controller_process_t * const process) F_attribute_visibility_internal_d;
+ extern void controller_thread_process(const bool is_normal, controller_data_t * const process) F_attribute_visibility_internal_d;
#endif // _di_controller_thread_process_
/**
*
* @param arguments
* The thread arguments.
- * Must be of type controller_process_t.
+ * Must be of type controller_data_t.
*
* @return
* 0, always.
*
* @param arguments
* The thread arguments.
- * Must be of type controller_process_t.
+ * Must be of type controller_data_t.
*
* @return
* 0, always.