fix: remove checking for waitpid

This commit is contained in:
Renge 2022-04-16 10:27:41 -04:00
parent 969fa07d28
commit 0c150e1f9d
2 changed files with 19 additions and 17 deletions

View File

@ -76,7 +76,11 @@ void chld_handler(int sig) {
if (WIFEXITED(status))
{
job_data_array[i]->exit_status = WEXITSTATUS(status);
job_data_array[i]->status = job_data_array[i]->exit_status == 0 ? COMPLETED : ABORTED;
job_data_array[i]->status = COMPLETED;
}
else {
job_data_array[i]->exit_status = 6;
job_data_array[i]->status = ABORTED;
}
}
}
@ -119,6 +123,8 @@ void io_handler(int sig) {
* @return 0 if finalization is completely successful, otherwise -1.
*/
int jobs_fini(void) {
store_fini();
prog_fini();
for (size_t i = 0; i < MAX_JOBS; i++)
{
if (job_data_array[i])
@ -133,9 +139,6 @@ int jobs_fini(void) {
}
}
store_fini();
prog_fini();
return 0;
}
@ -378,8 +381,7 @@ int jobs_run(PIPELINE *pline) {
for (size_t i = 0; i < size; i++)
{
int status;
if (waitpid(pids[i], &status, 0) == -1)
exit(-1);
waitpid(pids[i], &status, 0);
if (WIFEXITED(status))
exit_code = WEXITSTATUS(status);
}
@ -440,15 +442,13 @@ int jobs_wait(int jobid) {
int return_stat = -1;
if (WIFEXITED(status)) {
return_stat = WEXITSTATUS(status);
if (return_stat == 0)
{
job_data_array[jobid]->status = COMPLETED;
}
else {
job_data_array[jobid]->status = ABORTED;
}
job_data_array[jobid]->status = COMPLETED;
job_data_array[jobid]->exit_status = return_stat;
}
else {
job_data_array[jobid]->status = ABORTED;
job_data_array[jobid]->exit_status = 6;
}
return return_stat;
}
@ -503,7 +503,6 @@ int jobs_expunge(int jobid) {
if (job_data_array[jobid]->pipeline->capture_output) {
close(job_data_array[jobid]->pipe[0]);
// close(job_data_array[jobid]->pipe[1]);
}
free_pipeline(job_data_array[jobid]->pipeline);
@ -545,11 +544,14 @@ int jobs_cancel(int jobid) {
if (kill(pid, SIGKILL) == -1)
return -1;
int status;
if (waitpid(pid, &status, 0) == -1)
return -1;
waitpid(pid, &status, 0);
if (WIFEXITED(status)) {
job_data_array[jobid]->exit_status = WEXITSTATUS(status);
}
else
{
job_data_array[jobid]->exit_status = 9;
}
job_data_array[jobid]->status = CANCELED;
return 0;
}

View File

@ -31,7 +31,7 @@
*/
char *store_get_string(char *var) {
if (!var)
return -1;
return NULL;
store_data *data = store_get_data(var);
if (data)
return data->value;