[PATCH] dc-rhev-image: always detect/diagnose write failure

Jim Meyering jim at meyering.net
Wed Mar 23 18:55:39 UTC 2011


Hi Pete,
I noticed that dc-rhev-image did not call closeout,
yet does write to stdout.

That means if that write fails with say EIO or ENOSPC,
the program will fail to do its job yet still exit successfully.
You can test by redirecting its output to /dev/full.
It should detect the ENOSPC error and diagnose it,
but currently it does not.

This patch fixes that:

>From 1715bd84975f466b058589e9bd0c423eeee4692d Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 23 Mar 2011 19:52:11 +0100
Subject: [PATCH] dc-rhev-image: always detect/diagnose write failure

* dc-rhev-image.c: Include "closeout.h" and "progname.h".
(main): Call set_program_name and arrange for close_stdout to
be called on exit.
---
 dc-rhev-image.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/dc-rhev-image.c b/dc-rhev-image.c
index aff22fa..65ccd4c 100644
--- a/dc-rhev-image.c
+++ b/dc-rhev-image.c
@@ -45,7 +45,9 @@

 #include "base64.h"
 #include "close-stream.h"
+#include "closeout.h"
 #include "copy-file.h"
+#include "progname.h"

 /*
  * Note that we almost never prefix with TAG due to compatibility with EC2.
@@ -1482,6 +1484,9 @@ int main(int argc, char **argv, char **envp)
 	struct stor_dom *sd;
 	char uuidbuf[37];

+	set_program_name (argv[0]);
+	atexit (close_stdout);
+
 	env_p = envp;

 	if (argc == 1) {
--
1.7.4.1.586.g18336


More information about the iwhd-devel mailing list