If we get an error writing to the log, log it only once to stderr.
This avoids generating, say, 72 GB of ENOSPC errors in
teuthology.log when /var/log fills up.
Fixes: #14616
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit
d9ac0474b864afda58a44b9012cca4bbc6aaf509)
Conflicts:
src/log/Log.cc (drop m_uid and m_gid which are not used in hammer;
order of do_stderr, do_syslog, do_fd conditional blocks is reversed in
hammer; drop irrelevant speed optimization code from
5bfe05aebfefdff9022f0eb990805758e0edb1dc)
m_flush_mutex_holder(0),
m_new(), m_recent(),
m_fd(-1),
+ m_fd_last_error(0),
m_syslog_log(-2), m_syslog_crash(-2),
m_stderr_log(1), m_stderr_crash(-1),
m_stop(false),
r = safe_write(m_fd, s.data(), s.size());
if (r >= 0)
r = write(m_fd, "\n", 1);
- if (r < 0)
- cerr << "problem writing to " << m_log_file << ": " << cpp_strerror(r) << std::endl;
+ if (r != m_fd_last_error) {
+ if (r < 0)
+ cerr << "problem writing to " << m_log_file
+ << ": " << cpp_strerror(r)
+ << std::endl;
+ m_fd_last_error = r;
+ }
}
if (do_syslog) {
std::string m_log_file;
int m_fd;
+ int m_fd_last_error; ///< last error we say writing to fd (if any)
+
int m_syslog_log, m_syslog_crash;
int m_stderr_log, m_stderr_crash;