From f0b270f4c777815cbff9a8f6b641d9d0b84a3923 Mon Sep 17 00:00:00 2001 From: Eric Schwartz Date: Fri, 11 Oct 2019 17:40:38 +0000 Subject: [PATCH] address pipe remove on reload and add pipe reuse --- proxy/logging/LogFile.cc | 25 ++++++++++++++++++------- proxy/logging/LogObject.cc | 3 +-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/proxy/logging/LogFile.cc b/proxy/logging/LogFile.cc index 1d7d0a1c8cd..aeb567b2d11 100644 --- a/proxy/logging/LogFile.cc +++ b/proxy/logging/LogFile.cc @@ -170,14 +170,25 @@ LogFile::open_file() bool file_exists = LogFile::exists(m_name); if (m_file_format == LOG_FILE_PIPE) { - // setup pipe - if (mkfifo(m_name, S_IRUSR | S_IWUSR | S_IRGRP) < 0) { - if (errno != EEXIST) { - Error("Could not create named pipe %s for logging: %s", m_name, strerror(errno)); - return LOG_FILE_COULD_NOT_CREATE_PIPE; + bool pipe_exists = false; + // reuse existing pipe if available + struct stat stat_p; + stat(m_name, &stat_p); + if (S_ISREG(stat_p.st_mode) && S_ISFIFO(stat_p.st_mode)) { + pipe_exists = true; // pipe exists try to reuse + Debug("log-file", "Reusing existing pipe %s for logging", m_name); + } + + // setup pipe if not there + if (!pipe_exists) { + if (mkfifo(m_name, S_IRUSR | S_IWUSR | S_IRGRP) < 0) { + if (errno != EEXIST) { + Error("Could not create named pipe %s for logging: %s", m_name, strerror(errno)); + return LOG_FILE_COULD_NOT_CREATE_PIPE; + } + } else { + Debug("log-file", "Created named pipe %s for logging", m_name); } - } else { - Debug("log-file", "Created named pipe %s for logging", m_name); } // now open the pipe diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc index f1c2337b01d..45d826b165a 100644 --- a/proxy/logging/LogObject.cc +++ b/proxy/logging/LogObject.cc @@ -966,7 +966,7 @@ LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConfli // roll old filename so the new object can use the filename // it requested (previously we used to rename the NEW file // but now we roll the OLD file), or if the log object writes - // to a pipe, just remove the file if it was open as a pipe + // to a pipe, just don't roll bool roll_file = true; @@ -988,7 +988,6 @@ LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConfli roll_file = false; } else { if (S_ISFIFO(s.st_mode)) { - unlink(filename); roll_file = false; } }