summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-28 21:17:29 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-28 21:17:29 +0000
commitc22126755cd89f2b8aa309df8908d839e588a3bd (patch)
tree6a8f60739dffae50ce16a690eda77eaa56cdd550 /error.c
parent58018f1f2d41ec28203439496537106e6b08c377 (diff)
* error.c (rb_async_bug_errno): async-safe bug report function.
In timer thread, signal handler shoul use it. The patch is contributed by Eric Wong <normalperson@yhbt.net>. Refs: [ruby-core:37644] and [ruby-core:37647] * thread_pthread.c: use rb_async_bug_errno(). And replace all fprintf() to write(). * internal.h (rb_async_bug_errno): add decl. of above func. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/error.c b/error.c
index 7c95455826..66ebbba2cc 100644
--- a/error.c
+++ b/error.c
@@ -21,6 +21,9 @@
#include <stdlib.h>
#endif
#include <errno.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
@@ -36,6 +39,13 @@
extern const char ruby_description[];
+#define REPORTBUG_MSG \
+ "[NOTE]\n" \
+ "You may have encountered a bug in the Ruby interpreter" \
+ " or extension libraries.\n" \
+ "Bug reports are welcome.\n" \
+ "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
+
static const char *
rb_strerrno(int err)
{
@@ -247,12 +257,7 @@ report_bug(const char *file, int line, const char *fmt, va_list args)
rb_vm_bugreport();
- fprintf(out,
- "[NOTE]\n"
- "You may have encountered a bug in the Ruby interpreter"
- " or extension libraries.\n"
- "Bug reports are welcome.\n"
- "For details: http://www.ruby-lang.org/bugreport.html\n\n");
+ fprintf(out, REPORTBUG_MSG);
}
}
@@ -286,6 +291,35 @@ rb_bug_errno(const char *mesg, int errno_arg)
}
}
+/*
+ * this is safe to call inside signal handler and timer thread
+ * (which isn't a Ruby Thread object)
+ */
+#define WRITE_CONST(fd,str) write((fd),(str),sizeof(str) - 1)
+
+void rb_async_bug_errno(const char *mesg, int errno_arg)
+{
+ WRITE_CONST(2, "[ASYNC BUG] ");
+ write(2, mesg, strlen(mesg));
+ WRITE_CONST(2, "\n");
+
+ if (errno_arg == 0) {
+ WRITE_CONST(2, "errno == 0 (NOERROR)\n");
+ }
+ else {
+ const char *errno_str = rb_strerrno(errno_arg);
+
+ if (!errno_str)
+ errno_str = "undefined errno";
+ write(2, errno_str, strlen(errno_str));
+ }
+ WRITE_CONST(2, "\n\n");
+ write(2, ruby_description, strlen(ruby_description));
+ WRITE_CONST(2, "\n\n");
+ WRITE_CONST(2, REPORTBUG_MSG);
+ abort();
+}
+
void
rb_compile_bug(const char *file, int line, const char *fmt, ...)
{