From: Kevin Day Date: Tue, 23 Aug 2022 01:10:36 +0000 (-0500) Subject: Bugfix: The fll_program_standard_signal_received() needs a private implementation. X-Git-Tag: 0.6.1~12 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=ed22b926b67429681841b6b0dc3d76daca1b451f;p=fll Bugfix: The fll_program_standard_signal_received() needs a private implementation. The function fll_program_standard_signal_received() is being called by fll_program_standard_signal_state(). This is not supposed to be allowed and breaks the functional-modular design. A private function now exists that is called. --- diff --git a/build/level_2/settings b/build/level_2/settings index 0f5da27..2e42edb 100644 --- a/build/level_2/settings +++ b/build/level_2/settings @@ -30,7 +30,7 @@ build_sources_library fss_status_string.c build_sources_library iki.c private-iki.c build_sources_library path.c build_sources_library print.c -build_sources_library program.c program/common.c +build_sources_library program.c program/common.c private-program.c build_sources_library status_string.c build_sources_headers control_group.h diff --git a/build/monolithic/settings b/build/monolithic/settings index 42067e4..7b92e69 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -67,7 +67,7 @@ build_sources_library level_2/fss_status_string.c build_sources_library level_2/iki.c level_2/private-iki.c build_sources_library level_2/path.c build_sources_library level_2/print.c -build_sources_library level_2/program.c level_2/program/common.c +build_sources_library level_2/program.c level_2/program/common.c level_2/private-program.c build_sources_library level_2/status_string.c build_sources_library-monolithic level_0/thread.c level_0/private-thread.c level_0/thread/attribute.c level_0/thread/barrier.c level_0/thread/barrier_attribute.c level_0/thread/condition.c level_0/thread/condition_attribute.c level_0/thread/id.c level_0/thread/key.c level_0/thread/lock.c level_0/thread/lock_attribute.c level_0/thread/mutex.c level_0/thread/mutex_attribute.c level_0/thread/once.c level_0/thread/semaphore.c level_0/thread/set.c level_0/thread/spin.c diff --git a/level_2/fll_program/c/private-program.c b/level_2/fll_program/c/private-program.c new file mode 100644 index 0000000..46c7174 --- /dev/null +++ b/level_2/fll_program/c/private-program.c @@ -0,0 +1,37 @@ +#include "program.h" +#include "private-program.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_fll_program_standard_signal_received_) || !defined(_di_fll_program_standard_signal_state_) + f_status_t private_fll_program_standard_signal_received(fll_program_data_t * const main) { + + if (main->signal.id == -1) return 0; + + struct signalfd_siginfo information; + + memset(&information, 0, sizeof(struct signalfd_siginfo)); + + if (f_signal_read(main->signal, 0, &information) == F_signal) { + switch (information.ssi_signo) { + case F_signal_abort: + case F_signal_broken_pipe: + case F_signal_hangup: + case F_signal_interrupt: + case F_signal_quit: + case F_signal_termination: + main->signal_received = information.ssi_signo; + + return information.ssi_signo; + } + } + + return 0; + } +#endif // !defined(_di_fll_program_standard_signal_received_) || !defined(_di_fll_program_standard_signal_state_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_2/fll_program/c/private-program.h b/level_2/fll_program/c/private-program.h new file mode 100644 index 0000000..a9bb238 --- /dev/null +++ b/level_2/fll_program/c/private-program.h @@ -0,0 +1,43 @@ +/** + * FLL - Level 2 + * + * Project: Program + * API Version: 0.6 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_FLL_program_h +#define _PRIVATE_FLL_program_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation of fll_program_standard_signal_received(). + * + * Intended to be shared to each of the different implementation variations. + * + * @param main + * The main program data. + * + * @return + * A positive number representing a valid signal on signal received. + * 0 on no signal received or when main is NULL. + * + * @see f_signal_read() + * + * @see fll_program_standard_signal_received() + * @see fll_program_standard_signal_state() + */ +#if !defined(_di_fll_program_standard_signal_received_) || !defined(_di_fll_program_standard_signal_state_) + f_status_t private_fll_program_standard_signal_received(fll_program_data_t * const main) F_attribute_visibility_internal_d; +#endif // !defined(_di_fll_program_standard_signal_received_) || !defined(_di_fll_program_standard_signal_state_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_FLL_program_h diff --git a/level_2/fll_program/c/program.c b/level_2/fll_program/c/program.c index 5457553..9c49aeb 100644 --- a/level_2/fll_program/c/program.c +++ b/level_2/fll_program/c/program.c @@ -1,4 +1,5 @@ #include "program.h" +#include "private-program.h" #ifdef __cplusplus extern "C" { @@ -362,48 +363,24 @@ extern "C" { #ifndef _di_fll_program_standard_signal_received_ f_status_t fll_program_standard_signal_received(fll_program_data_t * const main) { - if (!main || main->signal.id == -1) { - return F_false; - } - - struct signalfd_siginfo information; - - memset(&information, 0, sizeof(struct signalfd_siginfo)); + if (!main) return 0; - if (f_signal_read(main->signal, 0, &information) == F_signal) { - switch (information.ssi_signo) { - case F_signal_abort: - case F_signal_broken_pipe: - case F_signal_hangup: - case F_signal_interrupt: - case F_signal_quit: - case F_signal_termination: - main->signal_received = information.ssi_signo; - - return information.ssi_signo; - } - } - - return F_false; + return private_fll_program_standard_signal_received(main); } #endif // _di_fss_basic_read_signal_received_ #ifndef _di_fll_program_standard_signal_state_ f_status_t fll_program_standard_signal_state(void * const state, void * const internal) { - if (!state) { - return F_interrupt_not; - } + if (!state) return F_interrupt_not; f_state_t *state_ptr = (f_state_t *) state; - if (!state_ptr->custom) { - return F_interrupt_not; - } + if (!state_ptr->custom) return F_interrupt_not; fll_program_data_t *custom = (fll_program_data_t *) state_ptr->custom; - custom->signal_received = fll_program_standard_signal_received(custom); + custom->signal_received = private_fll_program_standard_signal_received(custom); if (custom->signal_received == F_signal_abort || custom->signal_received == F_signal_broken_pipe || custom->signal_received == F_signal_hangup || custom->signal_received == F_signal_interrupt || custom->signal_received == F_signal_quit || custom->signal_received == F_signal_termination) { return F_status_set_error(F_interrupt); diff --git a/level_2/fll_program/c/program.h b/level_2/fll_program/c/program.h index bdea76a..7db8b03 100644 --- a/level_2/fll_program/c/program.h +++ b/level_2/fll_program/c/program.h @@ -441,7 +441,7 @@ extern "C" { * * @return * A positive number representing a valid signal on signal received. - * F_false on no signal received or when main is NULL. + * 0 on no signal received or when main is NULL. * * @see f_signal_read() */ diff --git a/level_2/fll_program/data/build/settings b/level_2/fll_program/data/build/settings index b9365d0..45cc451 100644 --- a/level_2/fll_program/data/build/settings +++ b/level_2/fll_program/data/build/settings @@ -20,7 +20,7 @@ build_language c build_libraries -lc build_libraries-individual -lfl_print -lfl_string -lf_color -lf_console -lf_conversion -lf_file -lf_memory -lf_print -lf_signal -lf_string -lf_type_array -lf_utf -build_sources_library program.c program/common.c +build_sources_library program.c program/common.c private-program.c build_sources_headers program.h program/common.h