From: Daniel P. Berrangé <[email protected]>

When writing the dnsmasq hosts file to a temporary file, there
is a fallback which tries to open the original file. We expect
creating the temporary file to always succeed, and if it fails
something serious has gone wrong that we want to have reported.
So this fallback is expected to be dead code.

Signed-off-by: Daniel P. Berrangé <[email protected]>
---
 src/util/virdnsmasq.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 656665e174..7bb1188516 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -320,7 +320,6 @@ hostsfileWrite(const char *path,
 {
     g_autofree char *tmp = NULL;
     FILE *f;
-    bool istmp = true;
     size_t i;
     int rc = 0;
 
@@ -331,19 +330,14 @@ hostsfileWrite(const char *path,
     tmp = g_strdup_printf("%s.new", path);
 
     if (!(f = fopen(tmp, "w"))) {
-        istmp = false;
-        if (!(f = fopen(path, "w")))
-            return -errno;
+        return -errno;
     }
 
     for (i = 0; i < nhosts; i++) {
         if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
             rc = -errno;
             VIR_FORCE_FCLOSE(f);
-
-            if (istmp)
-                unlink(tmp);
-
+            unlink(tmp);
             return rc;
         }
     }
@@ -351,7 +345,7 @@ hostsfileWrite(const char *path,
     if (VIR_FCLOSE(f) == EOF)
         return -errno;
 
-    if (istmp && rename(tmp, path) < 0) {
+    if (rename(tmp, path) < 0) {
         rc = -errno;
         unlink(tmp);
         return rc;
-- 
2.56.0

Reply via email to