From 135be3a8a0a414a47c07b6b91149ee5172693f46 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 22 Dec 2021 21:07:15 -0600 Subject: [PATCH] Bugfix: Signal id should be -1 the id should be passed to signalfd(). A file descriptor should be set to -1 and not 0. The 0 file descriptor is actually valid. The signalfd() program accepts an id. It makes sense to pass this along rather than always forcing -1. --- level_0/f_signal/c/signal-common.h | 4 ++-- level_0/f_signal/c/signal.c | 2 +- level_0/f_signal/c/signal.h | 3 +++ level_3/byte_dump/c/private-common.c | 2 +- level_3/control/c/private-common.c | 2 +- level_3/fake/c/private-common.c | 2 +- level_3/firewall/c/private-common.c | 2 +- level_3/fss_basic_list_read/c/private-common.c | 2 +- level_3/fss_basic_list_write/c/private-common.c | 2 +- level_3/fss_basic_read/c/private-common.c | 2 +- level_3/fss_basic_write/c/private-common.c | 2 +- level_3/fss_embedded_list_read/c/private-common.c | 2 +- level_3/fss_embedded_list_write/c/private-common.c | 2 +- level_3/fss_extended_list_read/c/private-common.c | 2 +- level_3/fss_extended_list_write/c/private-common.c | 2 +- level_3/fss_extended_read/c/private-common.c | 2 +- level_3/fss_extended_write/c/private-common.c | 2 +- level_3/fss_identify/c/private-common.c | 2 +- level_3/fss_status_code/c/private-common.c | 2 +- level_3/iki_read/c/private-common.c | 2 +- level_3/iki_write/c/private-common.c | 2 +- level_3/status_code/c/private-common.c | 2 +- 22 files changed, 25 insertions(+), 22 deletions(-) diff --git a/level_0/f_signal/c/signal-common.h b/level_0/f_signal/c/signal-common.h index b9c8415..8d3d67d 100644 --- a/level_0/f_signal/c/signal-common.h +++ b/level_0/f_signal/c/signal-common.h @@ -30,13 +30,13 @@ extern "C" { sigset_t set; } f_signal_t; - #define f_signal_t_initialize {0, 0, { 0 } } + #define f_signal_t_initialize {0, -1, { 0 } } #define macro_f_signal_t_initialize(flags, id, set) { flags, id, set } #define macro_f_signal_t_clear(signal) \ signal.flags = 0; \ - signal.id = 0; \ + signal.id = -1; \ signal.set[0] = 0; #endif // _di_f_signal_t_ diff --git a/level_0/f_signal/c/signal.c b/level_0/f_signal/c/signal.c index 0bdeb85..e2ffaaa 100644 --- a/level_0/f_signal/c/signal.c +++ b/level_0/f_signal/c/signal.c @@ -35,7 +35,7 @@ extern "C" { if (!signal) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - int result = signalfd(-1, &signal->set, signal->flags); + const int result = signalfd(signal->id, &signal->set, signal->flags); if (result < 0) { if (errno == EINVAL) return F_status_set_error(F_parameter); diff --git a/level_0/f_signal/c/signal.h b/level_0/f_signal/c/signal.h index c0563df..62580a2 100644 --- a/level_0/f_signal/c/signal.h +++ b/level_0/f_signal/c/signal.h @@ -60,6 +60,9 @@ extern "C" { * @param signal * The signal settings. * + * If signal.id is -1, then a new file descriptor is created. + * Otherwise, signal.id is used as the file descriptor. + * * @return * F_none on success but no signal found. * F_device (with error bit) if could not mount the internal inode device. diff --git a/level_3/byte_dump/c/private-common.c b/level_3/byte_dump/c/private-common.c index 15a0a16..1c2bf8a 100644 --- a/level_3/byte_dump/c/private-common.c +++ b/level_3/byte_dump/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_byte_dump_signal_received_ f_status_t byte_dump_signal_received(byte_dump_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/control/c/private-common.c b/level_3/control/c/private-common.c index 92941da..a32fd1f 100644 --- a/level_3/control/c/private-common.c +++ b/level_3/control/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_control_signal_received_ f_status_t control_signal_received(control_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fake/c/private-common.c b/level_3/fake/c/private-common.c index 3ac996e..4ed9784 100644 --- a/level_3/fake/c/private-common.c +++ b/level_3/fake/c/private-common.c @@ -258,7 +258,7 @@ extern "C" { #ifndef _di_fake_signal_received_ f_status_t fake_signal_received(fake_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/firewall/c/private-common.c b/level_3/firewall/c/private-common.c index 07a4227..ee858fd 100644 --- a/level_3/firewall/c/private-common.c +++ b/level_3/firewall/c/private-common.c @@ -96,7 +96,7 @@ void firewall_print_error_on_unhandled_for_file(const fl_print_t output, const f #ifndef _di_firewall_signal_received_ f_status_t firewall_signal_received(firewall_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_basic_list_read/c/private-common.c b/level_3/fss_basic_list_read/c/private-common.c index aa8bfbb..14ddedd 100644 --- a/level_3/fss_basic_list_read/c/private-common.c +++ b/level_3/fss_basic_list_read/c/private-common.c @@ -78,7 +78,7 @@ extern "C" { #ifndef _di_fss_basic_list_read_signal_received_ f_status_t fss_basic_list_read_signal_received(fss_basic_list_read_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_basic_list_write/c/private-common.c b/level_3/fss_basic_list_write/c/private-common.c index 5cea228..bf46868 100644 --- a/level_3/fss_basic_list_write/c/private-common.c +++ b/level_3/fss_basic_list_write/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_fss_basic_list_write_signal_received_ f_status_t fss_basic_list_write_signal_received(fss_basic_list_write_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_basic_read/c/private-common.c b/level_3/fss_basic_read/c/private-common.c index 26d9f3b..276e786 100644 --- a/level_3/fss_basic_read/c/private-common.c +++ b/level_3/fss_basic_read/c/private-common.c @@ -77,7 +77,7 @@ extern "C" { #ifndef _di_fss_basic_read_signal_received_ f_status_t fss_basic_read_signal_received(fss_basic_read_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_basic_write/c/private-common.c b/level_3/fss_basic_write/c/private-common.c index 66cad09..c253bdc 100644 --- a/level_3/fss_basic_write/c/private-common.c +++ b/level_3/fss_basic_write/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_fss_basic_write_signal_received_ f_status_t fss_basic_write_signal_received(fss_basic_write_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_embedded_list_read/c/private-common.c b/level_3/fss_embedded_list_read/c/private-common.c index 68cb82a..3f211cd 100644 --- a/level_3/fss_embedded_list_read/c/private-common.c +++ b/level_3/fss_embedded_list_read/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_fss_embedded_list_read_signal_received_ f_status_t fss_embedded_list_read_signal_received(fss_embedded_list_read_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_embedded_list_write/c/private-common.c b/level_3/fss_embedded_list_write/c/private-common.c index c90e4f9..edbc4bb 100644 --- a/level_3/fss_embedded_list_write/c/private-common.c +++ b/level_3/fss_embedded_list_write/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_fss_embedded_list_write_signal_received_ f_status_t fss_embedded_list_write_signal_received(fss_embedded_list_write_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_extended_list_read/c/private-common.c b/level_3/fss_extended_list_read/c/private-common.c index 97e73b0..49ff1b5 100644 --- a/level_3/fss_extended_list_read/c/private-common.c +++ b/level_3/fss_extended_list_read/c/private-common.c @@ -78,7 +78,7 @@ extern "C" { #ifndef _di_fss_extended_list_read_signal_received_ f_status_t fss_extended_list_read_signal_received(fss_extended_list_read_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_extended_list_write/c/private-common.c b/level_3/fss_extended_list_write/c/private-common.c index af21cd3..b588c36 100644 --- a/level_3/fss_extended_list_write/c/private-common.c +++ b/level_3/fss_extended_list_write/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_fss_extended_list_write_signal_received_ f_status_t fss_extended_list_write_signal_received(fss_extended_list_write_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_extended_read/c/private-common.c b/level_3/fss_extended_read/c/private-common.c index 65b7482..2ca7672 100644 --- a/level_3/fss_extended_read/c/private-common.c +++ b/level_3/fss_extended_read/c/private-common.c @@ -79,7 +79,7 @@ extern "C" { #ifndef _di_fss_extended_read_signal_received_ f_status_t fss_extended_read_signal_received(fss_extended_read_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_extended_write/c/private-common.c b/level_3/fss_extended_write/c/private-common.c index dd095ea..da04e4a 100644 --- a/level_3/fss_extended_write/c/private-common.c +++ b/level_3/fss_extended_write/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_fss_extended_write_signal_received_ f_status_t fss_extended_write_signal_received(fss_extended_write_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_identify/c/private-common.c b/level_3/fss_identify/c/private-common.c index dcf1eaa..81a8d30 100644 --- a/level_3/fss_identify/c/private-common.c +++ b/level_3/fss_identify/c/private-common.c @@ -35,7 +35,7 @@ extern "C" { #ifndef _di_fss_identify_signal_received_ f_status_t fss_identify_signal_received(fss_identify_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/fss_status_code/c/private-common.c b/level_3/fss_status_code/c/private-common.c index 3d12c1e..b1b0e67 100644 --- a/level_3/fss_status_code/c/private-common.c +++ b/level_3/fss_status_code/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_fss_status_code_signal_received_ f_status_t fss_status_code_signal_received(fss_status_code_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/iki_read/c/private-common.c b/level_3/iki_read/c/private-common.c index dd4af45..1a135e4 100644 --- a/level_3/iki_read/c/private-common.c +++ b/level_3/iki_read/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_iki_read_signal_received_ f_status_t iki_read_signal_received(iki_read_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/iki_write/c/private-common.c b/level_3/iki_write/c/private-common.c index 3eb1880..8083e83 100644 --- a/level_3/iki_write/c/private-common.c +++ b/level_3/iki_write/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_iki_write_signal_received_ f_status_t iki_write_signal_received(iki_write_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } diff --git a/level_3/status_code/c/private-common.c b/level_3/status_code/c/private-common.c index 132f650..55b9867 100644 --- a/level_3/status_code/c/private-common.c +++ b/level_3/status_code/c/private-common.c @@ -26,7 +26,7 @@ extern "C" { #ifndef _di_status_code_signal_received_ f_status_t status_code_signal_received(status_code_main_t * const main) { - if (!main->signal.id) { + if (main->signal.id == -1) { return F_false; } -- 1.8.3.1