From 51608af1a273200222df2e6a27c8b5f7c2a6f381 Mon Sep 17 00:00:00 2001 From: Alexey Chernobaev Date: Wed, 29 Aug 2018 20:30:38 +0300 Subject: [PATCH] fputs uncommented, checks added --- profctl.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/profctl.c b/profctl.c index 7241ac4..cd48375 100644 --- a/profctl.c +++ b/profctl.c @@ -131,20 +131,25 @@ static FILE *pipef; static void *output_thread(void *arg) { - size_t lsize = 0; - char *buffer = NULL; - openFileProcess(); int linesRead = 0; + char *buffer = NULL; + size_t lsize = 0; + while (getline(&buffer, &lsize, pipef) != -1) { - fputs(buffer, data_file_out); ++linesRead; + if (fputs(buffer, data_file_out) < 0) { + log_error("fputs failed - exiting"); + break; + } } + free(buffer); if (verbose) { log_error("output thread exits (%d lines read)", linesRead); } + exit(0); } @@ -173,7 +178,9 @@ static void finish() unlink(pname); } } - fflush(data_file_out); + if (data_file_out != NULL) { + fflush(data_file_out); + } log_error("=== finished ==="); kill(getpid(), SIGKILL); } -- 2.7.4