From f05cd13c723ba1f4a4f393884dcc118c9c0a6851 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 13 Dec 2020 19:44:59 -0600 Subject: [PATCH] Bugfix: closing the before at the end of the program can cause output pipe never to send. Make sure that the output pipes (output buffers) are flushed before closing. --- level_3/byte_dump/c/main.c | 4 ++++ level_3/control/c/main.c | 4 ++++ level_3/controller/c/main.c | 4 ++++ level_3/fake/c/main.c | 4 ++++ level_3/fss_basic_list_read/c/main.c | 4 ++++ level_3/fss_basic_list_write/c/main.c | 4 ++++ level_3/fss_basic_read/c/main.c | 4 ++++ level_3/fss_basic_write/c/main.c | 4 ++++ level_3/fss_embedded_list_read/c/main.c | 4 ++++ level_3/fss_embedded_list_write/c/main.c | 4 ++++ level_3/fss_extended_list_read/c/main.c | 4 ++++ level_3/fss_extended_list_write/c/main.c | 4 ++++ level_3/fss_extended_read/c/main.c | 4 ++++ level_3/fss_extended_write/c/main.c | 4 ++++ level_3/fss_status_code/c/main.c | 4 ++++ level_3/iki_read/c/main.c | 4 ++++ level_3/iki_write/c/main.c | 4 ++++ level_3/init/c/main.c | 4 ++++ level_3/status_code/c/main.c | 4 ++++ 19 files changed, 76 insertions(+) diff --git a/level_3/byte_dump/c/main.c b/level_3/byte_dump/c/main.c index 1714422..3d6d910 100644 --- a/level_3/byte_dump/c/main.c +++ b/level_3/byte_dump/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = byte_dump_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/control/c/main.c b/level_3/control/c/main.c index b0da32a..956ba14 100644 --- a/level_3/control/c/main.c +++ b/level_3/control/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = control_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/controller/c/main.c b/level_3/controller/c/main.c index d9cde60..9a5eef3 100644 --- a/level_3/controller/c/main.c +++ b/level_3/controller/c/main.c @@ -12,6 +12,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = controller_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fake/c/main.c b/level_3/fake/c/main.c index bf9a47e..1091ef4 100644 --- a/level_3/fake/c/main.c +++ b/level_3/fake/c/main.c @@ -45,6 +45,10 @@ int main(const unsigned long argc, const f_string_t *argv) { f_signal_close(&data.signal); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_basic_list_read/c/main.c b/level_3/fss_basic_list_read/c/main.c index c7119c8..aed5e66 100644 --- a/level_3/fss_basic_list_read/c/main.c +++ b/level_3/fss_basic_list_read/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_basic_list_read_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_basic_list_write/c/main.c b/level_3/fss_basic_list_write/c/main.c index 8821ae6..7d8ed20 100644 --- a/level_3/fss_basic_list_write/c/main.c +++ b/level_3/fss_basic_list_write/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_basic_list_write_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_basic_read/c/main.c b/level_3/fss_basic_read/c/main.c index 525f9a8..d6a5479 100644 --- a/level_3/fss_basic_read/c/main.c +++ b/level_3/fss_basic_read/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_basic_read_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_basic_write/c/main.c b/level_3/fss_basic_write/c/main.c index 3e3b56b..f425c45 100644 --- a/level_3/fss_basic_write/c/main.c +++ b/level_3/fss_basic_write/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_basic_write_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_embedded_list_read/c/main.c b/level_3/fss_embedded_list_read/c/main.c index 7cd347c..5e459fb 100644 --- a/level_3/fss_embedded_list_read/c/main.c +++ b/level_3/fss_embedded_list_read/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_embedded_list_read_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_embedded_list_write/c/main.c b/level_3/fss_embedded_list_write/c/main.c index d194dfb..8847680 100644 --- a/level_3/fss_embedded_list_write/c/main.c +++ b/level_3/fss_embedded_list_write/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_embedded_list_write_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_extended_list_read/c/main.c b/level_3/fss_extended_list_read/c/main.c index c1d0383..6d750b2 100644 --- a/level_3/fss_extended_list_read/c/main.c +++ b/level_3/fss_extended_list_read/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_extended_list_read_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_extended_list_write/c/main.c b/level_3/fss_extended_list_write/c/main.c index d543498..bb11a76 100644 --- a/level_3/fss_extended_list_write/c/main.c +++ b/level_3/fss_extended_list_write/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_extended_list_write_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_extended_read/c/main.c b/level_3/fss_extended_read/c/main.c index d9c3ea9..d4bf3e5 100644 --- a/level_3/fss_extended_read/c/main.c +++ b/level_3/fss_extended_read/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_extended_read_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_extended_write/c/main.c b/level_3/fss_extended_write/c/main.c index 4eee1d6..fbadc6e 100644 --- a/level_3/fss_extended_write/c/main.c +++ b/level_3/fss_extended_write/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_extended_write_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/fss_status_code/c/main.c b/level_3/fss_status_code/c/main.c index a668c81..1880cb0 100644 --- a/level_3/fss_status_code/c/main.c +++ b/level_3/fss_status_code/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = fss_status_code_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/iki_read/c/main.c b/level_3/iki_read/c/main.c index 0a7f6b4..2b91ba5 100644 --- a/level_3/iki_read/c/main.c +++ b/level_3/iki_read/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = iki_read_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/iki_write/c/main.c b/level_3/iki_write/c/main.c index 08a68b7..b1614de 100644 --- a/level_3/iki_write/c/main.c +++ b/level_3/iki_write/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = iki_write_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/init/c/main.c b/level_3/init/c/main.c index cd1282b..d10b1a0 100644 --- a/level_3/init/c/main.c +++ b/level_3/init/c/main.c @@ -28,6 +28,10 @@ int main(const unsigned long argc, const f_string_t *argv) { f_signal_close(&data.signal); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); diff --git a/level_3/status_code/c/main.c b/level_3/status_code/c/main.c index 1126a88..0dd8145 100644 --- a/level_3/status_code/c/main.c +++ b/level_3/status_code/c/main.c @@ -10,6 +10,10 @@ int main(const unsigned long argc, const f_string_t *argv) { const f_status_t status = status_code_main(arguments, &data); + // flush output pipes before closing. + fflush(f_type_output); + fflush(f_type_error); + // close all open file descriptors. close(f_type_descriptor_output); close(f_type_descriptor_input); -- 1.8.3.1