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 <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2015-12-04 20:35:35 +00:00
parent f5cd7383e4
commit 8fca82f148
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
2 changed files with 13 additions and 13 deletions

View file

@ -405,7 +405,7 @@ void clean_up(void)
/* Just in case there something in buffers */ /* Just in case there something in buffers */
if (fflush(NULL)) if (fflush(NULL))
error(0, 0, "clean_up: fflush"); error(EXIT_FAILURE, errno, "clean_up: fflush");
free(config.dhcpdconf_file); free(config.dhcpdconf_file);
free(config.dhcpdlease_file); free(config.dhcpdlease_file);
free(config.output_file); free(config.output_file);

View file

@ -200,12 +200,12 @@ int output_txt(void)
if (outfile == stdout) { if (outfile == stdout) {
ret = fflush(stdout); ret = fflush(stdout);
if (ret) { if (ret) {
error(0, 0, "output_txt: fflush"); error(EXIT_FAILURE, errno, "output_txt: fflush");
} }
} else { } else {
ret = close_stream(outfile); ret = close_stream(outfile);
if (ret) { 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) { if (outfile == stdout) {
ret = fflush(stdout); ret = fflush(stdout);
if (ret) { if (ret) {
error(0, 0, "output_xml: fflush"); error(EXIT_FAILURE, errno, "output_xml: fflush");
} }
} else { } else {
ret = close_stream(outfile); ret = close_stream(outfile);
if (ret) { 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) { if (outfile == stdout) {
ret = fflush(stdout); ret = fflush(stdout);
if (ret) { if (ret) {
error(0, 0, "output_json: fflush"); error(EXIT_FAILURE, errno, "output_json: fflush");
} }
} else { } else {
ret = close_stream(outfile); ret = close_stream(outfile);
if (ret) { 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) { if (outfile == stdout) {
ret = fflush(stdout); ret = fflush(stdout);
if (ret) { if (ret) {
error(0, 0, "output_html: fflush"); error(EXIT_FAILURE, errno, "output_html: fflush");
} }
} else { } else {
ret = close_stream(outfile); ret = close_stream(outfile);
if (ret) { if (ret) {
error(0, 0, "output_html: fclose"); error(EXIT_FAILURE, errno, "output_html: fclose");
} }
} }
return 0; return 0;
@ -911,12 +911,12 @@ int output_csv(void)
if (outfile == stdout) { if (outfile == stdout) {
ret = fflush(stdout); ret = fflush(stdout);
if (ret) { if (ret) {
error(0, 0, "output_cvs: fflush"); error(EXIT_FAILURE, errno, "output_cvs: fflush");
} }
} else { } else {
ret = close_stream(outfile); ret = close_stream(outfile);
if (ret) { if (ret) {
error(0, 0, "output_cvs: fclose"); error(EXIT_FAILURE, errno, "output_cvs: fclose");
} }
} }
return 0; return 0;
@ -1032,12 +1032,12 @@ int output_alarming(void)
if (outfile == stdout) { if (outfile == stdout) {
ret = fflush(stdout); ret = fflush(stdout);
if (ret) { if (ret) {
error(0, 0, "output_alarming: fflush"); error(EXIT_FAILURE, errno, "output_alarming: fflush");
} }
} else { } else {
ret = close_stream(outfile); ret = close_stream(outfile);
if (ret) { if (ret) {
error(0, 0, "output_alarming: fclose"); error(EXIT_FAILURE, errno, "output_alarming: fclose");
} }
} }
return ret_val; return ret_val;