From: Otto Moerbeek Date: Mon, 25 Mar 2024 14:40:30 +0000 (+0100) Subject: Use FDWrapper, modify its reset() to return the close() return value X-Git-Tag: rec-5.1.0-alpha1~77^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f17d18876b98c1aaeb84e2f3c3af769be70dc28;p=thirdparty%2Fpdns.git Use FDWrapper, modify its reset() to return the close() return value --- diff --git a/pdns/misc.hh b/pdns/misc.hh index cd7e607ef1..7798ada49b 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -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: diff --git a/pdns/recursordist/nod.cc b/pdns/recursordist/nod.cc index 75aed78a05..9e4c1dfa73 100644 --- a/pdns/recursordist/nod.cc +++ b/pdns/recursordist/nod.cc @@ -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(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); }