From 8fca82f148fcf227e655591410f11e85d2edadb1 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 4 Dec 2015 20:35:35 +0000 Subject: [PATCH] print include system error message when output fails Users want to know why write fail - was it because disk full, or destination read-only, or IO error, and so on. Signed-off-by: Sami Kerola --- src/other.c | 2 +- src/output.c | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/other.c b/src/other.c index 91cde58..f4cf877 100644 --- a/src/other.c +++ b/src/other.c @@ -405,7 +405,7 @@ void clean_up(void) /* Just in case there something in buffers */ if (fflush(NULL)) - error(0, 0, "clean_up: fflush"); + error(EXIT_FAILURE, errno, "clean_up: fflush"); free(config.dhcpdconf_file); free(config.dhcpdlease_file); free(config.output_file); diff --git a/src/output.c b/src/output.c index 2574d18..203fd65 100644 --- a/src/output.c +++ b/src/output.c @@ -200,12 +200,12 @@ int output_txt(void) if (outfile == stdout) { ret = fflush(stdout); if (ret) { - error(0, 0, "output_txt: fflush"); + error(EXIT_FAILURE, errno, "output_txt: fflush"); } } else { ret = close_stream(outfile); if (ret) { - error(0, 0, "output_txt: fclose"); + error(EXIT_FAILURE, errno, "output_txt: fclose"); } } @@ -303,12 +303,12 @@ int output_xml(void) if (outfile == stdout) { ret = fflush(stdout); if (ret) { - error(0, 0, "output_xml: fflush"); + error(EXIT_FAILURE, errno, "output_xml: fflush"); } } else { ret = close_stream(outfile); if (ret) { - error(0, 0, "output_xml: fclose"); + error(EXIT_FAILURE, errno, "output_xml: fclose"); } } @@ -440,12 +440,12 @@ int output_json(void) if (outfile == stdout) { ret = fflush(stdout); if (ret) { - error(0, 0, "output_json: fflush"); + error(EXIT_FAILURE, errno, "output_json: fflush"); } } else { ret = close_stream(outfile); if (ret) { - error(0, 0, "output_json: fclose"); + error(EXIT_FAILURE, errno, "output_json: fclose"); } } @@ -769,12 +769,12 @@ int output_html(void) if (outfile == stdout) { ret = fflush(stdout); if (ret) { - error(0, 0, "output_html: fflush"); + error(EXIT_FAILURE, errno, "output_html: fflush"); } } else { ret = close_stream(outfile); if (ret) { - error(0, 0, "output_html: fclose"); + error(EXIT_FAILURE, errno, "output_html: fclose"); } } return 0; @@ -911,12 +911,12 @@ int output_csv(void) if (outfile == stdout) { ret = fflush(stdout); if (ret) { - error(0, 0, "output_cvs: fflush"); + error(EXIT_FAILURE, errno, "output_cvs: fflush"); } } else { ret = close_stream(outfile); if (ret) { - error(0, 0, "output_cvs: fclose"); + error(EXIT_FAILURE, errno, "output_cvs: fclose"); } } return 0; @@ -1032,12 +1032,12 @@ int output_alarming(void) if (outfile == stdout) { ret = fflush(stdout); if (ret) { - error(0, 0, "output_alarming: fflush"); + error(EXIT_FAILURE, errno, "output_alarming: fflush"); } } else { ret = close_stream(outfile); if (ret) { - error(0, 0, "output_alarming: fclose"); + error(EXIT_FAILURE, errno, "output_alarming: fclose"); } } return ret_val;