]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use FDWrapper, modify its reset() to return the close() return value
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 25 Mar 2024 14:40:30 +0000 (15:40 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 25 Mar 2024 14:40:30 +0000 (15:40 +0100)
pdns/misc.hh
pdns/recursordist/nod.cc

index cd7e607ef1c784fd6a087c1456f3c4f4e8d94d91..7798ada49b056d39a67120c7719d126a32295a21 100644 (file)
@@ -821,12 +821,14 @@ struct FDWrapper
     return d_fd;
   }
 
-  void reset()
+  int reset()
   {
+    int ret = 0;
     if (d_fd != -1) {
-      ::close(d_fd);
+      ret = close(d_fd);
       d_fd = -1;
     }
+    return ret;
   }
 
 private:
index 75aed78a056c49b047a5f8f901f4f9a3f229eb95..9e4c1dfa730e5aa715db230aeb24a3819f2b91f0 100644 (file)
@@ -145,18 +145,17 @@ bool PersistentSBF::snapshotCurrent(std::thread::id tid)
         }
         // Now write it out to the file
         std::string ftmp = file.string() + ".XXXXXXXX";
-        int fileDesc = mkstemp(ftmp.data());
+        auto fileDesc = FDWrapper(mkstemp(ftmp.data()));
         if (fileDesc == -1) {
           throw std::runtime_error("Cannot create temp file: " + stringerror());
         }
         const std::string str = oss.str(); // XXX creates a copy, with c++20 we can use view()
         ssize_t len = write(fileDesc, str.data(), str.length());
         if (len != static_cast<ssize_t>(str.length())) {
-          close(fileDesc);
           filesystem::remove(ftmp.c_str());
           throw std::runtime_error("Failed to write to file:" + ftmp);
         }
-        if (close(fileDesc) != 0) {
+        if (fileDesc.reset() != 0) {
           filesystem::remove(ftmp);
           throw std::runtime_error("Failed to write to file:" + ftmp);
         }