]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Create cpp_strerror to make error reporting easier
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 20 Oct 2010 22:40:07 +0000 (15:40 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Wed, 20 Oct 2010 23:38:27 +0000 (16:38 -0700)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/Makefile.am
src/common/errno.cc [new file with mode: 0644]
src/os/FileJournal.cc

index 4a9224edcdc1141a2a5f9c2b4d4981da2c54eb0f..3d9dd46bc8c096f67b34cc301486ad5c734a32c5 100644 (file)
@@ -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 (file)
index 0000000..44cb749
--- /dev/null
@@ -0,0 +1,15 @@
+#include "common/errno.h"
+
+#include <sstream>
+#include <string>
+#include <string.h>
+
+std::string cpp_strerror(int err)
+{
+  char buf[128];
+
+  std::ostringstream oss;
+  oss << "error " << err << ": " << strerror_r(err, buf, sizeof(buf));
+
+  return oss.str();
+}
index 5e108767e63305c90a60749451bdd8ba4ca1b72f..c779f0f87817b91efd6b7a1bab45db7ad83a9832 100644 (file)
@@ -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;
   }