From c1e40e809cd9ff00b0548d1315ac6f031f16bb4f Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Sun, 25 Aug 2019 11:23:20 +0200 Subject: [PATCH] log: close previous log descriptor a bit later: --- logs.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/logs.cc b/logs.cc index 7cea49a..7099429 100644 --- a/logs.cc +++ b/logs.cc @@ -76,18 +76,18 @@ void logLevel(enum llevel_t ll) { void logFile(const std::string& logfile) { _log_set = true; - /* Close previous log_fd */ - if (_log_fd > STDERR_FILENO) { - close(_log_fd); - } int newlogfd = TEMP_FAILURE_RETRY( open(logfile.c_str(), O_CREAT | O_RDWR | O_APPEND | O_CLOEXEC, 0640)); - setDupLogFdOr(newlogfd, STDERR_FILENO); if (newlogfd == -1) { PLOG_W("Couldn't open logfile open('%s')", logfile.c_str()); - } else { - close(newlogfd); + return; + } + /* Close previous log_fd */ + if (_log_fd > STDERR_FILENO) { + close(_log_fd); } + setDupLogFdOr(newlogfd, STDERR_FILENO); + close(newlogfd); } void logMsg(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...) { -- 2.7.4