[Libvir] [PATCH] (vshCloseLogFile): Diagnose close/write failure.

Jim Meyering jim at meyering.net
Wed Nov 28 08:45:05 UTC 2007


I noticed a minor problem in vshCloseLogFile.
Although callers do check for log-file write failure,
this function doesn't check for close failure (which
can happen, and indicates a write failure).

I considered changing the function to return an int
and propagating that success/failure "up" to callers,
but that change is more invasive, and I'm not sure it's
desirable.  If any of you prefer it, let me know and
I'll rewrite accordingly:

Also slightly ugly: ctl->logfile may be null, so if/when it is
(however unlikely), the diagnostic prints "?" as the file name
rather than trying to dereference a NULL pointer.

	* src/virsh.c (vshCloseLogFile): Diagnose close/write failure.

---
 src/virsh.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/virsh.c b/src/virsh.c
index 5b50524..86f5b8b 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -4643,7 +4643,9 @@ vshCloseLogFile(vshControl *ctl)
 {
     /* log file close */
     if (ctl->log_fd >= 0) {
-        close(ctl->log_fd);
+        if (close(ctl->log_fd) < 0)
+            vshError(ctl, FALSE, _("%s: failed to write log file: %s")
+                     ctl->logfile ? ctl->logfile : "?", strerror (errno));
         ctl->log_fd = -1;
     }

--
1.5.3.6.961.gecf4




More information about the libvir-list mailing list