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

[libvirt] [PATCH] network: fix return value of hostsFileWrite



The lone caller to hostsFileWrite (and the callers for at least 3
levels up the return stack) assume that the return value will be < 0
on failure. However, hostsFileWrite returns 0 on success, and a
positive errno on failure. This patch changes hostsFileWrite to return
-errno on failure.
---
 src/util/dnsmasq.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/util/dnsmasq.c b/src/util/dnsmasq.c
index be230e1..2ba9355 100644
--- a/src/util/dnsmasq.c
+++ b/src/util/dnsmasq.c
@@ -159,19 +159,19 @@ hostsfileWrite(const char *path,
         return rc;
 
     if (virAsprintf(&tmp, "%s.new", path) < 0)
-        return ENOMEM;
+        return -ENOMEM;
 
     if (!(f = fopen(tmp, "w"))) {
         istmp = false;
         if (!(f = fopen(path, "w"))) {
-            rc = errno;
+            rc = -errno;
             goto cleanup;
         }
     }
 
     for (i = 0; i < nhosts; i++) {
         if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
-            rc = errno;
+            rc = -errno;
             VIR_FORCE_FCLOSE(f);
 
             if (istmp)
@@ -182,19 +182,19 @@ hostsfileWrite(const char *path,
     }
 
     if (VIR_FCLOSE(f) == EOF) {
-        rc = errno;
+        rc = -errno;
         goto cleanup;
     }
 
     if (istmp) {
         if (rename(tmp, path) < 0) {
-            rc = errno;
+            rc = -errno;
             unlink(tmp);
             goto cleanup;
         }
 
         if (unlink(tmp) < 0) {
-            rc = errno;
+            rc = -errno;
             goto cleanup;
         }
     }
-- 
1.7.3.4


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