From: Kevin Day Date: Sun, 11 Apr 2021 23:03:29 +0000 (-0500) Subject: Bugfix: child process PID is not being passed properly and child process prints failu... X-Git-Tag: 0.5.3~56 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=742599edf4d479e86f68e5ef95690fdbf67cc00c;p=fll Bugfix: child process PID is not being passed properly and child process prints failure message on terminate signal. The child process PID was not being assigned because the wrong variable was being passed. The child processes should not present error messages on exit when termination signal is received. Make sure that when the child process exists and the main thread is disabled, exit with F_signal. --- diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index e901eb9..6b8c9ae 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -1005,10 +1005,10 @@ extern "C" { const f_string_statics_t simulated_arguments = f_string_statics_t_initialize; fl_execute_parameter_t simulated_parameter = fl_macro_execute_parameter_t_initialize(execute_set->parameter.option, execute_set->parameter.wait, execute_set->parameter.environment, execute_set->parameter.signals, &simulated_program); - status = fll_execute_program(controller_default_program_script, simulated_arguments, &simulated_parameter, &execute_set->as, simulated_parameter.option & fl_execute_parameter_option_return ? (void *) &result : (void *) &id_child); + status = fll_execute_program(controller_default_program_script, simulated_arguments, &simulated_parameter, &execute_set->as, simulated_parameter.option & fl_execute_parameter_option_return ? (void *) &id_child : (void *) &result); } else { - status = fll_execute_program(program, arguments, &execute_set->parameter, &execute_set->as, execute_set->parameter.option & fl_execute_parameter_option_return ? (void *) &result : (void *) &id_child); + status = fll_execute_program(program, arguments, &execute_set->parameter, &execute_set->as, execute_set->parameter.option & fl_execute_parameter_option_return ? (void *) &id_child : (void *) &result); } if (status == F_parent) { @@ -1037,14 +1037,12 @@ extern "C" { // have the parent wait for the child process to finish. waitpid(id_child, &result, 0); - if (!main.thread->enabled) { - f_thread_unlock(&process->lock); + f_thread_unlock(&process->lock); + if (!main.thread->enabled) { return F_signal; } - f_thread_unlock(&process->lock); - status = controller_lock_write(main.thread, &process->lock); if (status == F_signal) { @@ -1068,6 +1066,11 @@ extern "C" { status = F_status_set_error(F_failure); } } + else { + if (!main.thread->enabled) { + return F_signal; + } + } if (F_status_is_error(status)) { status = F_status_set_fine(status); @@ -1080,8 +1083,8 @@ extern "C" { } } - if (status == F_child) { - return F_child; + if (status == F_child || status == F_signal) { + return status; } if (result != 0) { @@ -1117,7 +1120,7 @@ extern "C" { f_status_t status = F_none; int result = 0; - pid_t id_process = 0; + pid_t id_child = 0; // @todo check to see if pid file exists. @@ -1155,10 +1158,10 @@ extern "C" { const f_string_statics_t simulated_arguments = f_string_statics_t_initialize; fl_execute_parameter_t simulated_parameter = fl_macro_execute_parameter_t_initialize(execute_set->parameter.option, execute_set->parameter.wait, execute_set->parameter.environment, execute_set->parameter.signals, &simulated_program); - status = fll_execute_program(controller_default_program_script, simulated_arguments, &simulated_parameter, &execute_set->as, simulated_parameter.option & fl_execute_parameter_option_return ? (void *) &result : (void *) &id_process); + status = fll_execute_program(controller_default_program_script, simulated_arguments, &simulated_parameter, &execute_set->as, simulated_parameter.option & fl_execute_parameter_option_return ? (void *) &id_child : (void *) &result); } else { - status = fll_execute_program(program, arguments, &execute_set->parameter, &execute_set->as, execute_set->parameter.option & fl_execute_parameter_option_return ? (void *) &result : (void *) &id_process); + status = fll_execute_program(program, arguments, &execute_set->parameter, &execute_set->as, execute_set->parameter.option & fl_execute_parameter_option_return ? (void *) &id_child : (void *) &result); } if (status == F_parent) { @@ -1179,22 +1182,20 @@ extern "C" { } // assign the child process id to allow for the cancel process to send appropriate termination signals to the child process. - process->child = id_process; + process->child = id_child; f_thread_unlock(&process->lock); f_thread_lock_read(&process->lock); // have the parent wait for the child process to finish. @todo do not wait, this is a background execution! - waitpid(id_process, &result, 0); + waitpid(id_child, &result, 0); - if (!main.thread->enabled) { - f_thread_unlock(&process->lock); + f_thread_unlock(&process->lock); + if (!main.thread->enabled) { return F_signal; } - f_thread_unlock(&process->lock); - status = controller_lock_write(main.thread, &process->lock); if (status == F_signal) { @@ -1218,6 +1219,11 @@ extern "C" { status = F_status_set_error(F_failure); } } + else { + if (!main.thread->enabled) { + return F_signal; + } + } if (F_status_is_error(status)) { status = F_status_set_fine(status); @@ -1230,8 +1236,8 @@ extern "C" { } } - if (status == F_child) { - return F_child; + if (status == F_child || status == F_signal) { + return status; } if (result != 0) {