From 137aa0830908f1f4b50286b604e5e440256ac2b2 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 26 Mar 2025 20:18:50 -0500 Subject: [PATCH] Progress: Continue working on completing the remove program. Use polling on the standard input to allow for blocking in an interruptible way. Once there is input the file read can be called to read the input. This finishes the `remove` program development. I am still designating this as progress because the following wrapper programs now need to be written: - `rm` - `rmdir` - `unlink` --- data/build/stand_alone/configs/remove-config.h | 6 ++--- .../kevux/tools/remove/main/common/define.h | 7 ++++- .../program/kevux/tools/remove/main/common/print.c | 1 + .../program/kevux/tools/remove/main/common/print.h | 1 + .../program/kevux/tools/remove/main/common/type.c | 2 ++ .../program/kevux/tools/remove/main/common/type.h | 4 +++ .../c/program/kevux/tools/remove/main/operate.c | 30 +++++++++++++++++++++- 7 files changed, 46 insertions(+), 5 deletions(-) diff --git a/data/build/stand_alone/configs/remove-config.h b/data/build/stand_alone/configs/remove-config.h index 8d58a0f..477372b 100644 --- a/data/build/stand_alone/configs/remove-config.h +++ b/data/build/stand_alone/configs/remove-config.h @@ -400,7 +400,7 @@ #define _di_f_file_operation_wipe_s_ #define _di_f_file_operation_write_s_ #define _di_f_file_owner_read_ -#define _di_f_file_poll_ +//#define _di_f_file_poll_ #define _di_f_file_read_ //#define _di_f_file_read_block_ #define _di_f_file_read_until_ @@ -537,9 +537,9 @@ #define _di_f_pipe_error_exists_ //#define _di_f_pipe_input_exists_ #define _di_f_pipe_output_exists_ -#define _di_f_poll_e_ +//#define _di_f_poll_e_ //#define _di_f_poll_t_ -#define _di_f_polls_t_ +//#define _di_f_polls_t_ #define _di_f_pollss_delete_callback_ #define _di_f_pollss_destroy_callback_ #define _di_f_pollss_t_ diff --git a/sources/c/program/kevux/tools/remove/main/common/define.h b/sources/c/program/kevux/tools/remove/main/common/define.h index 3f0af2e..6ce4908 100644 --- a/sources/c/program/kevux/tools/remove/main/common/define.h +++ b/sources/c/program/kevux/tools/remove/main/common/define.h @@ -20,7 +20,10 @@ extern "C" { * The program defines. * * Leap Year: - * - If can be evenly divided by 4, then this is a leap year. (@fixme relocate or move "Leap Year" comments where appropriate.) + * - If can be evenly divided by 4, then this is a leap year. (@fixme relocate or move "Leap Year" comments where appropriate + * + * kt_remove_poll_*_d: + * - timeout: The time in milliseconds to block, waiting for a poll response. * * kt_remove_depth_*_d: * - max: The maximum recursion depth to perform when recursing into a directory. @@ -43,6 +46,8 @@ extern "C" { #ifndef _di_kt_remove_d_ #define kt_remove_depth_max_d F_directory_max_recurse_depth_d + #define kt_remove_poll_timeout_d 200 + #define kt_remove_signal_check_d 20000 #define kt_remove_signal_check_failsafe_d 20000 diff --git a/sources/c/program/kevux/tools/remove/main/common/print.c b/sources/c/program/kevux/tools/remove/main/common/print.c index 8e214d8..6d7d715 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.c +++ b/sources/c/program/kevux/tools/remove/main/common/print.c @@ -11,6 +11,7 @@ extern "C" { "f_directory_remove", "f_file_mode_from_string", "f_file_mode_to_mode", + "f_file_poll", "f_file_read_block", "f_file_remove", "f_memory_array_increase", diff --git a/sources/c/program/kevux/tools/remove/main/common/print.h b/sources/c/program/kevux/tools/remove/main/common/print.h index 968edb6..c72df87 100644 --- a/sources/c/program/kevux/tools/remove/main/common/print.h +++ b/sources/c/program/kevux/tools/remove/main/common/print.h @@ -44,6 +44,7 @@ extern "C" { kt_remove_f_f_directory_remove_e, kt_remove_f_f_file_mode_from_string_e, kt_remove_f_f_file_mode_to_mode_e, + kt_remove_f_f_file_poll_e, kt_remove_f_f_file_read_block_e, kt_remove_f_f_file_remove_e, kt_remove_f_f_memory_array_increase_e, diff --git a/sources/c/program/kevux/tools/remove/main/common/type.c b/sources/c/program/kevux/tools/remove/main/common/type.c index 3a459bb..39e5fcd 100644 --- a/sources/c/program/kevux/tools/remove/main/common/type.c +++ b/sources/c/program/kevux/tools/remove/main/common/type.c @@ -9,6 +9,8 @@ extern "C" { if (!cache) return; + f_memory_array_resize(0, sizeof(f_polls_t), (void **) &cache->polls.array, &cache->polls.used, &cache->polls.size); + f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size); f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->input.string, &cache->input.used, &cache->input.size); diff --git a/sources/c/program/kevux/tools/remove/main/common/type.h b/sources/c/program/kevux/tools/remove/main/common/type.h index d27a724..9c38df5 100644 --- a/sources/c/program/kevux/tools/remove/main/common/type.h +++ b/sources/c/program/kevux/tools/remove/main/common/type.h @@ -140,6 +140,7 @@ extern "C" { /** * The program cache. * + * polls: An array of poll structures. * buffer: The generic buffer. * input: The buffer used specifically for handling input. * files: A collection of files, often used during path recursion like those associated with the tree parameter. @@ -148,6 +149,8 @@ extern "C" { */ #ifndef _di_kt_remove_cache_t_ typedef struct { + f_polls_t polls; + f_string_dynamic_t buffer; f_string_dynamic_t input; f_string_dynamics_t files; @@ -157,6 +160,7 @@ extern "C" { #define kt_remove_cache_t_initialize \ { \ + f_polls_t_initialize, \ f_string_dynamic_t_initialize, \ f_string_dynamic_t_initialize, \ f_string_dynamics_t_initialize, \ diff --git a/sources/c/program/kevux/tools/remove/main/operate.c b/sources/c/program/kevux/tools/remove/main/operate.c index 4d1af67..c5d677e 100644 --- a/sources/c/program/kevux/tools/remove/main/operate.c +++ b/sources/c/program/kevux/tools/remove/main/operate.c @@ -164,7 +164,35 @@ extern "C" { kt_remove_print_message_remove_confirm(&main->program.message, path); - // @todo This does not work well with interrupts, so another f_file_read_block_interrupt() needs to be created in the FLL project (or add interrupt callback to each f_file_read function). + if (!main->cache.polls.size) { + main->setting.state.status = f_memory_array_increase(1, sizeof(f_poll_t), (void **) &main->cache.polls.array, &main->cache.polls.used, &main->cache.polls.size); + + if (F_status_is_error(main->setting.state.status)) { + kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_memory_array_increase)); + + return; + } + + // This is only every used here so assign this once and never again. + main->cache.polls.array[0].fd = main->program.input.id; + main->cache.polls.array[0].events = f_poll_read_e; + main->cache.polls.array[0].revents = 0; + main->cache.polls.used = 1; + } + + // Use polling to read input while allowing interrupt signals to be received (the read() function blocks signals). + do { + main->setting.state.status = f_file_poll(main->cache.polls, kt_remove_poll_timeout_d); + + if (F_status_is_error(main->setting.state.status)) { + kt_remove_print_error(&main->program.error, macro_kt_remove_f(f_file_poll)); + + return; + } + + if (kt_remove_signal_check(main)) return; + } while (F_status_set_fine(main->setting.state.status) == F_time_out); + main->setting.state.status = f_file_read_block(main->program.input, &main->cache.input); if (F_status_is_error(main->setting.state.status)) { -- 1.8.3.1