From 88642d50923e08b38d66a9019ba1b88a0a4c1ed3 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 4 Nov 2020 20:22:19 -0600 Subject: [PATCH] Update: Re-create Init program with barebones source structure. The Init program will instead be developed as an init-only program. The goal will be to not implement any service management. This means that another progrram will be written for that purpose (which will be called something like "control" and/or "controller"). --- level_3/init/c/init.c | 171 +----- level_3/init/c/init.h | 254 ++------- level_3/init/c/private-init.c | 623 --------------------- level_3/init/c/private-init.h | 358 +----------- level_3/init/data/build/dependencies | 8 +- level_3/init/data/build/settings | 2 +- level_3/init/data/settings/core.rule | 46 -- level_3/init/data/settings/rules/boot/devices.rule | 14 - .../init/data/settings/rules/boot/filesystem.rule | 52 -- level_3/init/data/settings/rules/boot/modules.rule | 88 --- level_3/init/data/settings/rules/net/all.rule | 9 - level_3/init/data/settings/rules/net/loopback.rule | 14 - .../init/data/settings/rules/program/terminal.rule | 21 - .../init/data/settings/rules/service/clock.rule | 23 - level_3/init/data/settings/rules/target/dbus.rule | 8 - .../init/data/settings/rules/target/logger.rule | 9 - level_3/init/data/settings/rules/target/mouse.rule | 12 - 17 files changed, 75 insertions(+), 1637 deletions(-) delete mode 100644 level_3/init/data/settings/core.rule delete mode 100644 level_3/init/data/settings/rules/boot/devices.rule delete mode 100644 level_3/init/data/settings/rules/boot/filesystem.rule delete mode 100644 level_3/init/data/settings/rules/boot/modules.rule delete mode 100644 level_3/init/data/settings/rules/net/all.rule delete mode 100644 level_3/init/data/settings/rules/net/loopback.rule delete mode 100644 level_3/init/data/settings/rules/program/terminal.rule delete mode 100644 level_3/init/data/settings/rules/service/clock.rule delete mode 100644 level_3/init/data/settings/rules/target/dbus.rule delete mode 100644 level_3/init/data/settings/rules/target/logger.rule delete mode 100644 level_3/init/data/settings/rules/target/mouse.rule diff --git a/level_3/init/c/init.c b/level_3/init/c/init.c index 5c2a352..ded62b4 100644 --- a/level_3/init/c/init.c +++ b/level_3/init/c/init.c @@ -1,12 +1,3 @@ -/** - * FLL - Level 3 - * - * Project: Init - * API Version: 0.5 - * Licenses: lgplv2.1 - * - * This is the FLL Init program. - */ #include "init.h" #include "private-init.h" @@ -29,11 +20,6 @@ extern "C" { fll_program_print_help_option(output, context, f_console_standard_short_debug, f_console_standard_long_debug, f_console_symbol_short_disable, f_console_symbol_long_disable, " Enable debugging, inceasing verbosity beyond normal output."); fll_program_print_help_option(output, context, f_console_standard_short_version, f_console_standard_long_version, f_console_symbol_short_disable, f_console_symbol_long_disable, " Print only the version number."); - fprintf(output.stream, "%c", f_string_eol[0]); - - fll_program_print_help_option(output, context, init_parameter_no_prepare_short_name, init_parameter_no_prepare_long_name, f_console_symbol_short_enable, f_console_symbol_long_enable, " Do not attempt to process kernel command line or perform any boot-time specific preparations."); - fll_program_print_help_option(output, context, init_parameter_runlevel_short_name, init_parameter_runlevel_long_name, f_console_symbol_short_enable, f_console_symbol_long_enable, " Specify a custom run level, ignoring the kernel command line runlevel argument."); - fll_program_print_help_usage(output, context, init_name, ""); return F_none; @@ -42,13 +28,7 @@ extern "C" { #ifndef _di_init_main_ f_return_status init_main(const f_console_arguments_t arguments, init_data_t *data) { - f_status_t status = F_none; - int8_t run_level[init_kernel_runlevel_buffer]; - - memset(run_level, 0, init_kernel_runlevel_buffer); - - unsigned short do_socket_file = F_true; - unsigned short do_socket_port = F_false; + f_status_t status = F_none; { const f_console_parameters_t parameters = f_macro_console_parameters_t_initialize(data->parameters, init_total_parameters); @@ -63,7 +43,12 @@ extern "C" { data->error.notable = data->context.set.notable; if (F_status_is_error(status)) { - // @todo: init_delete_data(data); + if (data->error.verbosity != f_console_verbosity_quiet) { + fll_error_print(data->error, F_status_set_fine(status), "fll_program_parameter_process", F_true); + fprintf(data->error.to.stream, "%c", f_string_eol[0]); + } + + init_delete_data(data); return F_status_set_error(status); } } @@ -112,138 +97,36 @@ extern "C" { return F_none; } - if (data->parameters[init_parameter_runlevel].result == f_console_result_found) { - const unsigned int parameter_length = strlen(arguments.argv[data->parameters[init_parameter_runlevel].values.array[0]]); + // @todo - // if the run_level value is greater than the static buffer size, ignore the entire string rather than process a cut off value. - if (parameter_length > 0 && parameter_length < init_kernel_runlevel_buffer) { - strncpy((char *) &run_level, arguments.argv[data->parameters[init_parameter_runlevel].values.array[0]], parameter_length); + // ensure a newline is always put at the end of the program execution, unless in quiet mode. + if (data->error.verbosity != f_console_verbosity_quiet) { + if (F_status_is_error(status)) { + fprintf(data->error.to.stream, "%c", f_string_eol[0]); } } + init_delete_data(data); + return status; + } +#endif // _di_init_main_ - // before doing anything make sure that the rootfs has been properly setup. - if (data->parameters[init_parameter_no_prepare].result == f_console_result_none) { - //init_prepare_system(&run_level); - } - - // make sure appropriate required directories exist. - //init_prepare_init(); - - - // attempt to load the main rule before forking and starting child processes. - { - // @todo: should this pre-scan the main rule file to see if there is a custom chroot command, if so, change behavior to process rules and then chroot into a new system (cleaning up resources as much as possible before doing chroot) (don't fork child processes?)? - // 1) check the last object for a chroot command in reverse order. - // - if the chroot fails then additional rules may apply. the chroot command does not have to be the last command. - // 2) if chroot is not specified, then continue onto code below. - // 3) if chroot is specified, then execute rules directly and exit this process on success (via chroot command). - // 4) if chroot is specified, but chroot fails, then continue processing rules and then exit this process (dropping to bash shell). - // effectively use my initrd_init and pre_init code here. - - // @todo: init_process_main_rule(); - } - - - // commented out code is an alternative method to avoid using malloc for stacks passed to clone. - //f_char stack_services[init_stack_size_small_services]; - //f_char stack_control_file[init_stack_size_small_control_file]; - init_stack_memory stack_memory = init_stack_memory_initialize; - - //status = init_initialize_stack_memory(&stack_memory); - if (F_status_is_error(status)) { - // @todo: init_delete_data((*data)); - // @todo: init_delete_stack_memory(&stack_memory); - return status; - } - - { - /* - pid_t pid_services = clone(init_handler_child_services, stack_memory.services + init_stack_size_small_services, init_flags_clone, stack_memory.services); - - if (pid_services < 0) { - fl_color_print(data->error.to.stream, data->context.set.error, "%sFailed to clone services process (errno = %i).%c", fll_error_print_error, errno, f_string_eol[0]); - } - - pid_t pid_control_file = clone(init_handler_child_control_file, stack_memory.control_file + init_stack_size_control_file, init_flags_clone, stack_memory.control_file); - - if (pid_control_file < 0) { - fl_color_print(data->error.to.stream, data->context.set.error, "%sFailed to clone control via file process (errno = %i).%c", fll_error_print_error, errno, f_string_eol[0]); - } - */ - - // block signals - sigset_t signal_mask; - siginfo_t signal_information; - - memset(&signal_mask, 0, sizeof(sigset_t)); - memset(&signal_information, 0, sizeof(siginfo_t)); - - // block all signals. - sigfillset(&signal_mask); - sigprocmask(SIG_BLOCK, &signal_mask, 0); - - int signal_problem_count = 0; - const int problem_count_max_signal_size = 10; - - // sit and wait for signals. - for (;;) { - int signal_result = sigwaitinfo(&signal_mask, &signal_information); - - if (signal_result < 0) { - if (errno == EAGAIN) { - // do nothing. - continue; - } - else if (errno != EINTR) { - fl_color_print(data->error.to.stream, data->context.set.error, "%ssigwaitinfo() failed (errno = %i).%c", fll_error_print_error, errno, f_string_eol[0]); - - signal_problem_count++; - if (signal_problem_count > problem_count_max_signal_size) { - fl_color_print(data->error.to.stream, data->context.set.error, "%sMax signal problem count has been reached, sleeping for a period of time.%c", fll_error_print_error, errno, f_string_eol[0]); - sleep(init_panic_signal_sleep_seconds); - signal_problem_count = 0; - } - - continue; - } - } +#ifndef _di_init_delete_data_ + f_return_status init_delete_data(init_data_t *data) { - signal_problem_count = 0; + for (f_string_length_t i = 0; i < init_total_parameters; i++) { + f_macro_string_lengths_t_delete_simple(data->parameters[i].locations); + f_macro_string_lengths_t_delete_simple(data->parameters[i].locations_sub); + f_macro_string_lengths_t_delete_simple(data->parameters[i].values); + } // for - if (signal_information.si_signo == SIGHUP) { - // @todo: close all child process connections? try using small initial memory instead? - } - else if (signal_information.si_signo == SIGINT) { - // check the status of processes to see if they are still running, if not, then restart them. - } - else if (signal_information.si_signo == SIGQUIT || signal_information.si_signo == SIGTERM) { - // @todo: block these or attempt to respawn init process? try using small initial memory instead? - break; - } - else if (signal_information.si_signo == SIGSEGV || signal_information.si_signo == SIGBUS || signal_information.si_signo == SIGILL || signal_information.si_signo == SIGFPE) { - // @todo: block these or attempt to respawn init process? - } - else if (signal_information.si_signo == SIGPWR) { - // @todo: shutdown process? - } - else if (signal_information.si_signo == SIGABRT || signal_information.si_signo == SIGIOT || signal_information.si_signo == SIGXCPU) { - // do nothing. - } - else if (signal_information.si_signo == SIGCHLD) { - // @todo: restart child processes? try using large initial memory instead? - } + f_macro_string_lengths_t_delete_simple(data->remaining); - memset(&signal_information, 0, sizeof(siginfo_t)); - continue; - } // for - } + f_macro_color_context_t_delete_simple(data->context); - // @todo: init_delete_data((*data)); - // @todo: init_delete_stack_memory(&stack_memory); - return status; + return F_none; } -#endif // _di_init_main_ +#endif // _di_init_delete_data_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/init/c/init.h b/level_3/init/c/init.h index 51fceb3..2742d4d 100644 --- a/level_3/init/c/init.h +++ b/level_3/init/c/init.h @@ -1,62 +1,24 @@ -/* FLL - Level 3 - * Project: Firewall - * Version: 0.1.0 - * Licenses: lgplv2.1 - * Programmers: Kevin Day - * Documentation: - * - * This is the Kevux Operating System Init program. - * This program utilizes the Featureless Linux Library. - * - * This init program is designed to run with certain paths and if they do not exist, it will attempt to create them. - * This expects the Kevux path permissions structure and naming, so a valid /etc/group file should exist. - * - * This is designed to have different threads handling the following actions: - * Thread Group 1 (Signals and Control) - * - (parent process) handles/blocks all signals for init program and handles children accordingly. - * - runs as root. - * - * Thread Group 2 (Services) - * - Handles starting and stopping of individual services. - * - New thread created for each user. - * - Runs as root. - * - Each individual thread runs as a specified user. +/** + * FLL - Level 3 * - * Thread Group 3 (Reporting and Output) - * - Handles output to the terminal or any other supported devices. - * - No child threads. - * - Runs as init user. + * Project: Init + * API Version: 0.5 + * Licenses: lgplv2.1 * - * Thread Group 4 (Commands: Socket File) - * - If socket file is enabled, then this thread is created to listen on the socket file and process received commands. - * - No child threads. - * - Runs as init user. + * This is the Init program. * - * Thread Group 5 (Commands: Socket Port) - * - If socket port is enabled, then this thread is created to listen on the socket port and process received commands. - * - No child threads. - * - Runs as init user. + * This program utilizes the Featureless Linux Library. + * This program performs the basic system boot operations. * - * It would be nice to be able to start the init program as a non-root user who has elevated privileges similar to root. - * - That is, have ability to su to any user (except root). - * - While this will still be a security concern, not running as root will significantly reduce the potential problems. - * - This design would not allow for root-specific cron jobs. + * This program does the following: + * 1) perform all initial filesystem setup tasks (creating directories, mounting, setting permissions, populated device files, etc..). + * 2) finding the desired/wanted boot partition, mounting it (and any other mount points). + * 3) booting into target partition using a given target program (controller, bash, etc..). + * 4) falling back into a failsafe environment on error (such as bash). */ #ifndef _init_h -#define _GNU_SOURCE - // libc includes -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // fll-0 includes #include @@ -67,23 +29,16 @@ #include #include #include -#include #include #include // fll-1 includes #include #include -#include -#include -#include #include // fll-2 includes #include -#include -#include -#include #include #ifdef __cplusplus @@ -93,86 +48,16 @@ extern "C" { #ifndef _di_init_version_ #define init_major_version "0" #define init_minor_version "5" - #define init_micro_version "1" + #define init_micro_version "2" #define init_version init_major_version "." init_minor_version "." init_micro_version #endif // _di_init_version_ #ifndef _di_init_name_ #define init_name "init" - #define init_name_long "Kevux Init Program" + #define init_name_long "Init Program" #endif // _di_init_name_ -#ifndef _di_init_default_allocation_step_ - #define init_default_allocation_step f_memory_default_allocation_step -#endif // _di_init_default_allocation_step_ - -#ifndef _di_init_paths_ - // @todo: this will eventually be written to use the f_path project. - #define init_paths_rootfs "/" - #define init_paths_devices "/dev/" - #define init_paths_devices_pts "/dev/pts/" - #define init_paths_system "/sys/" - #define init_paths_processes "/proc/" - #define init_paths_temporary "/tmp/" - #define init_paths_mount "/mnt/" - #define init_paths_run "/run/" - #define init_paths_init_run "/run/init/" - #define init_paths_init_settings "/etc/init/" - #define init_paths_init_socket "/run/init/socket/" - #define init_paths_init_process "/run/init/process/" - #define init_paths_init_log "/log/init/" - #define init_paths_init_log "/tmp/init/" - #define init_paths_log "/log/" -#endif // _di_init_paths_ - -#ifndef _di_init_extension_ - #define init_extension_settings "settings" - #define init_extension_rule "rule" - #define init_extension_socket "socket" - #define init_extension_process "pid" -#endif // _di_init_extension_ - -#ifndef _di_init_settings_ - #define init_rule_core "main" - #define init_rule_core_file init_paths_init_settings init_rule_core "." init_extension_rule - - #define init_kernel_command_line init_paths_processes "cmdline" - #define init_kernel_runlevel "\\used); - - status = fll_fss_basic_list_read(buffer, &input, objects, contents, &delimits, 0); - } - - if (F_status_is_error(status)) { - status = F_status_set_fine(status); - - if (status == F_parameter) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sInvalid parameter when calling fll_fss_basic_list_read() for the file '%s'.%c", fll_error_print_error, filename, f_string_eol[0]); - } else if (status == F_data_not_eos || status == F_data_not || status == F_data_not_stop) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sNo relevant data was found within the file '%s'.%c", fll_error_print_error, filename, f_string_eol[0]); - } else if (status == F_memory_allocation || status == F_memory_reallocation) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sUnable to allocate memory.%c", fll_error_print_error, f_string_eol[0]); - } else { - fl_color_print(data.error.to.stream, data.context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_fss_basic_list_read() for the file '%s'.%c", fll_error_print_error, status, filename, f_string_eol[0]); - } - - f_macro_fss_delimits_t_delete_simple(delimits); - - return F_status_set_error(status); - } - else { - *status = fl_fss_apply_delimit(delimits, &buffer); - - if (F_status_is_error(*status)) { - fll_error_print(data.error, F_status_set_fine(*status), "fl_fss_apply_delimit", F_true); - } - } - - f_macro_fss_delimits_t_delete_simple(delimits); - - return status; - } -#endif // _di_init_rule_buffer_ - -#ifndef _di_init_rules_process_main_ - f_return_status init_rules_process_main(const init_data_t data, const f_string_t filename, f_string_dynamic_t *buffer, f_fss_objects_t *objects, f_fss_contents_t *contents) { - f_status_t status = F_none; - f_fss_delimits_t delimits = f_fss_delimits_t_initialize; - - // @todo: resume replacing code below. - status = fll_fss_extended_read(&buffer, input, &local->rule_objects, &local->rule_contents, 0, 0, &delimits, 0); - - if (F_status_is_error_not(*status)) { - status = fl_fss_apply_delimit(delimits, &buffer); - } - - f_macro_fss_delimits_t_delete_simple(delimits); - - if (F_status_is_error_not(status)) { - //status = init_perform_commands(*local, *data); // @fixme - - if (F_status_is_error(status)) { - if (F_status_set_fine(status) == F_memory_allocation || F_status_set_fine(status) == F_memory_reallocation) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sUnable to allocate memory.", fll_error_print_error); - } else if (F_status_set_fine(status) == F_failure) { - // the error message has already been displayed. - } else { - fl_color_print(data.error.to.stream, data.context.set.error, "%sAn unhandled error (%u) has occurred while calling firewall_perform_commands().", fll_error_print_error, status); - } - } - } - - f_macro_fss_objects_t_delete_simple(local->rule_objects); - f_macro_fss_contents_t_delete_simple(local->rule_contents); - return status; - } -#endif // _init_rules_process_main_ - -#ifndef _di_init_handler_child_services_ - f_return_status init_handler_child_services(void *data) { - init_local_data *local_data = (init_local_data *) data; - - // load and process rules. - - return F_none; - } -#endif // _di_init_handler_child_services_ - -#ifndef _di_init_handler_child_control_file_ - f_return_status init_handler_child_control_file(void *data) { - init_local_data *local_data = (init_local_data *) data; - - return F_none; - } -#endif // _di_init_handler_child_control_file_ - -#ifndef _di_init_initialize_stack_memory_ - f_return_status init_initialize_stack_memory(init_stack_memory *stack_memory) { - stack_memory->services = mmap(0, init_stack_size_small_services, init_stack_protections, init_stack_flags, -1, 0); - stack_memory->control_file = mmap(0, init_stack_size_small_control_file, init_stack_protections, init_stack_flags, -1, 0); - - if (stack_memory->services == (void *) -1) { - return F_failure; - } - - if (stack_memory->control_file == (void *) -1) { - return F_failure; - } - - return F_none; - } -#endif // _di_init_initialize_stack_memory_ - -#ifndef _di_init_delete_stack_memory_ - f_return_status init_delete_stack_memory(init_stack_memory *stack_memory) { - f_status_t status = F_none; - - if (stack_memory->services > 0) { - if (munmap(stack_memory->services, 0) >= 0) { - stack_memory->services = 0; - } - else { - status = F_failure; - } - } - - if (stack_memory->control_file > 0) { - if (munmap(stack_memory->control_file, 0) >= 0) { - stack_memory->control_file = 0; - } - else { - status = F_failure; - } - } - - return status; - } -#endif // _di_init_delete_stack_memory_ - -#ifndef _di_init_prepare_system_ - f_return_status init_prepare_system(int8_t *run_level) { - f_status_t status = F_none; - f_stat stat; - - memset(&stat, 0, sizeof(f_stat)); - - - // create the required directories if they do not already exist and then perform appropriate mount. - status = f_file_stat(init_paths_devices, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_devices); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " init_paths_devices); - - status = f_file_stat(init_paths_system, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_system); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " -p " init_paths_system); - - status = f_file_stat(init_paths_devices_pts, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_devices_pts); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " -t " init_paths_devices_pts); - - status = f_file_stat(init_paths_log, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_log); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " init_paths_log); - - status = f_file_stat(var_run_path, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " var_run_path); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " var_run_path); - - status = f_file_stat(mnt_path, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " mnt_path); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " mnt_path); - - status = f_file_stat(tmp_path, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " tmp_path); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " tmp_path); - - status = f_file_stat(init_paths_processes, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_processes); - memset(&stat, 0, sizeof(f_stat)); - } - - // Look for the kernel command line to determine whether or not the proc is mounted. - // doing this also allows for unusual circumstances where the kernel command line is not mounted but a custom kernel command line is statically provided. - status = f_file_stat(init_kernel_command_line, &stat); - - if (status == F_file_found_not) { - system(init_program_mount " " init_paths_processes); - } - - - // create the required devices - system(init_program_mknod " -m 0660 " init_path_device_null " c 1 3"); - system(init_program_mknod " -m 0660 " init_path_device_zero " c 1 5"); - system(init_program_mknod " -m 0660 " init_path_device_console " c 5 1"); - system(init_program_mknod " -m 0440 " init_path_device_random " c 1 8"); - system(init_program_mknod " -m 0440 " init_path_device_urandom " c 1 9"); - system(init_program_chgrp " " init_group_process_null " " init_path_device_null); - system(init_program_chgrp " " init_group_process_zero " " init_path_device_zero); - system(init_program_chgrp " " init_group_process_console " " init_path_device_console); - system(init_program_chgrp " " init_group_process_random " " init_path_device_random); - system(init_program_chgrp " " init_group_process_urandom " " init_path_device_urandom); - - // attempt to load kernel command line, but do not stop on failure. - if (run_level > 0 && run_level[0] != 0) { - f_file_p kernel_command_line_file = 0; - f_string_t kernel_command_line_string = f_string_t_initialize; - size_t kernel_command_line_length = 0; - - kernel_command_line_file = fopen(init_kernel_command_line, "ro"); - - if (kernel_command_line_file > 0) { - getline(&kernel_command_line_string, &kernel_command_line_length, kernel_command_line_file); - - if (kernel_command_line_file) { - fclose(kernel_command_line_file); - } - } - - if (kernel_command_line_length > 0) { - regex_t expression; - regmatch_t match; - unsigned int reg_result = 0; - unsigned int string_length = 0; - - reg_result = do_regex_match(&expression, &match, kernel_command_line_string, init_kernel_runlevel); - - if (reg_result == REG_OK) { - string_length = match.rm_eo - match.rm_so - init_kernel_runlevel_ignore; - - // if the run_level value is greater than the static buffer size, ignore the entire string rather than process a cut off value. - if (string_length > 0 && string_length < init_kernel_runlevel_buffer) { - strncpy(run_level, kernel_command_line_string + match.rm_so + init_kernel_runlevel_ignore, string_length); - } - } - } - - if (kernel_command_line_string) { - f_status_t status_free = F_none; - f_macro_string_t_delete(status_free, kernel_command_line_string, string_length); - } - } - - return F_none; - } -#endif // _di_init_prepare_system_ - -#ifndef _di_init_prepare_system_ - f_return_status init_prepare_system() { - f_status_t status = F_none; - f_stat stat; - - memset(&stat, 0, sizeof(f_stat)); - - // @fixme: this is implemented using user space tools. - // such a design allows for quick implementation but I consider this bad practice. - // work towards replacing this with custom functions. - - // create the required directories if they do not already exist and then perform appropriate mount. - status = f_file_stat(init_paths_devices, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_devices); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " init_paths_devices); - - status = f_file_stat(init_paths_system, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_system); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " -p " init_paths_system); - - status = f_file_stat(init_paths_devices_pts, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_devices_pts); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " -t " init_paths_devices_pts); - - status = f_file_stat(init_paths_log, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_log); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " init_paths_log); - - status = f_file_stat(var_run_path, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " var_run_path); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " var_run_path); - - status = f_file_stat(mnt_path, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " mnt_path); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " mnt_path); - - status = f_file_stat(tmp_path, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " tmp_path); - memset(&stat, 0, sizeof(f_stat)); - } - - system(init_program_mount " " tmp_path); - - // create the required devices - system(init_program_mknod " -m 0660 " init_path_device_null " c 1 3"); - system(init_program_mknod " -m 0660 " init_path_device_zero " c 1 5"); - system(init_program_mknod " -m 0660 " init_path_device_console " c 5 1"); - system(init_program_mknod " -m 0440 " init_path_device_random " c 1 8"); - system(init_program_mknod " -m 0440 " init_path_device_urandom " c 1 9"); - system(init_program_chgrp " " init_group_process_null " " init_path_device_null); - system(init_program_chgrp " " init_group_process_zero " " init_path_device_zero); - system(init_program_chgrp " " init_group_process_console " " init_path_device_console); - system(init_program_chgrp " " init_group_process_random " " init_path_device_random); - system(init_program_chgrp " " init_group_process_urandom " " init_path_device_urandom); - - return F_none; - } -#endif // _di_init_prepare_system_ - -#ifndef _di_init_prepare_init_ - f_return_status init_prepare_init() { - f_stat stat; - - memset(&stat, 0, sizeof(f_stat)); - - // @fixme: this is implemented using user space tools. - // such a design allows for quick implementation but I consider this bad practice. - // work towards replacing this with custom functions. - - status = f_file_stat(init_paths_init_run, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_init_run); - system(init_program_chgrp " " init_group_init_run " " init_paths_init_run); - memset(&stat, 0, sizeof(f_stat)); - } - - status = f_file_stat(init_paths_init_settings, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_init_settings); - system(init_program_chgrp " " init_group_init_settings " " init_paths_init_settings); - memset(&stat, 0, sizeof(f_stat)); - } - - status = f_file_stat(init_paths_init_socket, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_init_socket); - system(init_program_chgrp " " init_group_init_socket " " init_paths_init_socket); - memset(&stat, 0, sizeof(f_stat)); - } - - status = f_file_stat(init_paths_init_process, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_init_process); - system(init_program_chgrp " " init_group_init_process " " init_paths_init_process); - memset(&stat, 0, sizeof(f_stat)); - } - - status = f_file_stat(init_paths_init_log, &stat); - - if (status == F_file_found_not || status == F_status_set_error(F_directory)) { - system(init_program_mkdir " -p " init_paths_init_log); - system(init_program_chgrp " " init_group_init_log " " init_paths_init_log); - memset(&stat, 0, sizeof(f_stat)); - } - - memset(&stat, 0, sizeof(f_stat)); - - return F_none; - } -#endif // _di_init_prepare_init_ - -#ifndef _di_init_process_main_rule_ - f_return_status init_process_main_rule(const init_data_t data, f_string_dynamic_t *buffer, init_data_t *settings) { - f_status_t status = F_none; - f_string_dynamic_t buffer = f_string_dynamic_t_initialize; - f_string_range_t range = f_string_range_t_initialize; - f_fss_objects_t objects = f_fss_objects_t_initialize; - f_fss_contents_t contents = f_fss_contents_t_initialize; - f_string_length_t position = 0; - f_fss_delimits_t delimits = f_fss_delimits_t_initialize; - - // load the main file into memory. - status = init_rule_buffer(&data, init_rule_core_file, &buffer, &objects, &contents); - - if (F_status_is_error(status)) { - status = F_status_set_fine(status); - - if (status == F_parameter) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sInvalid parameter when calling fll_fss_basic_list_read() for the file '%s'.", fll_error_print_error, init_rule_core_file); - } else if (status == F_data_not_eos || status == F_data_not || status == F_data_not_stop) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sNo relevant data was found within the file '%s'.", fll_error_print_error, init_rule_core_file); - } else if (status == F_memory_allocation || status == F_memory_reallocation) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sUnable to allocate memory.", fll_error_print_error); - } else { - fl_color_print(data.error.to.stream, data.context.set.error, "%sAn unhandled error (%u) has occurred while calling fll_fss_basic_list_read() for the file '%s'.", fll_error_print_error, status, init_rule_core_file); - } - - f_macro_string_dynamic_t_delete(buffer); - f_macro_fss_objects_t_delete(objects); - f_macro_fss_contents_t_delete(contents); - f_macro_fss_delimits_t_delete_simple(delimits); - return status; - } - - while (position < objects.used) { - location.start = objects.array[position].start; - location.stop = objects.array[position].stop; - delimits.used = 0; - - status = fll_fss_extended_read(&buffer, &location, &objects, &contents, 0, 0, &delimits, 0); - - if (F_status_is_error_not(*status)) { - status = fl_fss_apply_delimit(delimits, &buffer); - } - - position++; - } // while - - // @fixme: resume here, below is just notes and copy&pasted code as examples/reminders. - - /* - delimits.used = 0; - - status = fll_fss_extended_read(&buffer, &location, &objects, &contents, 0, 0, &delimits, 0); - - if (F_status_is_error_not(status)) { - status = fl_fss_apply_delimit(delimits, &buffer); - } - - if (F_status_is_error(status_process)) { - if (status == F_memory_allocation || status == F_memory_reallocation) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sUnable to allocate memory.", fll_error_print_error); - } - else { - fl_color_print(data.error.to.stream, data.context.set.error, "%sAn unhandled error (%u) has occurred while calling init_load_main_rule().", fll_error_print_error, status); - } - - // @todo: init_delete_data((*data)); - // @todo: init_delete_stack_memory(&stack_memory); - f_macro_fss_delimits_t_delete_simple(delimits); - - return status_process; - } - */ - - - /* - f_status_t status = F_none; - delimits.used = 0; - - status = fll_fss_extended_read(buffer, location, objects, contents, 0, 0, &delimits, 0); - - if (F_status_is_error_not(status)) { - status = fl_fss_apply_delimit(delimits, &buffer); - } - - if (F_status_is_error(*status)) { - fll_error_print(data.error, F_status_set_fine(*status), "fl_fss_apply_delimit", F_true); - } - - if (F_status_is_error_not(status)) { - // @todo: process objects and contents. - // execute individual processes. - - if (F_status_is_error(status)) { - status = F_status_set_fine(status); - - if (status == F_memory_allocation || status == F_memory_reallocation) { - fl_color_print(data.error.to.stream, data.context.set.error, "%sUnable to allocate memory.", fll_error_print_error); - } else if (status == F_failure) { - // the error message has already been displayed. - } else { - fl_color_print(data.error.to.stream, data.context.set.error, "%sAn unhandled error (%u) has occurred while calling firewall_perform_commands().", fll_error_print_error, status); - } - - f_macro_fss_objects_t_delete_simple((*rule_objects)); - f_macro_fss_contents_t_delete_simple((*rule_contents)); - f_macro_fss_delimits_t_delete_simple(delimits); - return F_status_set_error(status); - } - } - else { - if (status == F_memory_allocation || status == F_memory_reallocation) { - fl_color_print(data.error.to.stream, context.set.error, "%sUnable to allocate memory.", fll_error_print_error); - } - else { - fl_color_print(data.error.to.stream, context.set.error, "%sAn unhandled error (%u) has occurred while calling init_load_main_rule().", fll_error_print_error, status); - } - } - - f_macro_fss_objects_t_delete_simple((*rule_objects)); - f_macro_fss_contents_t_delete_simple((*rule_contents)); - */ -/* - f_macro_fss_delimits_t_delete_simple(delimits); - f_macro_string_dynamic_t_delete(buffer); - f_macro_fss_objects_t_delete(objects); - f_macro_fss_contents_t_delete(contents); - return status; - } -#endif // _di_init_process_main_rule_ - */ diff --git a/level_3/init/c/private-init.h b/level_3/init/c/private-init.h index 09ba4a2..b630b67 100644 --- a/level_3/init/c/private-init.h +++ b/level_3/init/c/private-init.h @@ -1,7 +1,10 @@ /** - * Private include file for init.c. + * FLL - Level 3 + * + * Project: Init + * API Version: 0.5 + * Licenses: lgplv2.1 */ - #ifndef _PRIVATE_init_h #define _PRIVATE_init_h @@ -9,357 +12,6 @@ extern "C" { #endif -// define a custom stack size for each handler. -// consider mmap(): -// - http://www.evanjones.ca/software/threading.html -// - http://stackoverflow.com/questions/1083172/how-to-mmap-the-stack-for-the-clone-system-call-on-linux -// - void *stack = mmap(0,initial_stacksize,PROT_WRITE|PROT_READ,MAP_PRIVATE|MAP_GROWSDOWN|MAP_ANONYMOUS,-1,0); -// - http://lwn.net/Articles/294001/ -// - http://tiku.io/questions/659065/how-to-mmap-the-stack-for-the-clone-system-call-on-linux -#define init_stack_size_small_services 6144 -#define init_stack_size_small_control_file 4096 -#define init_stack_size_large_services 12288 -#define init_stack_size_large_control_file 8192 - -#define init_flags_clone 0 - -#define init_stack_protections PROT_WRITE | PROT_READ -#define init_stack_flags MAP_PRIVATE | MAP_GROWSDOWN | MAP_ANONYMOUS - -#define init_clone_flags CLONE_FILES | CLONE_FS | CLONE_IO | CLONE_VM | CLONE_SIGHAND | CLONE_THREAD - -#define init_panic_signal_sleep_seconds 9 - -#ifndef _di_init_rule_ - // rule [directory] [filename (no-extension)] [require] [last] [asynchronous] = execute a rule located in [directory][filename].rule. - typedef struct { - f_string_dynamic_t name; - f_string_dynamic_t directory; - f_string_dynamic_t file; - bool require; - bool asynchronous; - } init_rule; - - #define init_rule_initialize \ - { \ - f_string_dynamic_t_initialize, \ - f_string_dynamic_t_initialize, \ - f_string_dynamic_t_initialize, \ - F_false, \ - F_false, \ - } - - #define delete_init_rule(status, rule) \ - f_macro_string_dynamic_t_delete(status, rule.name); \ - if (status == F_none) { \ - f_macro_string_dynamic_t_delete(status, rule.directory); \ - } \ - if (status == F_none) { \ - f_macro_string_dynamic_t_delete(status, rule.address); \ - } \ - if (status == F_none) { \ - rule.require = 0; \ - rule.asynchronous = 0; \ - } - - #define destroy_init_rule(status, rule) \ - f_macro_string_dynamic_t_destroy(status, rule.name); \ - if (status == F_none) { \ - f_macro_string_dynamic_t_destroy(status, rule.directory); \ - } \ - if (status == F_none) { \ - f_macro_string_dynamic_t_destroy(status, rule.address); \ - } \ - if (status == F_none) { \ - rule.require = 0; \ - rule.asynchronous = 0; \ - } -#endif // _di_init_data_t_ - -// an array of dynamic strings -#ifndef _di_init_rules_ - typedef struct { - init_rule *array; // the array of init_rule - f_string_length_t size; // total amount of allocated space - f_string_length_t used; // total number of allocated spaces used - } init_rules; - - #define init_rules_initialize { 0, 0, 0 } - - #define f_init_rules_delete(status, rules) \ - status = F_none; \ - while (rules.size > 0) { \ - --rules.size; \ - delete_init_rule(status, rules.array[rules.size]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_delete((void **) & rules.array, sizeof(init_rule), rules.size); \ - if (status == F_none) rules.used = 0; - - #define f_init_rules_destroy(status, rules) \ - status = F_none; \ - while (rules.size > 0) { \ - --rules.size; \ - destroy_init_rule(status, rules.array[rules.size]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_destroy((void **) & rules.array, sizeof(init_rule), rules.size); \ - if (status == F_none) rules.used = 0; - - #define f_init_rules_resize(status, rules, new_length) \ - status = F_none; \ - if (new_length < rules.size) { \ - f_string_length_t _macro__i = rules.size - new_length; \ - for (; _macro__i < rules.size; _macro__i++) { \ - delete_init_rule(status, rules.array[_macro__i]); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_resize((void **) & rules.array, sizeof(init_rule), rules.size, new_length); \ - if (status == F_none) { \ - if (new_length > rules.size) { \ - f_string_length_t _macro__i = rules.size; \ - for (; _macro__i < new_length; _macro__i++) { \ - memset(&rules.array[_macro__i], 0, sizeof(f_string_t)); \ - } \ - } \ - rules.size = new_length; \ - if (rules.used > rules.size) rules.used = new_length; \ - } - - #define f_init_rules_adjust(status, rules, new_length) \ - status = F_none; \ - if (new_length < rules.size) { \ - f_string_length_t _macro__i = rules.size - new_length; \ - for (; _macro__i < rules.size; _macro__i++) { \ - destroy_init_rule(status, rules.array[_macro__i]); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_adjust((void **) & rules.array, sizeof(init_rule), rules.size, new_length); \ - if (status == F_none) { \ - if (new_length > rules.size) { \ - f_string_length_t _macro__i = rules.size; \ - for (; _macro__i < new_length; _macro__i++) { \ - memset(&rules.array[_macro__i], 0, sizeof(init_rule)); \ - } \ - } \ - rules.size = new_length; \ - if (rules.used > rules.size) rules.used = new_length; \ - } -#endif // _di_init_rules_ - -#ifndef _di_init_category_ - // category [name] = execute rules in the specified list called [name]. - typedef struct { - f_string_dynamic_t name; - init_rule last; - } init_category; - - #define init_category_initialize \ - { \ - f_string_dynamic_t_initialize, \ - init_rule_initialize, \ - } - - #define delete_init_category(status, category) \ - f_macro_string_dynamic_t_delete(status, category.name); \ - if (status == F_none) { \ - delete_init_rule(status, category.last); \ - } - - #define destroy_init_category(status, category) \ - f_macro_string_dynamic_t_destroy(status, category.name); \ - if (status == F_none) { \ - destroy_init_rule(status, category.last); \ - } -#endif // _di_init_category_ - -// an array of dynamic strings -#ifndef _di_init_categorys_ - typedef struct { - init_category *array; // the array of init_category - - f_string_length_t size; // total amount of allocated space - f_string_length_t used; // total number of allocated spaces used - } init_categorys; - - #define init_categorys_initialize { 0, 0, 0 } - - #define f_init_categorys_delete(status, categorys) \ - status = F_none; \ - while (categorys.size > 0) { \ - --categorys.size; \ - delete_init_category(status, categorys.array[categorys.size]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_delete((void **) & categorys.array, sizeof(init_category), categorys.size); \ - if (status == F_none) categorys.used = 0; - - #define f_init_categorys_destroy(status, categorys) \ - status = F_none; \ - while (categorys.size > 0) { \ - --categorys.size; \ - destroy_init_category(status, categorys.array[categorys.size]); \ - if (status != F_none) break; \ - } \ - if (status == F_none) status = f_memory_destroy((void **) & categorys.array, sizeof(init_category), categorys.size); \ - if (status == F_none) categorys.used = 0; - - #define f_init_categorys_resize(status, categorys, new_length) \ - status = F_none; \ - if (new_length < categorys.size) { \ - f_string_length_t _macro__i = categorys.size - new_length; \ - for (; _macro__i < categorys.size; _macro__i++) { \ - delete_init_category(status, categorys.array[_macro__i]); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_resize((void **) & categorys.array, sizeof(init_category), categorys.size, new_length); \ - if (status == F_none) { \ - if (new_length > categorys.size) { \ - f_string_length_t _macro__i = categorys.size; \ - for (; _macro__i < new_length; _macro__i++) { \ - memset(&categorys.array[_macro__i], 0, sizeof(f_string_t)); \ - } \ - } \ - categorys.size = new_length; \ - if (categorys.used > categorys.size) categorys.used = new_length; \ - } - - #define f_init_categorys_adjust(status, categorys, new_length) \ - status = F_none; \ - if (new_length < categorys.size) { \ - f_string_length_t _macro__i = categorys.size - new_length; \ - for (; _macro__i < categorys.size; _macro__i++) { \ - destroy_init_category(status, categorys.array[_macro__i]); \ - if (status != F_none) break; \ - } \ - } \ - if (status == F_none) status = f_memory_adjust((void **) & categorys.array, sizeof(init_category), categorys.size, new_length); \ - if (status == F_none) { \ - if (new_length > categorys.size) { \ - f_string_length_t _macro__i = categorys.size; \ - for (; _macro__i < new_length; _macro__i++) { \ - memset(&categorys.array[_macro__i], 0, sizeof(init_category)); \ - } \ - } \ - categorys.size = new_length; \ - if (categorys.used > categorys.size) categorys.used = new_length; \ - } -#endif // _di_init_categorys_ - -#ifndef _di_init_setting_ - typedef struct { - f_string_t socket_file; - unsigned int socket_port; - unsigned int socket_id_target; - unsigned int socket_id_client; - - unsigned short timeout_start; - unsigned short timeout_stop; - unsigned short timeout_kill; - - init_rules main_rules; - init_categorys main_categorys; - init_rule main_failsafe; - } init_setting; - - #define init_setting_initialize \ - { \ - f_string_t_initialize, \ - 0, \ - 0, \ - 0, \ - 2, \ - 2, \ - 1, \ - init_rules_initialize, \ - init_categorys_initialize, \ - init_rule_initialize, \ - } -#endif // _di_init_setting_ - -typedef struct { - void *services; - void *reporting; - void *time; - void *control_file; - void *control_port; - void *login_file; - void *login_port; - - init_data_t data; - init_setting setting; -} init_stack_memory; - -#define init_stack_memory_initialize \ - { \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - 0, \ - init_data_initialize, \ - init_setting_initialize, \ - } - -// custom settings to prepare the init process. -// this is not self-contained and depends on user space applications to exist. -#define init_program_umount "umount" -#define init_program_mount "mount" -#define init_program_mkdir "mkdir" -#define init_program_chmod "chmod" -#define init_program_chgrp "chgrp" -#define init_program_mknod "mknod" -#define init_program_ln "ln" - -#define init_path_device_console init_paths_devices "console" -#define init_path_device_zero init_paths_devices "zero" -#define init_path_device_null init_paths_devices "null" -#define init_path_device_random init_paths_devices "random" -#define init_path_device_urandom init_paths_devices "urandom" - -#define init_path_processes_cmdline init_paths_processes "cmdline" -#define init_path_processes_mounts init_paths_processes "mounts" -/* -#ifndef _di_init_rule_buffer_ - f_return_status init_rule_buffer(const init_data_t data, const f_string_t filename, f_string_dynamic_t *buffer, f_fss_objects_t *objects, f_fss_contents_t *contents) f_gcc_attribute_visibility_internal; -#endif // _di_init_rule_buffer_ - -#ifndef _di_init_handler_chif_string_dynamic_initializeld_services_ - // start, stop, and handle signals to services. - f_return_status init_handler_child_services(void *argument) f_gcc_attribute_visibility_internal; -#endif // _di_init_handler_child_services_ - -#ifndef _di_init_handler_child_control_file_ - // listens on a socket file and accepts control commands. - f_return_status init_handler_child_control_file(void *argument) f_gcc_attribute_visibility_internal; -#endif // _di_init_handler_child_socket_file_ - -#ifndef _di_init_initialize_stack_memory_ - f_return_status init_initialize_stack_memory(init_stack_memory *stack_memory) f_gcc_attribute_visibility_internal; -#endif // _di_init_initialize_stack_memory_ - -#ifndef _di_init_delete_stack_memory_ - f_return_status init_delete_stack_memory(init_stack_memory *stack_memory) f_gcc_attribute_visibility_internal; -#endif // _di_init_delete_stack_memory_ - -#ifndef _di_init_prepare_system_ - f_return_status init_prepare_system() f_gcc_attribute_visibility_internal; -#endif // _di_init_prepare_system_ - -#ifndef _di_init_prepare_init_ - f_return_status init_prepare_init() f_gcc_attribute_visibility_internal; -#endif // _di_init_prepare_init_ - -#ifndef _di_init_process_main_rule_ - f_return_status init_process_main_rule(const init_data_t data, f_string_dynamic_t *buffer, init_setting *setting) f_gcc_attribute_visibility_internal; -#endif // _di_init_process_main_rule_ -*/ - #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/init/data/build/dependencies b/level_3/init/data/build/dependencies index 73d3b85..3b53a6c 100644 --- a/level_3/init/data/build/dependencies +++ b/level_3/init/data/build/dependencies @@ -7,18 +7,12 @@ f_string f_utf f_color f_console -f_directory -f_environment f_file -f_fss f_pipe f_print fl_color fl_console -fl_fss -fl_status fl_string fll_error -fll_execute -fll_fss fll_program +fll_status diff --git a/level_3/init/data/build/settings b/level_3/init/data/build/settings index 8118e46..ca7867d 100644 --- a/level_3/init/data/build/settings +++ b/level_3/init/data/build/settings @@ -19,7 +19,7 @@ build_compiler gcc build_indexer ar build_language c build_libraries -lc -build_libraries-individual -lfll_error -lfll_execute -lfll_fss -lfll_program -lfl_color -lfl_console -lfl_conversion -lfl_environment -lfl_fss -lfl_status -lfl_string -lf_console -lf_conversion -lf_directory -lf_environment -lf_file -lf_fss -lf_memory -lf_path -lf_pipe -lf_print -lf_signal -lf_utf +build_libraries-individual -lfll_error -lfll_program -lfll_status -lfl_color -lfl_console -lfl_status -lfl_string -lf_console -lf_conversion -lf_file -lf_memory -lf_pipe -lf_print -lf_utf build_libraries-level -lfll_2 -lfll_1 -lfll_0 build_libraries-monolithic -lfll build_sources_library init.c private-init.c diff --git a/level_3/init/data/settings/core.rule b/level_3/init/data/settings/core.rule deleted file mode 100644 index 51207d7..0000000 --- a/level_3/init/data/settings/core.rule +++ /dev/null @@ -1,46 +0,0 @@ -# fss-0002 -# category [name] = execute rules in the specified list called [name]. -# failsafe [name] = a list whose rules get executed when required rules fail. -# rule [directory] [filename (no-extension)] [require] [last] [asynchronous] = execute a rule located in [directory][filename].rule. -# If [require] is specified, then execute failsafe list. -# If [last] is specified, then execution ceases with this list or rule. -# If [asynchronous] is specified, then execution of this rule will be run asynchronously. -# timeout [start|stop|kill] [seconds] provide a default time setting in seconds. -# -# this file is only used for booting. - -main: - timeout start 7 - timeout stop 7 - timeout kill 3 - - category boot - category net - category time - category console - - failsafe maintenance last - -maintenance: - timeout start 2 - timeout stop 2 - timeout kill 1 - - rule maintenance console - -boot: - rule boot filesystem require - rule boot modules require - rule boot devices require - rule target logger - rule target dbus - -net: - rule net all - -time: - rule service clock - -console: - rule program terminal require - rule target mouse diff --git a/level_3/init/data/settings/rules/boot/devices.rule b/level_3/init/data/settings/rules/boot/devices.rule deleted file mode 100644 index b62bdb2..0000000 --- a/level_3/init/data/settings/rules/boot/devices.rule +++ /dev/null @@ -1,14 +0,0 @@ -# fss-0002 - -main: - name boot-devices - -script: - start { - ip addr add 127.0.0.1/8 label lo dev lo; - ip link set lo up; - } - - stop { - ip link set lo down; - } diff --git a/level_3/init/data/settings/rules/boot/filesystem.rule b/level_3/init/data/settings/rules/boot/filesystem.rule deleted file mode 100644 index ec18c8b..0000000 --- a/level_3/init/data/settings/rules/boot/filesystem.rule +++ /dev/null @@ -1,52 +0,0 @@ -# fss-0002 -# the first list to be executed, will be called 'main' and is broken up into the following fss-0000 or fss-0001 content. -# name = an identifier that this rule represents. The first rule with this identifier name to be successfully executed will cease all other uses of this list. -# need = all of the rule identifiers that represent rules required to be executed (and succeed) before this starts. -# want = all of the rule identifiers that represent rules required to be executed (but not succeed) before this starts. -# wish = all of the rule identifiers that represents rules that would be prefered to be executed before this starts. -# variable [variable name] [filename] [file format] [count number] = a variable to be loaded and used by lists in this rule. -# [variable name] = name of the variable in both the file and in the rule -# [filename] = name of the file stored in. -# [file format] = the format to read the file and load the variable. Supported formats: raw, fss-0000, fss-0001, fss-0002, fss-0003. -# [count number] = select a specific occurance of the [variable name] within the [filename]. -# -# each list, following the 'main' list will have a name that represents how it gets executed. -# 'command' represents a list with the single-line fss-0000 rules 'start', 'stop', 'restart', and 'reload' that get directly passed. -# not providing restart means that a 'start' and then 'stop' is used. -# not providing reload makes reload do nothing. -# providing 'start', 'stop', 'restart', or 'reload' but having no values means that the command will not be provided. -# -# 'script' represents a list broken up into multiple fss-0003 lists: 'start', 'stop', 'restart', and 'reload'. -# not providing restart means thata 'start' and then 'stop' is used. -# not providing reload makes reload do nothing. -# providing 'start', 'stop', 'restart', or 'reload' but having no values means that the command will not be provided. -# -# 'target' represents a 'command' list that expects a given pid file to be created by the program or created by this program. -# example pid line: 'pid program /run/program/name.pid' or: 'pid init /run/program/name.pid', such that 'program' tells the init program to expect the target to create the pid file and 'init' to expect this program to create the pid file. -# not providing stop will result in the init program reading the pid file and terminating the process by the pid. -# not providing restart means that a 'start' and then 'stop' is used. -# not providing reload makes reload do nothing. -# not providing start will result in no action on start. -# providing a 'stop' that is blank will result in no action on stop. -# -# 'timeout' [start|stop|kill] represents an amount of time to wait for pid file before considering the start, stop, or kill as problematic. -# providing a blank start or stop will result in an indefinite wait. -# kill will be called after stop fails and process is still running. -# providing a blank kill will result in kill not being executed when stop fails. -# -# each list, except for main, will be executed in a top down order (synchronously). -# -# each script, command, and target will support the following settings: -# 'user' the user id to switch to before executing/processing. -# 'group' the group id to switch to before executing/processing. - -main: - name boot-filesystem - -command: - start mount -a -O no_netdev - stop umount -arf -O no_netdev - -command: - start swapon -a - stop swapoff -a diff --git a/level_3/init/data/settings/rules/boot/modules.rule b/level_3/init/data/settings/rules/boot/modules.rule deleted file mode 100644 index 468635d..0000000 --- a/level_3/init/data/settings/rules/boot/modules.rule +++ /dev/null @@ -1,88 +0,0 @@ -# fss-0002 - -default: - name boot-modules - need boot-filesystem - -script: - start { - if [[ ! -f /proc/modules ]] ; then - exit 0; - fi - - if [[ ! -e /lib/modules/$(uname -r)/modules.dep ]] ; then - depmod; - fi - - return 0; - } - - stop { - video_line=$(dmesg | grep -s -o '^\[drm] [[:alpha:]]* defaulting to [[:alpha:]]* modesetting.$') - - if [[ $(echo $video_line | grep -s -o '\') != "" ]] ; then - modesetting=kernel - else - modesetting=user - fi - - video_card=$(echo $video_line | grep -s -o '^\[drm] [[:alpha:]]* defaulting' | sed -e 's|^\[drm] ||' -e 's| defaulting$||') - - # handle nouveau - if [[ $video_card == "" ]] ; then - video_line=$(dmesg | grep -s -o '^\[drm] Initialized nouveau .*$') - - if [[ $video_line != "" ]] ; then - video_line=$(dmesg | grep -s -o '^fbcon: nouveaufb (fb0) is primary device$') - - if [[ $video_line != "" ]] ; then - modesetting=kernel - video_card=nouveau - fi - fi - fi - - if [[ $modesetting == "user" ]] ; then - video_line=$(dmesg | grep -s -o '^fbcon: NV.* (fb0) is primary device$') - - if [[ $video_line != "" ]] ; then - video_card=nv - fi - - if [[ $video_card == "" ]] ; then - video_line=$(dmesg | grep -s -o '^fbcon: radeon.*fb (fb0) is primary device$') - - if [[ $video_line != "" ]] ; then - video_card=radeon - fi - fi - - if [[ $video_card == "" ]] ; then - video_line=$(dmesg | grep -s -o '^fbcon: .* Radeon .* (fb0) is primary device$') - - if [[ $video_line != "" ]] ; then - video_card=radeon - fi - fi - - if [[ $video_card == "" ]] ; then - video_line=$(dmesg | grep -s -o '^fbcon: intel.*fb (fb0) is primary device$') - - if [[ $video_line != "" ]] ; then - video_card=intel - fi - fi - fi - - if [[ ! -f /dev/modesetting ]] ; then - echo $modesetting > /dev/modesetting - chmod u+rw-x,g+r-wx,o-rwx /dev/modesetting - chgrp e_xorg /dev/modesetting - fi - - if [[ ! -f /dev/video_card ]] ; then - echo $video_card > /dev/video_card - chmod u+rw-x,g+r-wx,o-rwx /dev/video_card - chgrp e_xorg /dev/video_card - fi - } diff --git a/level_3/init/data/settings/rules/net/all.rule b/level_3/init/data/settings/rules/net/all.rule deleted file mode 100644 index b09acbc..0000000 --- a/level_3/init/data/settings/rules/net/all.rule +++ /dev/null @@ -1,9 +0,0 @@ -# fss-0002 - -main: - name net-all - -command: - start network start - stop network stop - restart network restart diff --git a/level_3/init/data/settings/rules/net/loopback.rule b/level_3/init/data/settings/rules/net/loopback.rule deleted file mode 100644 index aa6b169..0000000 --- a/level_3/init/data/settings/rules/net/loopback.rule +++ /dev/null @@ -1,14 +0,0 @@ -# fss-0002 - -main: - name net-loopback - -script: - start { - ip addr add 127.0.0.1/8 label lo dev lo; - ip link set lo up; - } - - stop { - ip link set lo down; - } diff --git a/level_3/init/data/settings/rules/program/terminal.rule b/level_3/init/data/settings/rules/program/terminal.rule deleted file mode 100644 index 766fde1..0000000 --- a/level_3/init/data/settings/rules/program/terminal.rule +++ /dev/null @@ -1,21 +0,0 @@ -# fss-0002 - -main: - name program-terminal - want boot-modules - -target: - start qingy tty1 -d -l -n -t - pid init /run/tty/tty1.pid - -target: - start qingy tty2 -d -l -n -t - pid init /run/tty/tty2.pid - -target: - start qingy tty3 -d -l -n -t - pid init /run/tty/tty3.pid - -target: - start qingy tty4 -d -l -n -t - pid init /run/tty/tty4.pid diff --git a/level_3/init/data/settings/rules/service/clock.rule b/level_3/init/data/settings/rules/service/clock.rule deleted file mode 100644 index 1edf634..0000000 --- a/level_3/init/data/settings/rules/service/clock.rule +++ /dev/null @@ -1,23 +0,0 @@ -# fss-0002 - -main: - name - -script: - start { - clock_mode=$(fss_basic_read -c 0 -n mode /etc/clock); - - if [[ $clock_mode == "local" ]] ; then - hwclock --hctosys; - elif [[ $clock_mode == "ntpdate" ]] ; then - ntpdate $(fss_basic_read -c 0 -n server /etc/clock) && - hwclock --systohc --utc - elif [[ $clock_mode == "ntp" ]] ; then - if [[ $(fss_basic_read -c 0 -n ntpdate /etc/clock) == "yes" ]] ; then - ntpdate $(fss_basic_read -c 0 -n server /etc/clock) && - hwclock --systohc --utc - fi - elif [[ $clock_mode == "utc" ]] ; then - hwclock --hctosys --utc; - fi - } diff --git a/level_3/init/data/settings/rules/target/dbus.rule b/level_3/init/data/settings/rules/target/dbus.rule deleted file mode 100644 index 369ab3f..0000000 --- a/level_3/init/data/settings/rules/target/dbus.rule +++ /dev/null @@ -1,8 +0,0 @@ -# fss-0002 - -main: - name target-dbus - -target: - start dbus-daemon --system --fork - pid target /run/dbus/dbus.pid diff --git a/level_3/init/data/settings/rules/target/logger.rule b/level_3/init/data/settings/rules/target/logger.rule deleted file mode 100644 index eaa1d51..0000000 --- a/level_3/init/data/settings/rules/target/logger.rule +++ /dev/null @@ -1,9 +0,0 @@ -# fss-0002 - -main: - name target/logger - -target: - start metalog -B -p /run/logger/logger.pid -C /etc/logger.conf - pid target /run/logger/logger.pid - diff --git a/level_3/init/data/settings/rules/target/mouse.rule b/level_3/init/data/settings/rules/target/mouse.rule deleted file mode 100644 index 40aa768..0000000 --- a/level_3/init/data/settings/rules/target/mouse.rule +++ /dev/null @@ -1,12 +0,0 @@ -# fss-0002 - -main: - name target-mouse - want boot/modules - variable device /etc/mouse fss-0000 - variable protocol /etc/mouse fss-0000 - variable options /etc/mouse fss-0000 - -target: - start gpm -m [device] -t [protocol] [options] - pid /run/mouse/mouse.pid -- 1.8.3.1