From ff85407b437d335b387cc7b7e894b40d21191ddf Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Thu, 10 Feb 2011 08:00:34 -0800 Subject: [PATCH] common/DoutStreambuf: use safe_io.h Signed-off-by: Colin McCabe --- src/common/DoutStreambuf.cc | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc index 4c42b1e9ba7c7..e4c444d3eea16 100644 --- a/src/common/DoutStreambuf.cc +++ b/src/common/DoutStreambuf.cc @@ -16,6 +16,7 @@ #include "common/DoutStreambuf.h" #include "common/errno.h" #include "common/Mutex.h" +#include "common/safe_io.h" #include #include @@ -96,36 +97,13 @@ static inline int dout_prio_to_syslog_prio(int prio) return LOG_DEBUG; } -static int safe_write(int fd, const char *buf, signed int len) -{ - int res; - - assert(len != 0); - while (1) { - res = write(fd, buf, len); - if (res < 0) { - int err = errno; - if (err != EINTR) { - ostringstream oss; - oss << __func__ << ": failed to write to fd " << fd << ": " - << cpp_strerror(err) << "\n"; - TEMP_FAILURE_RETRY(::write(STDERR_FILENO, oss.str().c_str(), - oss.str().size())); - syslog(LOG_USER | LOG_NOTICE, "%s", oss.str().c_str()); - return err; - } - } - len -= res; - buf += res; - if (len <= 0) - return 0; - } -} - /* Complain about errors even without a logfile */ static void primitive_log(const std::string &str) { - safe_write(STDERR_FILENO, str.c_str(), str.size()); + if (safe_write(STDERR_FILENO, str.c_str(), str.size())) { + // ignore errors + ; + } syslog(LOG_USER | LOG_NOTICE, "%s", str.c_str()); } -- 2.47.3