[Libreoffice-commits] online.git: 2 commits - common/Log.hpp common/Util.hpp net/DelaySocket.cpp test/httpcrashtest.cpp wsd/Storage.cpp
Tor Lillqvist
tml at collabora.com
Wed Jul 11 10:37:32 UTC 2018
common/Log.hpp | 6 +-
common/Util.hpp | 142 +++++++++++++++++++++++++++++++++++++++++++++++++
net/DelaySocket.cpp | 6 +-
test/httpcrashtest.cpp | 2
wsd/Storage.cpp | 2
5 files changed, 151 insertions(+), 7 deletions(-)
New commits:
commit 3b4269a301e373262a091a5e06a33354996dd52b
Author: Tor Lillqvist <tml at collabora.com>
Date: Wed Jul 11 12:58:10 2018 +0300
Use Util::symbolicErrno()
I think the general policy should be to always log errno using both
Util::symbolicErrno() and std::strerror(), never log a naked errno.
But only in cases where we know that it is highly likely that it is
the most recent system call that has failed, so errno makes sense.
Change-Id: I4a1fb31e375ea949e7da17687464361efe7c1761
diff --git a/common/Log.hpp b/common/Log.hpp
index bb5a61554..a26c68148 100644
--- a/common/Log.hpp
+++ b/common/Log.hpp
@@ -23,6 +23,8 @@
#include <Poco/DateTimeFormatter.h>
#include <Poco/Logger.h>
+#include "Util.hpp"
+
inline std::ostream& operator<< (std::ostream& os, const Poco::Timestamp& ts)
{
os << Poco::DateTimeFormatter::format(Poco::DateTime(ts),
@@ -220,9 +222,9 @@ namespace Log
#define LOG_INF(X) do { auto& l_ = Log::logger(); if (l_.information()) { LOG_BODY_(INFORMATION, "INF", X); } } while (false)
#define LOG_WRN(X) do { auto& l_ = Log::logger(); if (l_.warning()) { LOG_BODY_(WARNING, "WRN", X); } } while (false)
#define LOG_ERR(X) do { auto& l_ = Log::logger(); if (l_.error()) { LOG_BODY_(ERROR, "ERR", X); } } while (false)
-#define LOG_SYS(X) do { auto& l_ = Log::logger(); if (l_.error()) { LOG_BODY_(ERROR, "ERR", X << " (errno: " << std::strerror(errno) << ")"); } } while (false)
+#define LOG_SYS(X) do { auto& l_ = Log::logger(); if (l_.error()) { LOG_BODY_(ERROR, "ERR", X << " (" << Util::symbolicErrno(errno) << ": " << std::strerror(errno) << ")"); } } while (false)
#define LOG_FTL(X) do { auto& l_ = Log::logger(); if (l_.fatal()) { LOG_BODY_(FATAL, "FTL", X); } } while (false)
-#define LOG_SFL(X) do { auto& l_ = Log::logger(); if (l_.error()) { LOG_BODY_(FATAL, "FTL", X << " (errno: " << std::strerror(errno) << ")"); } } while (false)
+#define LOG_SFL(X) do { auto& l_ = Log::logger(); if (l_.error()) { LOG_BODY_(FATAL, "FTL", X << " (" << Util::symbolicErrno(errno) << ": " << std::strerror(errno) << ")"); } } while (false)
#define LOG_END(l) do { l << __FILE__ << ':' << __LINE__; l.flush(); } while (false)
diff --git a/net/DelaySocket.cpp b/net/DelaySocket.cpp
index 2c999edb5..41eb4faf5 100644
--- a/net/DelaySocket.cpp
+++ b/net/DelaySocket.cpp
@@ -150,7 +150,7 @@ public:
}
else if (errno != EAGAIN && errno != EWOULDBLOCK)
{
- DELAY_LOG("#" << getFD() << " error : " << errno << " " << strerror(errno) << "\n");
+ DELAY_LOG("#" << getFD() << " error : " << Util::symbolicErrno(errno) << ": " << strerror(errno) << "\n");
changeState(Closed); // FIXME - propagate the error ?
}
}
@@ -189,8 +189,8 @@ public:
DELAY_LOG("#" << getFD() << " failed onwards write "
<< len << "bytes of "
<< chunk->_data.size()
- << " queue: " << _chunks.size() << " error "
- << strerror(errno) << "\n");
+ << " queue: " << _chunks.size() << " error: "
+ << Util::symbolicErrno(errno) << ": " << strerror(errno) << "\n");
changeState(Closed);
}
}
diff --git a/test/httpcrashtest.cpp b/test/httpcrashtest.cpp
index d4a0e06ab..a2b1a9d2a 100644
--- a/test/httpcrashtest.cpp
+++ b/test/httpcrashtest.cpp
@@ -240,7 +240,7 @@ static void killPids(const std::vector<int> &pids, const std::string& testname)
{
TST_LOG_BEGIN("Killing " << pid);
if (kill(pid, SIGKILL) == -1)
- TST_LOG_APPEND("kill(" << pid << ", SIGKILL) failed: " << std::strerror(errno));
+ TST_LOG_APPEND("kill(" << pid << ", SIGKILL) failed: " << Util::symbolicErrno(errno) << ": " << std::strerror(errno));
TST_LOG_END;
}
}
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 0b3ed3545..f6f8066eb 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -269,7 +269,7 @@ std::string LocalStorage::loadStorageFileToLocal(const Authorization& /*auth*/)
{
// Failed
LOG_WRN("link(\"" << publicFilePath << "\", \"" << _jailedFilePath << "\") failed. Will copy. "
- "Linking error: " << errno << " " << strerror(errno));
+ "Linking error: " << Util::symbolicErrno(errno) << " " << strerror(errno));
}
try
commit 40f4cf17c9be3795ebb0b5be5e2bc147176f48ab
Author: Tor Lillqvist <tml at collabora.com>
Date: Wed Jul 11 12:54:23 2018 +0300
Add a symbolicErrno() function to Util
For a developer, it is much nicer to see "EXDEV" in a log than "18",
for instance. (Sure, we often also log strerror(), but might that
perhaps be localised? And the symbolic names are what one uses when
coding anyway.)
Change-Id: I456a8c2589147dcad87f1b4c3a20b3bd5a35d097
diff --git a/common/Util.hpp b/common/Util.hpp
index cd59f7d95..afc42dcd0 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -11,6 +11,7 @@
#define INCLUDED_UTIL_HPP
#include <cassert>
+#include <cerrno>
#include <cstddef>
#include <atomic>
#include <functional>
@@ -305,6 +306,147 @@ namespace Util
return s.length() >= t.length() && memcmp(s.c_str(), t.c_str(), t.length()) == 0;
}
+ /// Return the symbolic name for an errno value, or in decimal if not handled here.
+ inline std::string symbolicErrno(int e)
+ {
+ // Errnos from <asm-generic/errno-base.h> and <asm-generic/errno.h> on Linux.
+ switch (e)
+ {
+ case EPERM: return "EPERM";
+ case ENOENT: return "ENOENT";
+ case ESRCH: return "ESRCH";
+ case EINTR: return "EINTR";
+ case EIO: return "EIO";
+ case ENXIO: return "ENXIO";
+ case E2BIG: return "E2BIG";
+ case ENOEXEC: return "ENOEXEC";
+ case EBADF: return "EBADF";
+ case ECHILD: return "ECHILD";
+ case EAGAIN: return "EAGAIN";
+ case ENOMEM: return "ENOMEM";
+ case EACCES: return "EACCES";
+ case EFAULT: return "EFAULT";
+ case ENOTBLK: return "ENOTBLK";
+ case EBUSY: return "EBUSY";
+ case EEXIST: return "EEXIST";
+ case EXDEV: return "EXDEV";
+ case ENODEV: return "ENODEV";
+ case ENOTDIR: return "ENOTDIR";
+ case EISDIR: return "EISDIR";
+ case EINVAL: return "EINVAL";
+ case ENFILE: return "ENFILE";
+ case EMFILE: return "EMFILE";
+ case ENOTTY: return "ENOTTY";
+ case ETXTBSY: return "ETXTBSY";
+ case EFBIG: return "EFBIG";
+ case ENOSPC: return "ENOSPC";
+ case ESPIPE: return "ESPIPE";
+ case EROFS: return "EROFS";
+ case EMLINK: return "EMLINK";
+ case EPIPE: return "EPIPE";
+ case EDOM: return "EDOM";
+ case ERANGE: return "ERANGE";
+ case EDEADLK: return "EDEADLK";
+ case ENAMETOOLONG: return "ENAMETOOLONG";
+ case ENOLCK: return "ENOLCK";
+ case ENOSYS: return "ENOSYS";
+ case ENOTEMPTY: return "ENOTEMPTY";
+ case ELOOP: return "ELOOP";
+ case ENOMSG: return "ENOMSG";
+ case EIDRM: return "EIDRM";
+ case ECHRNG: return "ECHRNG";
+ case EL2NSYNC: return "EL2NSYNC";
+ case EL3HLT: return "EL3HLT";
+ case EL3RST: return "EL3RST";
+ case ELNRNG: return "ELNRNG";
+ case EUNATCH: return "EUNATCH";
+ case ENOCSI: return "ENOCSI";
+ case EL2HLT: return "EL2HLT";
+ case EBADE: return "EBADE";
+ case EBADR: return "EBADR";
+ case EXFULL: return "EXFULL";
+ case ENOANO: return "ENOANO";
+ case EBADRQC: return "EBADRQC";
+ case EBADSLT: return "EBADSLT";
+ case EBFONT: return "EBFONT";
+ case ENOSTR: return "ENOSTR";
+ case ENODATA: return "ENODATA";
+ case ETIME: return "ETIME";
+ case ENOSR: return "ENOSR";
+ case ENONET: return "ENONET";
+ case ENOPKG: return "ENOPKG";
+ case EREMOTE: return "EREMOTE";
+ case ENOLINK: return "ENOLINK";
+ case EADV: return "EADV";
+ case ESRMNT: return "ESRMNT";
+ case ECOMM: return "ECOMM";
+ case EPROTO: return "EPROTO";
+ case EMULTIHOP: return "EMULTIHOP";
+ case EDOTDOT: return "EDOTDOT";
+ case EBADMSG: return "EBADMSG";
+ case EOVERFLOW: return "EOVERFLOW";
+ case ENOTUNIQ: return "ENOTUNIQ";
+ case EBADFD: return "EBADFD";
+ case EREMCHG: return "EREMCHG";
+ case ELIBACC: return "ELIBACC";
+ case ELIBBAD: return "ELIBBAD";
+ case ELIBSCN: return "ELIBSCN";
+ case ELIBMAX: return "ELIBMAX";
+ case ELIBEXEC: return "ELIBEXEC";
+ case EILSEQ: return "EILSEQ";
+ case ERESTART: return "ERESTART";
+ case ESTRPIPE: return "ESTRPIPE";
+ case EUSERS: return "EUSERS";
+ case ENOTSOCK: return "ENOTSOCK";
+ case EDESTADDRREQ: return "EDESTADDRREQ";
+ case EMSGSIZE: return "EMSGSIZE";
+ case EPROTOTYPE: return "EPROTOTYPE";
+ case ENOPROTOOPT: return "ENOPROTOOPT";
+ case EPROTONOSUPPORT: return "EPROTONOSUPPORT";
+ case ESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT";
+ case EOPNOTSUPP: return "EOPNOTSUPP";
+ case EPFNOSUPPORT: return "EPFNOSUPPORT";
+ case EAFNOSUPPORT: return "EAFNOSUPPORT";
+ case EADDRINUSE: return "EADDRINUSE";
+ case EADDRNOTAVAIL: return "EADDRNOTAVAIL";
+ case ENETDOWN: return "ENETDOWN";
+ case ENETUNREACH: return "ENETUNREACH";
+ case ENETRESET: return "ENETRESET";
+ case ECONNABORTED: return "ECONNABORTED";
+ case ECONNRESET: return "ECONNRESET";
+ case ENOBUFS: return "ENOBUFS";
+ case EISCONN: return "EISCONN";
+ case ENOTCONN: return "ENOTCONN";
+ case ESHUTDOWN: return "ESHUTDOWN";
+ case ETOOMANYREFS: return "ETOOMANYREFS";
+ case ETIMEDOUT: return "ETIMEDOUT";
+ case ECONNREFUSED: return "ECONNREFUSED";
+ case EHOSTDOWN: return "EHOSTDOWN";
+ case EHOSTUNREACH: return "EHOSTUNREACH";
+ case EALREADY: return "EALREADY";
+ case EINPROGRESS: return "EINPROGRESS";
+ case ESTALE: return "ESTALE";
+ case EUCLEAN: return "EUCLEAN";
+ case ENOTNAM: return "ENOTNAM";
+ case ENAVAIL: return "ENAVAIL";
+ case EISNAM: return "EISNAM";
+ case EREMOTEIO: return "EREMOTEIO";
+ case EDQUOT: return "EDQUOT";
+ case ENOMEDIUM: return "ENOMEDIUM";
+ case EMEDIUMTYPE: return "EMEDIUMTYPE";
+ case ECANCELED: return "ECANCELED";
+ case ENOKEY: return "ENOKEY";
+ case EKEYEXPIRED: return "EKEYEXPIRED";
+ case EKEYREVOKED: return "EKEYREVOKED";
+ case EKEYREJECTED: return "EKEYREJECTED";
+ case EOWNERDEAD: return "EOWNERDEAD";
+ case ENOTRECOVERABLE: return "ENOTRECOVERABLE";
+ case ERFKILL: return "ERFKILL";
+ case EHWPOISON: return "EHWPOISON";
+ default: return std::to_string(e);
+ }
+ }
+
/// Check for the URI scheme validity.
/// For now just a basic sanity check, can be extended if necessary.
bool isValidURIScheme(const std::string& scheme);
More information about the Libreoffice-commits
mailing list