From: Colin Patrick McCabe Date: Wed, 20 Oct 2010 22:40:07 +0000 (-0700) Subject: Create cpp_strerror to make error reporting easier X-Git-Tag: v0.22.1~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1127e47cff0a3f8eb1dc26ade352c2831acc0cbd;p=ceph.git Create cpp_strerror to make error reporting easier Signed-off-by: Colin McCabe --- diff --git a/src/Makefile.am b/src/Makefile.am index 4a9224edcdc1..3d9dd46bc8c0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -385,6 +385,7 @@ libcommon_files = \ common/armor.c \ common/base64.c \ common/str_list.cc \ + common/errno.cc \ mon/MonMap.cc \ mon/MonClient.cc \ osd/OSDMap.cc \ diff --git a/src/common/errno.cc b/src/common/errno.cc new file mode 100644 index 000000000000..44cb749c2766 --- /dev/null +++ b/src/common/errno.cc @@ -0,0 +1,15 @@ +#include "common/errno.h" + +#include +#include +#include + +std::string cpp_strerror(int err) +{ + char buf[128]; + + std::ostringstream oss; + oss << "error " << err << ": " << strerror_r(err, buf, sizeof(buf)); + + return oss.str(); +} diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 5e108767e633..c779f0f87817 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -13,6 +13,7 @@ */ #include "config.h" +#include "common/errno.h" #include "FileJournal.h" #include "include/color.h" @@ -31,7 +32,6 @@ const static int64_t ONE_MEG(1 << 20); int FileJournal::_open(bool forwrite, bool create) { - char buf[80]; int flags, ret; if (forwrite) { @@ -47,17 +47,17 @@ int FileJournal::_open(bool forwrite, bool create) ::close(fd); fd = ::open(fn.c_str(), flags, 0644); if (fd < 0) { - dout(2) << "_open failed " << errno << " " << strerror_r(errno, buf, sizeof(buf)) << dendl; - cerr << "unable to open journal " << fn << ": " << strerror_r(errno, buf, sizeof(buf)) << std::endl; - return -errno; + int err = errno; + dout(2) << "_open failed " << cpp_strerror(err) << dendl; + cerr << "unable to open journal " << fn << ": " << cpp_strerror(err) << std::endl; + return -err; } struct stat st; ret = ::fstat(fd, &st); if (ret) { int err = errno; - dout(2) << "_open failed to fstat! " << err << " " - << strerror_r(err, buf, sizeof(buf)) << dendl; + dout(2) << "_open failed to fstat! " << cpp_strerror(err) << dendl; return -err; }