From e27119ba171a083ed0b41d4b499212106e8c6819 Mon Sep 17 00:00:00 2001 From: Renge Date: Fri, 15 Apr 2022 21:13:14 -0400 Subject: [PATCH] fix: bug in io_handler --- hw4/src/jobs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw4/src/jobs.c b/hw4/src/jobs.c index 25be457..58baf9b 100644 --- a/hw4/src/jobs.c +++ b/hw4/src/jobs.c @@ -92,9 +92,12 @@ void io_handler(int sig) { if (job_data_array[i]->pipeline->capture_output) { char c; - while (read(job_data_array[i]->pipe[0], &c, sizeof(char)) && - read(job_data_array[i]->pipe[0], &c, sizeof(char)) != -1) + while (1) { + int num = read(job_data_array[i]->pipe[0], &c, sizeof(char)); + if (num == 0 || num == -1) { + break; + } job_data_array[i]->output_length ++; job_data_array[i]->output = realloc(job_data_array[i]->output, (job_data_array[i]->output_length + 1) * sizeof(char)); job_data_array[i]->output[job_data_array[i]->output_length - 1] = c;