[Groonga-commit] groonga/groonga at 5f7d5bd [master] Show system error message on mmap() is failed

Back to archive index

Kouhei Sutou null+****@clear*****
Sun May 19 09:55:45 JST 2013


Kouhei Sutou	2013-05-19 09:55:45 +0900 (Sun, 19 May 2013)

  New Revision: 5f7d5bd7e14e5af761ebe92cf1aa857aa7cb8b1e
  https://github.com/groonga/groonga/commit/5f7d5bd7e14e5af761ebe92cf1aa857aa7cb8b1e

  Message:
    Show system error message on mmap() is failed
    
    It is tested by changing grn_io_seg_map_() like:
    
         void
         grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *info)
         {
        +   errno = ENOMEM;
        +   return;
            SEG_MAP(io, segno, info);
         }
    
    NOTE: Windows version may not be worked. I didn't try it yet.

  Added files:
    lib/error.c
    lib/error.h
  Modified files:
    lib/io.h
    lib/sources.am

  Added: lib/error.c (+53 -0) 100644
===================================================================
--- /dev/null
+++ lib/error.c    2013-05-19 09:55:45 +0900 (6b2d06d)
@@ -0,0 +1,53 @@
+/* -*- c-basic-offset: 2 -*- */
+/* Copyright(C) 2013 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "error.h"
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif /* HAVE_ERRNO_H */
+
+#include <string.h>
+
+#ifdef WIN32
+const char *
+grn_current_error_message(void)
+{
+# define ERROR_MESSAGE_BUFFER_SIZE 4096
+  int error_code = WSAGetLastError();
+  static char message[ERROR_MESSAGE_BUFFER_SIZE];
+
+  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
+                FORMAT_MESSAGE_IGNORE_INSERTS,
+                NULL,
+                error_codee,
+                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                message,
+                ERROR_MESSAGE_BUFFER_SIZE,
+                NULL);
+
+  return message;
+
+# undef ERROR_MESSAGE_BUFFER_SIZE 4096
+}
+#else
+const char *
+grn_current_error_message(void)
+{
+  return strerror(errno);
+}
+#endif

  Added: lib/error.h (+35 -0) 100644
===================================================================
--- /dev/null
+++ lib/error.h    2013-05-19 09:55:45 +0900 (f425e46)
@@ -0,0 +1,35 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2013 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+#ifndef GRN_ERROR_H
+#define GRN_ERROR_H
+
+#ifndef GROONGA_IN_H
+#include "groonga_in.h"
+#endif /* GROONGA_IN_H */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *grn_current_error_message(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GRN_ERROR_H */

  Modified: lib/io.h (+13 -3)
===================================================================
--- lib/io.h    2013-05-18 00:32:32 +0900 (348bc9b)
+++ lib/io.h    2013-05-19 09:55:45 +0900 (27538b3)
@@ -21,6 +21,10 @@
 #include "groonga_in.h"
 #endif /* GROONGA_IN_H */
 
+#ifndef GRN_ERROR_H
+#include "error.h"
+#endif /* GRN_ERROR_H */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -196,7 +200,9 @@ void grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *i
           if (!info->map) {\
             grn_io_seg_map_(ctx, io, segno, info);\
             if (!info->map) {\
-              GRN_LOG(ctx, GRN_LOG_CRIT, "mmap failed! in GRN_IO_SEG_REF(%p, %u)", io, segno);\
+              GRN_LOG(ctx, GRN_LOG_CRIT,\
+                      "mmap failed! in GRN_IO_SEG_REF(%p, %u): %s",\
+                      io, segno, grn_current_error_message());\
             }\
           }\
           GRN_ATOMIC_ADD_EX(pnref, -1, nref);\
@@ -233,7 +239,9 @@ void grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *i
             grn_io_seg_map_(ctx, io, segno, info);\
             if (!info->map) {\
               GRN_ATOMIC_ADD_EX(pnref, -1, nref);\
-              GRN_LOG(ctx, GRN_LOG_CRIT, "mmap failed!!! in GRN_IO_SEG_REF(%p, %u, %u)", io, segno, nref);\
+              GRN_LOG(ctx, GRN_LOG_CRIT,\
+                      "mmap failed!!! in GRN_IO_SEG_REF(%p, %u, %u): %s",\
+                      io, segno, nref, grn_current_error_message());\
             }\
             \
             GRN_FUTEX_WAKE(pnref);\
@@ -257,7 +265,9 @@ void grn_io_seg_map_(grn_ctx *ctx, grn_io *io, uint32_t segno, grn_io_mapinfo *i
         if (!info->map) {\
           grn_io_seg_map_(ctx, io, segno, info);\
           if (!info->map) {\
-            GRN_LOG(ctx, GRN_LOG_CRIT, "mmap failed!!!! in GRN_IO_SEG_REF(%p, %u)", io, segno);\
+            GRN_LOG(ctx, GRN_LOG_CRIT,\
+                    "mmap failed!!!! in GRN_IO_SEG_REF(%p, %u): %s",\
+                    io, segno, grn_current_error_message());\
           }\
         }\
         GRN_ATOMIC_ADD_EX(pnref, -1, nref);\

  Modified: lib/sources.am (+2 -0)
===================================================================
--- lib/sources.am    2013-05-18 00:32:32 +0900 (e2c72b1)
+++ lib/sources.am    2013-05-19 09:55:45 +0900 (0bca90e)
@@ -8,6 +8,8 @@ libgroonga_la_SOURCES =				\
 	dat.h					\
 	db.c					\
 	db.h					\
+	error.c					\
+	error.h					\
 	expr.c					\
 	geo.c					\
 	geo.h					\
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index