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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]